Home | History | Annotate | Line # | Download | only in wsconsctl
display.c revision 1.8
      1 /*	$NetBSD: display.c,v 1.8 2004/07/30 15:22:42 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 <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(fd)
     77 	int fd;
     78 {
     79 	if (field_by_value(&dpytype)->flags & FLG_GET)
     80 		if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
     81 			err(1, "WSDISPLAYIO_GTYPE");
     82 
     83 	if (field_by_value(&border)->flags & FLG_GET)
     84 		if (ioctl(fd, WSDISPLAYIO_GBORDER, &border) < 0)
     85 			field_disable_by_value(&border);
     86 
     87 	if (field_by_value(&msg_default_attrs)->flags & FLG_GET ||
     88 	    field_by_value(&msg_default_bg)->flags & FLG_GET ||
     89 	    field_by_value(&msg_default_fg)->flags & FLG_GET ||
     90 	    field_by_value(&msg_kernel_attrs)->flags & FLG_GET ||
     91 	    field_by_value(&msg_kernel_bg)->flags & FLG_GET ||
     92 	    field_by_value(&msg_kernel_fg)->flags & FLG_GET) {
     93 		struct wsdisplay_msgattrs ma;
     94 
     95 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0) {
     96 			field_disable_by_value(&msg_default_attrs);
     97 			field_disable_by_value(&msg_default_bg);
     98 			field_disable_by_value(&msg_default_fg);
     99 			field_disable_by_value(&msg_kernel_attrs);
    100 			field_disable_by_value(&msg_kernel_bg);
    101 			field_disable_by_value(&msg_kernel_fg);
    102 		} else {
    103 			msg_default_attrs = ma.default_attrs;
    104 			if (ma.default_attrs & WSATTR_WSCOLORS) {
    105 				msg_default_bg = ma.default_bg;
    106 				msg_default_fg = ma.default_fg;
    107 			} else
    108 				msg_default_bg = msg_default_fg = -1;
    109 
    110 			msg_kernel_attrs = ma.kernel_attrs;
    111 			if (ma.kernel_attrs & WSATTR_WSCOLORS) {
    112 				msg_kernel_bg = ma.kernel_bg;
    113 				msg_kernel_fg = ma.kernel_fg;
    114 			} else
    115 				msg_kernel_bg = msg_kernel_fg = -1;
    116 		}
    117 	}
    118 
    119 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_GET ||
    120 	    field_by_value(&scroll_l.slowlines)->flags & FLG_GET) {
    121 		if (ioctl(fd, WSDISPLAYIO_DGSCROLL, &scroll_l) < 0) {
    122 			field_disable_by_value(&scroll_l.fastlines);
    123 			field_disable_by_value(&scroll_l.slowlines);
    124 		}
    125 	}
    126 }
    127 
    128 void
    129 display_put_values(fd)
    130 	int fd;
    131 {
    132 	if (field_by_value(&font.name)->flags & FLG_SET) {
    133 		if (ioctl(fd, WSDISPLAYIO_SFONT, &font) < 0)
    134 			err(1, "WSDISPLAYIO_SFONT");
    135 		pr_field(field_by_value(&font.name), " -> ");
    136 	}
    137 
    138 	if (field_by_value(&border)->flags & FLG_SET) {
    139 		if (ioctl(fd, WSDISPLAYIO_SBORDER, &border) < 0)
    140 			err(1, "WSDISPLAYIO_SBORDER");
    141 		pr_field(field_by_value(&border), " -> ");
    142 	}
    143 
    144 	if (field_by_value(&msg_default_attrs)->flags & FLG_SET ||
    145 	    field_by_value(&msg_default_bg)->flags & FLG_SET ||
    146 	    field_by_value(&msg_default_fg)->flags & FLG_SET ||
    147 	    field_by_value(&msg_kernel_attrs)->flags & FLG_SET ||
    148 	    field_by_value(&msg_kernel_bg)->flags & FLG_SET ||
    149 	    field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    150 		struct wsdisplay_msgattrs ma;
    151 
    152 		if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0)
    153 			err(1, "WSDISPLAYIO_GMSGATTRS");
    154 
    155 		if (field_by_value(&msg_default_attrs)->flags & FLG_SET) {
    156 			ma.default_attrs = msg_default_attrs;
    157 			pr_field(field_by_value(&msg_default_attrs), " -> ");
    158 		}
    159 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    160 			if (field_by_value(&msg_default_bg)->flags & FLG_SET) {
    161 				ma.default_bg = msg_default_bg;
    162 				pr_field(field_by_value(&msg_default_bg),
    163 				         " -> ");
    164 			}
    165 			if (field_by_value(&msg_default_fg)->flags & FLG_SET) {
    166 				ma.default_fg = msg_default_fg;
    167 				pr_field(field_by_value(&msg_default_fg),
    168 				         " -> ");
    169 			}
    170 		}
    171 
    172 		if (field_by_value(&msg_kernel_attrs)->flags & FLG_SET) {
    173 			ma.kernel_attrs = msg_kernel_attrs;
    174 			pr_field(field_by_value(&msg_kernel_attrs), " -> ");
    175 		}
    176 		if (ma.default_attrs & WSATTR_WSCOLORS) {
    177 			if (field_by_value(&msg_kernel_bg)->flags & FLG_SET) {
    178 				ma.kernel_bg = msg_kernel_bg;
    179 				pr_field(field_by_value(&msg_kernel_bg),
    180 				         " -> ");
    181 			}
    182 			if (field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
    183 				ma.kernel_fg = msg_kernel_fg;
    184 				pr_field(field_by_value(&msg_kernel_fg),
    185 				         " -> ");
    186 			}
    187 		}
    188 
    189 		if (ioctl(fd, WSDISPLAYIO_SMSGATTRS, &ma) < 0)
    190 			err(1, "WSDISPLAYIO_SMSGATTRS");
    191 	}
    192 
    193 	scroll_l.which = 0;
    194 	if (field_by_value(&scroll_l.fastlines)->flags & FLG_SET)
    195 		scroll_l.which |= WSDISPLAY_SCROLL_DOFASTLINES;
    196 	if (field_by_value(&scroll_l.slowlines)->flags & FLG_SET)
    197 		scroll_l.which |= WSDISPLAY_SCROLL_DOSLOWLINES;
    198 	if (scroll_l.which != 0 &&
    199 	    ioctl(fd, WSDISPLAYIO_DSSCROLL, &scroll_l) < 0)
    200 		err (1, "WSDISPLAYIO_DSSCROLL");
    201 	if (scroll_l.which & WSDISPLAY_SCROLL_DOFASTLINES)
    202 		pr_field(field_by_value(&scroll_l.fastlines), " -> ");
    203 	if (scroll_l.which & WSDISPLAY_SCROLL_DOSLOWLINES)
    204 		pr_field(field_by_value(&scroll_l.slowlines), " -> ");
    205 }
    206