Home | History | Annotate | Line # | Download | only in wsconsctl
display.c revision 1.6
      1 /*	$NetBSD: display.c,v 1.6 2004/07/29 22:29:37 jmmv Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Juergen Hannken-Illjes.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/ioctl.h>
     40 #include <sys/time.h>
     41 
     42 #include <stdio.h>
     43 #include <string.h>
     44 #include <errno.h>
     45 #include <err.h>
     46 
     47 #include <dev/wscons/wsconsio.h>
     48 
     49 #include "wsconsctl.h"
     50 
     51 static int border;
     52 static int dpytype;
     53 static struct wsdisplay_usefontdata font;
     54 static struct wsdisplay_scroll_data scroll_l;
     55 static int havescroll = 1;
     56 static int msg_default_attrs, msg_default_bg, msg_default_fg;
     57 static int msg_kernel_attrs, msg_kernel_bg, msg_kernel_fg;
     58 
     59 struct field display_field_tab[] = {
     60     { "border",			&border,	FMT_COLOR,	FLG_MODIFY },
     61     { "type",			&dpytype,	FMT_DPYTYPE,	FLG_RDONLY },
     62     { "font",			&font.name,	FMT_STRING,	FLG_WRONLY },
     63     { "scroll.fastlines",	&scroll_l.fastlines, FMT_UINT, FLG_MODIFY },
     64     { "scroll.slowlines",	&scroll_l.slowlines, FMT_UINT, FLG_MODIFY },
     65     { "msg.default.attrs",	&msg_default_attrs, FMT_ATTRS,	FLG_MODIFY },
     66     { "msg.default.bg",		&msg_default_bg, FMT_COLOR,	FLG_MODIFY },
     67     { "msg.default.fg",		&msg_default_fg, FMT_COLOR,	FLG_MODIFY },
     68     { "msg.kernel.attrs",	&msg_kernel_attrs, FMT_ATTRS,	FLG_MODIFY },
     69     { "msg.kernel.bg",		&msg_kernel_bg, FMT_COLOR,	FLG_MODIFY },
     70     { "msg.kernel.fg",		&msg_kernel_fg, FMT_COLOR,	FLG_MODIFY },
     71 };
     72 
     73 int display_field_tab_len = sizeof(display_field_tab)/
     74 			     sizeof(display_field_tab[0]);
     75 
     76 static int
     77 init_values(void)
     78 {
     79 	scroll_l.which = 0;
     80 
     81 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_GET)
     82 		scroll_l.which |= WSDISPLAY_SCROLL_DOFASTLINES;
     83 	if (field_by_value(&scroll_l.slowlines)->flags & FLG_GET)
     84 		scroll_l.which |= WSDISPLAY_SCROLL_DOSLOWLINES;
     85 
     86 	return scroll_l.which;
     87 
     88 }
     89 void
     90 display_get_values(fd)
     91 	int fd;
     92 {
     93 	if (field_by_value(&dpytype)->flags & FLG_GET)
     94 		if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
     95 			err(1, "WSDISPLAYIO_GTYPE");
     96 
     97 	if (field_by_value(&border)->flags & FLG_GET)
     98 		if (ioctl(fd, WSDISPLAYIO_GBORDER, &border) < 0)
     99 			warn("WSDISPLAYIO_GBORDER");
    100 
    101 	if (field_by_value(&msg_default_attrs)->flags & FLG_GET ||
    102 	    field_by_value(&msg_default_bg)->flags & FLG_GET ||
    103 	    field_by_value(&msg_default_fg)->flags & FLG_GET ||
    104 	    field_by_value(&msg_kernel_attrs)->flags & FLG_GET ||
    105 	    field_by_value(&msg_kernel_bg)->flags & FLG_GET ||
    106 	    field_by_value(&msg_kernel_fg)->flags & FLG_GET) {
    107 		struct wsdisplay_msgattrs ma;
    108 
    109 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0) {
    110 			warnx("no support to change console/kernel colors");
    111 
    112 			ma.default_attrs = -1;
    113 			ma.default_bg = -1;
    114 			ma.default_fg = -1;
    115 
    116 			ma.kernel_attrs = -1;
    117 			ma.kernel_bg = -1;
    118 			ma.kernel_fg = -1;
    119 		}
    120 
    121 		msg_default_attrs = ma.default_attrs;
    122 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    123 			msg_default_bg = ma.default_bg;
    124 			msg_default_fg = ma.default_fg;
    125 		} else
    126 			msg_default_bg = msg_default_fg = -1;
    127 
    128 		msg_kernel_attrs = ma.kernel_attrs;
    129 		if (ma.kernel_attrs & WSATTR_WSCOLORS) {
    130 			msg_kernel_bg = ma.kernel_bg;
    131 			msg_kernel_fg = ma.kernel_fg;
    132 		} else
    133 			msg_kernel_bg = msg_kernel_fg = -1;
    134 	}
    135 
    136 	if (init_values() == 0 || havescroll == 0)
    137 		return;
    138 
    139 	if (ioctl(fd, WSDISPLAYIO_DGSCROLL, &scroll_l) < 0) {
    140 		if (errno != ENODEV)
    141 			err(1, "WSDISPLAYIO_GSCROLL");
    142 		else
    143 			havescroll = 0;
    144 	}
    145 }
    146 
    147 void
    148 display_put_values(fd)
    149 	int fd;
    150 {
    151 	if (field_by_value(&font.name)->flags & FLG_SET) {
    152 		if (ioctl(fd, WSDISPLAYIO_SFONT, &font) < 0)
    153 			err(1, "WSDISPLAYIO_SFONT");
    154 		pr_field(field_by_value(&font.name), " -> ");
    155 	}
    156 
    157 	if (field_by_value(&border)->flags & FLG_SET) {
    158 		if (ioctl(fd, WSDISPLAYIO_SBORDER, &border) < 0)
    159 			err(1, "WSDISPLAYIO_SBORDER");
    160 		pr_field(field_by_value(&border), " -> ");
    161 	}
    162 
    163 	if (field_by_value(&msg_default_attrs)->flags & FLG_SET ||
    164 	    field_by_value(&msg_default_bg)->flags & FLG_SET ||
    165 	    field_by_value(&msg_default_fg)->flags & FLG_SET ||
    166 	    field_by_value(&msg_kernel_attrs)->flags & FLG_SET ||
    167 	    field_by_value(&msg_kernel_bg)->flags & FLG_SET ||
    168 	    field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    169 		struct wsdisplay_msgattrs ma;
    170 
    171 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0)
    172 			err(1, "WSDISPLAYIO_GMSGATTRS");
    173 
    174 		if (field_by_value(&msg_default_attrs)->flags & FLG_SET) {
    175 			ma.default_attrs = msg_default_attrs;
    176 			pr_field(field_by_value(&msg_default_attrs), " -> ");
    177 		}
    178 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    179 			if (field_by_value(&msg_default_bg)->flags & FLG_SET) {
    180 				ma.default_bg = msg_default_bg;
    181 				pr_field(field_by_value(&msg_default_bg),
    182 				         " -> ");
    183 			}
    184 			if (field_by_value(&msg_default_fg)->flags & FLG_SET) {
    185 				ma.default_fg = msg_default_fg;
    186 				pr_field(field_by_value(&msg_default_fg),
    187 				         " -> ");
    188 			}
    189 		}
    190 
    191 		if (field_by_value(&msg_kernel_attrs)->flags & FLG_SET) {
    192 			ma.kernel_attrs = msg_kernel_attrs;
    193 			pr_field(field_by_value(&msg_kernel_attrs), " -> ");
    194 		}
    195 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    196 			if (field_by_value(&msg_kernel_bg)->flags & FLG_SET) {
    197 				ma.kernel_bg = msg_kernel_bg;
    198 				pr_field(field_by_value(&msg_kernel_bg),
    199 				         " -> ");
    200 			}
    201 			if (field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    202 				ma.kernel_fg = msg_kernel_fg;
    203 				pr_field(field_by_value(&msg_kernel_fg),
    204 				         " -> ");
    205 			}
    206 		}
    207 
    208 		if (ioctl(fd, WSDISPLAYIO_SMSGATTRS, &ma) < 0)
    209 			err(1, "WSDISPLAYIO_SMSGATTRS");
    210 	}
    211 
    212 	if (init_values() == 0 || havescroll == 0)
    213 		return;
    214 
    215 	if (scroll_l.which & WSDISPLAY_SCROLL_DOFASTLINES)
    216 		pr_field(field_by_value(&scroll_l.fastlines), " -> ");
    217 	if (scroll_l.which & WSDISPLAY_SCROLL_DOSLOWLINES)
    218 		pr_field(field_by_value(&scroll_l.slowlines), " -> ");
    219 
    220 	if (ioctl(fd, WSDISPLAYIO_DSSCROLL, &scroll_l) < 0) {
    221 		if (errno != ENODEV)
    222 			err (1, "WSDISPLAYIO_DSSCROLL");
    223 		else {
    224 			warnx("scrolling is not supported by this kernel");
    225 			havescroll = 0;
    226 		}
    227 	}
    228 }
    229