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