Home | History | Annotate | Line # | Download | only in wsconsctl
display.c revision 1.9
      1 /*	$NetBSD: display.c,v 1.9 2005/01/19 20:37:52 xtraeme 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_scroll_data scroll_l;
     55 static int msg_default_attrs, msg_default_bg, msg_default_fg;
     56 static int msg_kernel_attrs, msg_kernel_bg, msg_kernel_fg;
     57 
     58 struct field display_field_tab[] = {
     59     { "border",			&border,	FMT_COLOR,	FLG_MODIFY },
     60     { "type",			&dpytype,	FMT_DPYTYPE,	FLG_RDONLY },
     61     { "font",			&font.name,	FMT_STRING,	FLG_WRONLY },
     62     { "scroll.fastlines",	&scroll_l.fastlines, FMT_UINT, FLG_MODIFY },
     63     { "scroll.slowlines",	&scroll_l.slowlines, FMT_UINT, FLG_MODIFY },
     64     { "msg.default.attrs",	&msg_default_attrs, FMT_ATTRS,	FLG_MODIFY },
     65     { "msg.default.bg",		&msg_default_bg, FMT_COLOR,	FLG_MODIFY },
     66     { "msg.default.fg",		&msg_default_fg, FMT_COLOR,	FLG_MODIFY },
     67     { "msg.kernel.attrs",	&msg_kernel_attrs, FMT_ATTRS,	FLG_MODIFY },
     68     { "msg.kernel.bg",		&msg_kernel_bg, FMT_COLOR,	FLG_MODIFY },
     69     { "msg.kernel.fg",		&msg_kernel_fg, FMT_COLOR,	FLG_MODIFY },
     70 };
     71 
     72 int display_field_tab_len = sizeof(display_field_tab)/
     73 			     sizeof(display_field_tab[0]);
     74 
     75 void
     76 display_get_values(int fd)
     77 {
     78 	if (field_by_value(&dpytype)->flags & FLG_GET)
     79 		if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
     80 			err(1, "WSDISPLAYIO_GTYPE");
     81 
     82 	if (field_by_value(&border)->flags & FLG_GET)
     83 		if (ioctl(fd, WSDISPLAYIO_GBORDER, &border) < 0)
     84 			field_disable_by_value(&border);
     85 
     86 	if (field_by_value(&msg_default_attrs)->flags & FLG_GET ||
     87 	    field_by_value(&msg_default_bg)->flags & FLG_GET ||
     88 	    field_by_value(&msg_default_fg)->flags & FLG_GET ||
     89 	    field_by_value(&msg_kernel_attrs)->flags & FLG_GET ||
     90 	    field_by_value(&msg_kernel_bg)->flags & FLG_GET ||
     91 	    field_by_value(&msg_kernel_fg)->flags & FLG_GET) {
     92 		struct wsdisplay_msgattrs ma;
     93 
     94 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0) {
     95 			field_disable_by_value(&msg_default_attrs);
     96 			field_disable_by_value(&msg_default_bg);
     97 			field_disable_by_value(&msg_default_fg);
     98 			field_disable_by_value(&msg_kernel_attrs);
     99 			field_disable_by_value(&msg_kernel_bg);
    100 			field_disable_by_value(&msg_kernel_fg);
    101 		} else {
    102 			msg_default_attrs = ma.default_attrs;
    103 			if (ma.default_attrs & WSATTR_WSCOLORS) {
    104 				msg_default_bg = ma.default_bg;
    105 				msg_default_fg = ma.default_fg;
    106 			} else
    107 				msg_default_bg = msg_default_fg = -1;
    108 
    109 			msg_kernel_attrs = ma.kernel_attrs;
    110 			if (ma.kernel_attrs & WSATTR_WSCOLORS) {
    111 				msg_kernel_bg = ma.kernel_bg;
    112 				msg_kernel_fg = ma.kernel_fg;
    113 			} else
    114 				msg_kernel_bg = msg_kernel_fg = -1;
    115 		}
    116 	}
    117 
    118 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_GET ||
    119 	    field_by_value(&scroll_l.slowlines)->flags & FLG_GET) {
    120 		if (ioctl(fd, WSDISPLAYIO_DGSCROLL, &scroll_l) < 0) {
    121 			field_disable_by_value(&scroll_l.fastlines);
    122 			field_disable_by_value(&scroll_l.slowlines);
    123 		}
    124 	}
    125 }
    126 
    127 void
    128 display_put_values(fd)
    129 	int fd;
    130 {
    131 	if (field_by_value(&font.name)->flags & FLG_SET) {
    132 		if (ioctl(fd, WSDISPLAYIO_SFONT, &font) < 0)
    133 			err(1, "WSDISPLAYIO_SFONT");
    134 		pr_field(field_by_value(&font.name), " -> ");
    135 	}
    136 
    137 	if (field_by_value(&border)->flags & FLG_SET) {
    138 		if (ioctl(fd, WSDISPLAYIO_SBORDER, &border) < 0)
    139 			err(1, "WSDISPLAYIO_SBORDER");
    140 		pr_field(field_by_value(&border), " -> ");
    141 	}
    142 
    143 	if (field_by_value(&msg_default_attrs)->flags & FLG_SET ||
    144 	    field_by_value(&msg_default_bg)->flags & FLG_SET ||
    145 	    field_by_value(&msg_default_fg)->flags & FLG_SET ||
    146 	    field_by_value(&msg_kernel_attrs)->flags & FLG_SET ||
    147 	    field_by_value(&msg_kernel_bg)->flags & FLG_SET ||
    148 	    field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    149 		struct wsdisplay_msgattrs ma;
    150 
    151 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0)
    152 			err(1, "WSDISPLAYIO_GMSGATTRS");
    153 
    154 		if (field_by_value(&msg_default_attrs)->flags & FLG_SET) {
    155 			ma.default_attrs = msg_default_attrs;
    156 			pr_field(field_by_value(&msg_default_attrs), " -> ");
    157 		}
    158 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    159 			if (field_by_value(&msg_default_bg)->flags & FLG_SET) {
    160 				ma.default_bg = msg_default_bg;
    161 				pr_field(field_by_value(&msg_default_bg),
    162 				         " -> ");
    163 			}
    164 			if (field_by_value(&msg_default_fg)->flags & FLG_SET) {
    165 				ma.default_fg = msg_default_fg;
    166 				pr_field(field_by_value(&msg_default_fg),
    167 				         " -> ");
    168 			}
    169 		}
    170 
    171 		if (field_by_value(&msg_kernel_attrs)->flags & FLG_SET) {
    172 			ma.kernel_attrs = msg_kernel_attrs;
    173 			pr_field(field_by_value(&msg_kernel_attrs), " -> ");
    174 		}
    175 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    176 			if (field_by_value(&msg_kernel_bg)->flags & FLG_SET) {
    177 				ma.kernel_bg = msg_kernel_bg;
    178 				pr_field(field_by_value(&msg_kernel_bg),
    179 				         " -> ");
    180 			}
    181 			if (field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    182 				ma.kernel_fg = msg_kernel_fg;
    183 				pr_field(field_by_value(&msg_kernel_fg),
    184 				         " -> ");
    185 			}
    186 		}
    187 
    188 		if (ioctl(fd, WSDISPLAYIO_SMSGATTRS, &ma) < 0)
    189 			err(1, "WSDISPLAYIO_SMSGATTRS");
    190 	}
    191 
    192 	scroll_l.which = 0;
    193 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_SET)
    194 		scroll_l.which |= WSDISPLAY_SCROLL_DOFASTLINES;
    195 	if (field_by_value(&scroll_l.slowlines)->flags & FLG_SET)
    196 		scroll_l.which |= WSDISPLAY_SCROLL_DOSLOWLINES;
    197 	if (scroll_l.which != 0 &&
    198 	    ioctl(fd, WSDISPLAYIO_DSSCROLL, &scroll_l) < 0)
    199 		err (1, "WSDISPLAYIO_DSSCROLL");
    200 	if (scroll_l.which & WSDISPLAY_SCROLL_DOFASTLINES)
    201 		pr_field(field_by_value(&scroll_l.fastlines), " -> ");
    202 	if (scroll_l.which & WSDISPLAY_SCROLL_DOSLOWLINES)
    203 		pr_field(field_by_value(&scroll_l.slowlines), " -> ");
    204 }
    205