Home | History | Annotate | Line # | Download | only in wsconsctl
display.c revision 1.10
      1 /*	$NetBSD: display.c,v 1.10 2005/02/27 15:26:16 uwe Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998, 2004 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_param backlight;
     55 static struct wsdisplay_param brightness;
     56 static struct wsdisplay_param contrast;
     57 static struct wsdisplay_scroll_data scroll_l;
     58 static int msg_default_attrs, msg_default_bg, msg_default_fg;
     59 static int msg_kernel_attrs, msg_kernel_bg, msg_kernel_fg;
     60 
     61 struct field display_field_tab[] = {
     62     { "border",			&border,	FMT_COLOR,	FLG_MODIFY },
     63     { "type",			&dpytype,	FMT_DPYTYPE,	FLG_RDONLY },
     64     { "font",			&font.name,	FMT_STRING,	FLG_WRONLY },
     65     { "backlight",		&backlight.curval,  FMT_UINT,	0 },
     66     { "brightness",		&brightness.curval, FMT_UINT,	FLG_MODIFY },
     67     { "contrast",		&contrast.curval,   FMT_UINT,	FLG_MODIFY },
     68     { "scroll.fastlines",	&scroll_l.fastlines, FMT_UINT, FLG_MODIFY },
     69     { "scroll.slowlines",	&scroll_l.slowlines, FMT_UINT, FLG_MODIFY },
     70     { "msg.default.attrs",	&msg_default_attrs, FMT_ATTRS,	FLG_MODIFY },
     71     { "msg.default.bg",		&msg_default_bg, FMT_COLOR,	FLG_MODIFY },
     72     { "msg.default.fg",		&msg_default_fg, FMT_COLOR,	FLG_MODIFY },
     73     { "msg.kernel.attrs",	&msg_kernel_attrs, FMT_ATTRS,	FLG_MODIFY },
     74     { "msg.kernel.bg",		&msg_kernel_bg, FMT_COLOR,	FLG_MODIFY },
     75     { "msg.kernel.fg",		&msg_kernel_fg, FMT_COLOR,	FLG_MODIFY },
     76 };
     77 
     78 int display_field_tab_len = sizeof(display_field_tab)/
     79 			     sizeof(display_field_tab[0]);
     80 
     81 void
     82 display_get_values(int fd)
     83 {
     84 	if (field_by_value(&dpytype)->flags & FLG_GET)
     85 		if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
     86 			err(1, "WSDISPLAYIO_GTYPE");
     87 
     88 	if (field_by_value(&border)->flags & FLG_GET)
     89 		if (ioctl(fd, WSDISPLAYIO_GBORDER, &border) < 0)
     90 			field_disable_by_value(&border);
     91 
     92 	if (field_by_value(&backlight.curval)->flags & FLG_GET) {
     93 		backlight.param = WSDISPLAYIO_PARAM_BACKLIGHT;
     94 		if (ioctl(fd, WSDISPLAYIO_GETPARAM, &backlight) < 0)
     95 			field_disable_by_value(&backlight.curval);
     96 	}
     97 
     98 	if (field_by_value(&brightness.curval)->flags & FLG_GET) {
     99 		brightness.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
    100 		if (ioctl(fd, WSDISPLAYIO_GETPARAM, &brightness))
    101 			field_disable_by_value(&brightness.curval);
    102 	}
    103 
    104 	if (field_by_value(&contrast.curval)->flags & FLG_GET) {
    105 		contrast.param = WSDISPLAYIO_PARAM_CONTRAST;
    106 		if (ioctl(fd, WSDISPLAYIO_GETPARAM, &contrast))
    107 			field_disable_by_value(&contrast.curval);
    108 	}
    109 
    110 	if (field_by_value(&msg_default_attrs)->flags & FLG_GET ||
    111 	    field_by_value(&msg_default_bg)->flags & FLG_GET ||
    112 	    field_by_value(&msg_default_fg)->flags & FLG_GET ||
    113 	    field_by_value(&msg_kernel_attrs)->flags & FLG_GET ||
    114 	    field_by_value(&msg_kernel_bg)->flags & FLG_GET ||
    115 	    field_by_value(&msg_kernel_fg)->flags & FLG_GET) {
    116 		struct wsdisplay_msgattrs ma;
    117 
    118 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0) {
    119 			field_disable_by_value(&msg_default_attrs);
    120 			field_disable_by_value(&msg_default_bg);
    121 			field_disable_by_value(&msg_default_fg);
    122 			field_disable_by_value(&msg_kernel_attrs);
    123 			field_disable_by_value(&msg_kernel_bg);
    124 			field_disable_by_value(&msg_kernel_fg);
    125 		} else {
    126 			msg_default_attrs = ma.default_attrs;
    127 			if (ma.default_attrs & WSATTR_WSCOLORS) {
    128 				msg_default_bg = ma.default_bg;
    129 				msg_default_fg = ma.default_fg;
    130 			} else
    131 				msg_default_bg = msg_default_fg = -1;
    132 
    133 			msg_kernel_attrs = ma.kernel_attrs;
    134 			if (ma.kernel_attrs & WSATTR_WSCOLORS) {
    135 				msg_kernel_bg = ma.kernel_bg;
    136 				msg_kernel_fg = ma.kernel_fg;
    137 			} else
    138 				msg_kernel_bg = msg_kernel_fg = -1;
    139 		}
    140 	}
    141 
    142 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_GET ||
    143 	    field_by_value(&scroll_l.slowlines)->flags & FLG_GET) {
    144 		if (ioctl(fd, WSDISPLAYIO_DGSCROLL, &scroll_l) < 0) {
    145 			field_disable_by_value(&scroll_l.fastlines);
    146 			field_disable_by_value(&scroll_l.slowlines);
    147 		}
    148 	}
    149 }
    150 
    151 void
    152 display_put_values(fd)
    153 	int fd;
    154 {
    155 	if (field_by_value(&font.name)->flags & FLG_SET) {
    156 		if (ioctl(fd, WSDISPLAYIO_SFONT, &font) < 0)
    157 			err(1, "WSDISPLAYIO_SFONT");
    158 		pr_field(field_by_value(&font.name), " -> ");
    159 	}
    160 
    161 	if (field_by_value(&border)->flags & FLG_SET) {
    162 		if (ioctl(fd, WSDISPLAYIO_SBORDER, &border) < 0)
    163 			err(1, "WSDISPLAYIO_SBORDER");
    164 		pr_field(field_by_value(&border), " -> ");
    165 	}
    166 
    167 	if (field_by_value(&backlight.curval)->flags & FLG_SET) {
    168 		backlight.param = WSDISPLAYIO_PARAM_BACKLIGHT;
    169 		if (ioctl(fd, WSDISPLAYIO_SETPARAM, &backlight) < 0)
    170 			err(1, "WSDISPLAYIO_PARAM_BACKLIGHT");
    171 		pr_field(field_by_value(&backlight.curval), " -> ");
    172 	}
    173 
    174 	if (field_by_value(&brightness.curval)->flags & FLG_SET) {
    175 		brightness.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
    176 		if (ioctl(fd, WSDISPLAYIO_SETPARAM, &brightness) < 0)
    177 			err(1, "WSDISPLAYIO_PARAM_BRIGHTNESS");
    178 		pr_field(field_by_value(&brightness.curval), " -> ");
    179 	}
    180 
    181 	if (field_by_value(&contrast.curval)->flags & FLG_SET) {
    182 		contrast.param = WSDISPLAYIO_PARAM_CONTRAST;
    183 		if (ioctl(fd, WSDISPLAYIO_SETPARAM, &contrast) < 0)
    184 			err(1, "WSDISPLAYIO_PARAM_CONTRAST");
    185 		pr_field(field_by_value(&contrast.curval), " -> ");
    186 	}
    187 
    188 	if (field_by_value(&msg_default_attrs)->flags & FLG_SET ||
    189 	    field_by_value(&msg_default_bg)->flags & FLG_SET ||
    190 	    field_by_value(&msg_default_fg)->flags & FLG_SET ||
    191 	    field_by_value(&msg_kernel_attrs)->flags & FLG_SET ||
    192 	    field_by_value(&msg_kernel_bg)->flags & FLG_SET ||
    193 	    field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    194 		struct wsdisplay_msgattrs ma;
    195 
    196 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0)
    197 			err(1, "WSDISPLAYIO_GMSGATTRS");
    198 
    199 		if (field_by_value(&msg_default_attrs)->flags & FLG_SET) {
    200 			ma.default_attrs = msg_default_attrs;
    201 			pr_field(field_by_value(&msg_default_attrs), " -> ");
    202 		}
    203 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    204 			if (field_by_value(&msg_default_bg)->flags & FLG_SET) {
    205 				ma.default_bg = msg_default_bg;
    206 				pr_field(field_by_value(&msg_default_bg),
    207 				         " -> ");
    208 			}
    209 			if (field_by_value(&msg_default_fg)->flags & FLG_SET) {
    210 				ma.default_fg = msg_default_fg;
    211 				pr_field(field_by_value(&msg_default_fg),
    212 				         " -> ");
    213 			}
    214 		}
    215 
    216 		if (field_by_value(&msg_kernel_attrs)->flags & FLG_SET) {
    217 			ma.kernel_attrs = msg_kernel_attrs;
    218 			pr_field(field_by_value(&msg_kernel_attrs), " -> ");
    219 		}
    220 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    221 			if (field_by_value(&msg_kernel_bg)->flags & FLG_SET) {
    222 				ma.kernel_bg = msg_kernel_bg;
    223 				pr_field(field_by_value(&msg_kernel_bg),
    224 				         " -> ");
    225 			}
    226 			if (field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    227 				ma.kernel_fg = msg_kernel_fg;
    228 				pr_field(field_by_value(&msg_kernel_fg),
    229 				         " -> ");
    230 			}
    231 		}
    232 
    233 		if (ioctl(fd, WSDISPLAYIO_SMSGATTRS, &ma) < 0)
    234 			err(1, "WSDISPLAYIO_SMSGATTRS");
    235 	}
    236 
    237 	scroll_l.which = 0;
    238 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_SET)
    239 		scroll_l.which |= WSDISPLAY_SCROLL_DOFASTLINES;
    240 	if (field_by_value(&scroll_l.slowlines)->flags & FLG_SET)
    241 		scroll_l.which |= WSDISPLAY_SCROLL_DOSLOWLINES;
    242 	if (scroll_l.which != 0 &&
    243 	    ioctl(fd, WSDISPLAYIO_DSSCROLL, &scroll_l) < 0)
    244 		err (1, "WSDISPLAYIO_DSSCROLL");
    245 	if (scroll_l.which & WSDISPLAY_SCROLL_DOFASTLINES)
    246 		pr_field(field_by_value(&scroll_l.fastlines), " -> ");
    247 	if (scroll_l.which & WSDISPLAY_SCROLL_DOSLOWLINES)
    248 		pr_field(field_by_value(&scroll_l.slowlines), " -> ");
    249 }
    250