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