xref: /openbsd-src/sbin/wsconsctl/display.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: display.c,v 1.4 2001/07/06 04:11:26 pvalchev Exp $	*/
2 /*	$NetBSD: display.c,v 1.1 1998/12/28 14:01:16 hannken Exp $ */
3 
4 /*-
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Juergen Hannken-Illjes.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/ioctl.h>
41 #include <sys/time.h>
42 #include <dev/wscons/wsconsio.h>
43 #include <err.h>
44 #include "wsconsctl.h"
45 
46 int dpytype;
47 int focus;
48 int burnon, burnoff, vblank, kbdact, msact, outact;
49 
50 struct field display_field_tab[] = {
51     { "type",			&dpytype,	FMT_DPYTYPE,	FLG_RDONLY },
52     { "focus",			&focus,		FMT_UINT,	FLG_MODIFY },
53     { "screen_on",		&burnon,	FMT_UINT,	FLG_MODIFY },
54     { "screen_off",		&burnoff,	FMT_UINT,	FLG_MODIFY },
55     { "vblank",			&vblank,	FMT_BOOL,	FLG_MODIFY },
56     { "kbdact",			&kbdact,	FMT_BOOL,	FLG_MODIFY },
57     { "msact",			&msact,		FMT_BOOL,	FLG_MODIFY },
58     { "outact",			&outact,	FMT_BOOL,	FLG_MODIFY },
59     { NULL }
60 };
61 
62 void
63 display_get_values(pre, fd)
64 	const char *pre;
65 	int fd;
66 {
67 	struct wsdisplay_addscreendata gscr;
68 
69 	if (field_by_value(display_field_tab, &dpytype)->flags & FLG_GET)
70 		if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
71 			err(1, "WSDISPLAYIO_GTYPE");
72 
73 	gscr.idx = -1;
74 	if (field_by_value(display_field_tab, &focus)->flags & FLG_GET) {
75 		if (ioctl(fd, WSDISPLAYIO_GETSCREEN, &gscr) < 0)
76 			err(1, "WSDISPLAYIO_GETSCREEN");
77 	}
78 	else
79 		focus = gscr.idx;
80 
81 	if (field_by_value(display_field_tab, &burnon)->flags & FLG_GET ||
82 	    field_by_value(display_field_tab, &burnoff)->flags & FLG_GET ||
83 	    field_by_value(display_field_tab, &vblank)->flags & FLG_GET ||
84 	    field_by_value(display_field_tab, &kbdact)->flags & FLG_GET ||
85 	    field_by_value(display_field_tab, &msact )->flags & FLG_GET ||
86 	    field_by_value(display_field_tab, &outact)->flags & FLG_GET) {
87 
88 		struct wsdisplay_burner burners;
89 
90 		if (ioctl(fd, WSDISPLAYIO_GBURNER, &burners) < 0)
91 			err(1, "WSDISPLAYIO_GBURNER");
92 
93 		if (field_by_value(display_field_tab, &burnon)->flags & FLG_GET)
94 			burnon = burners.on;
95 
96 		if (field_by_value(display_field_tab, &burnoff)->flags & FLG_GET)
97 			burnoff = burners.off;
98 
99 		if (field_by_value(display_field_tab, &vblank)->flags & FLG_GET)
100 			vblank = burners.flags & WSDISPLAY_BURN_VBLANK;
101 
102 		if (field_by_value(display_field_tab, &kbdact)->flags & FLG_GET)
103 			kbdact = burners.flags & WSDISPLAY_BURN_KBD;
104 
105 		if (field_by_value(display_field_tab, &msact )->flags & FLG_GET)
106 			msact = burners.flags & WSDISPLAY_BURN_MOUSE;
107 
108 		if (field_by_value(display_field_tab, &outact)->flags & FLG_GET)
109 			outact = burners.flags & WSDISPLAY_BURN_OUTPUT;
110 	}
111 }
112 
113 void
114 display_put_values(pre, fd)
115 	const char *pre;
116 	int fd;
117 {
118 	if (field_by_value(display_field_tab, &focus)->flags & FLG_SET)
119 		if (ioctl(fd, WSDISPLAYIO_SETSCREEN, &focus) < 0)
120 			err(1, "WSDISPLAYIO_SETSCREEN");
121 
122 	if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET ||
123 	    field_by_value(display_field_tab, &burnoff)->flags & FLG_SET ||
124 	    field_by_value(display_field_tab, &vblank)->flags & FLG_SET ||
125 	    field_by_value(display_field_tab, &kbdact)->flags & FLG_SET ||
126 	    field_by_value(display_field_tab, &msact )->flags & FLG_SET ||
127 	    field_by_value(display_field_tab, &outact)->flags & FLG_SET) {
128 
129 		struct wsdisplay_burner burners;
130 
131 		if (ioctl(fd, WSDISPLAYIO_GBURNER, &burners) < 0)
132 			err(1, "WSDISPLAYIO_GBURNER");
133 
134 		if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET)
135 			burners.on = burnon;
136 
137 		if (field_by_value(display_field_tab, &burnoff)->flags & FLG_SET)
138 			burners.off = burnoff;
139 
140 		if (field_by_value(display_field_tab, &vblank)->flags & FLG_SET) {
141 			if (vblank)
142 				burners.flags |= WSDISPLAY_BURN_VBLANK;
143 			else
144 				burners.flags &= ~WSDISPLAY_BURN_VBLANK;
145 		}
146 
147 		if (field_by_value(display_field_tab, &kbdact)->flags & FLG_SET) {
148 			if (kbdact)
149 				burners.flags |= WSDISPLAY_BURN_KBD;
150 			else
151 				burners.flags &= ~WSDISPLAY_BURN_KBD;
152 		}
153 
154 		if (field_by_value(display_field_tab, &msact )->flags & FLG_SET) {
155 			if (msact)
156 				burners.flags |= WSDISPLAY_BURN_MOUSE;
157 			else
158 				burners.flags &= ~WSDISPLAY_BURN_MOUSE;
159 		}
160 
161 		if (field_by_value(display_field_tab, &outact)->flags & FLG_SET) {
162 			if (outact)
163 				burners.flags |= WSDISPLAY_BURN_OUTPUT;
164 			else
165 				burners.flags &= ~WSDISPLAY_BURN_OUTPUT;
166 		}
167 
168 		if (ioctl(fd, WSDISPLAYIO_SBURNER, &burners) < 0)
169 			err(1, "WSDISPLAYIO_SBURNER");
170 	}
171 }
172