keyboard.c revision 1.4 1 /* $NetBSD: keyboard.c,v 1.4 2004/05/28 21:44:15 christos 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 #include <dev/wscons/wsksymdef.h>
42 #include <dev/wscons/wsconsio.h>
43 #include <err.h>
44 #include "wsconsctl.h"
45
46 static int kbtype;
47 static int keyclick;
48 static struct wskbd_bell_data bell;
49 static struct wskbd_bell_data dfbell;
50 static struct wscons_keymap mapdata[KS_NUMKEYCODES];
51 struct wskbd_map_data kbmap = { KS_NUMKEYCODES, mapdata }; /* used in map_parse.y
52 and in util.c */
53 static struct wskbd_keyrepeat_data repeat;
54 static struct wskbd_keyrepeat_data dfrepeat;
55 static struct wskbd_scroll_data scroll;
56 static int ledstate;
57 static kbd_t kbdencoding;
58
59 struct field keyboard_field_tab[] = {
60 { "type", &kbtype, FMT_KBDTYPE, FLG_RDONLY },
61 { "bell.pitch", &bell.pitch, FMT_UINT, FLG_MODIFY },
62 { "bell.period", &bell.period, FMT_UINT, FLG_MODIFY },
63 { "bell.volume", &bell.volume, FMT_UINT, FLG_MODIFY },
64 { "bell.pitch.default", &dfbell.pitch, FMT_UINT, FLG_MODIFY },
65 { "bell.period.default", &dfbell.period, FMT_UINT, FLG_MODIFY },
66 { "bell.volume.default", &dfbell.volume, FMT_UINT, FLG_MODIFY },
67 { "map", &kbmap, FMT_KBMAP, FLG_MODIFY|FLG_NOAUTO },
68 { "repeat.del1", &repeat.del1, FMT_UINT, FLG_MODIFY },
69 { "repeat.deln", &repeat.delN, FMT_UINT, FLG_MODIFY },
70 { "repeat.del1.default", &dfrepeat.del1, FMT_UINT, FLG_MODIFY },
71 { "repeat.deln.default", &dfrepeat.delN, FMT_UINT, FLG_MODIFY },
72 { "ledstate", &ledstate, FMT_UINT, 0 },
73 { "encoding", &kbdencoding, FMT_KBDENC, FLG_MODIFY },
74 { "keyclick", &keyclick, FMT_UINT, FLG_MODIFY },
75 { "scroll.mode", &scroll.mode, FMT_UINT, FLG_MODIFY },
76 { "scroll.modifier", &scroll.modifier, FMT_UINT, FLG_MODIFY },
77 };
78
79 int keyboard_field_tab_len = sizeof(keyboard_field_tab)/
80 sizeof(keyboard_field_tab[0]);
81
82 void
83 keyboard_get_values(fd)
84 int fd;
85 {
86 if (field_by_value(&kbtype)->flags & FLG_GET)
87 if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0)
88 err(1, "WSKBDIO_GTYPE");
89
90 bell.which = 0;
91 if (field_by_value(&bell.pitch)->flags & FLG_GET)
92 bell.which |= WSKBD_BELL_DOPITCH;
93 if (field_by_value(&bell.period)->flags & FLG_GET)
94 bell.which |= WSKBD_BELL_DOPERIOD;
95 if (field_by_value(&bell.volume)->flags & FLG_GET)
96 bell.which |= WSKBD_BELL_DOVOLUME;
97 if (bell.which != 0 && ioctl(fd, WSKBDIO_GETBELL, &bell) < 0)
98 err(1, "WSKBDIO_GETBELL");
99
100 dfbell.which = 0;
101 if (field_by_value(&dfbell.pitch)->flags & FLG_GET)
102 dfbell.which |= WSKBD_BELL_DOPITCH;
103 if (field_by_value(&dfbell.period)->flags & FLG_GET)
104 dfbell.which |= WSKBD_BELL_DOPERIOD;
105 if (field_by_value(&dfbell.volume)->flags & FLG_GET)
106 dfbell.which |= WSKBD_BELL_DOVOLUME;
107 if (dfbell.which != 0 &&
108 ioctl(fd, WSKBDIO_GETDEFAULTBELL, &dfbell) < 0)
109 err(1, "WSKBDIO_GETDEFAULTBELL");
110
111 if (field_by_value(&kbmap)->flags & FLG_GET) {
112 kbmap.maplen = KS_NUMKEYCODES;
113 if (ioctl(fd, WSKBDIO_GETMAP, &kbmap) < 0)
114 err(1, "WSKBDIO_GETMAP");
115 }
116
117 repeat.which = 0;
118 if (field_by_value(&repeat.del1)->flags & FLG_GET)
119 repeat.which |= WSKBD_KEYREPEAT_DODEL1;
120 if (field_by_value(&repeat.delN)->flags & FLG_GET)
121 repeat.which |= WSKBD_KEYREPEAT_DODELN;
122 if (repeat.which != 0 &&
123 ioctl(fd, WSKBDIO_GETKEYREPEAT, &repeat) < 0)
124 err(1, "WSKBDIO_GETKEYREPEAT");
125
126 dfrepeat.which = 0;
127 if (field_by_value(&dfrepeat.del1)->flags & FLG_GET)
128 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1;
129 if (field_by_value(&dfrepeat.delN)->flags & FLG_GET)
130 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN;
131 if (dfrepeat.which != 0 &&
132 ioctl(fd, WSKBDIO_GETKEYREPEAT, &dfrepeat) < 0)
133 err(1, "WSKBDIO_GETKEYREPEAT");
134
135 if (field_by_value(&ledstate)->flags & FLG_GET)
136 if (ioctl(fd, WSKBDIO_GETLEDS, &ledstate) < 0)
137 err(1, "WSKBDIO_GETLEDS");
138
139 if (field_by_value(&kbdencoding)->flags & FLG_GET)
140 if (ioctl(fd, WSKBDIO_GETENCODING, &kbdencoding) < 0)
141 err(1, "WSKBDIO_GETENCODING");
142
143 if (field_by_value(&keyclick)->flags & FLG_GET) {
144 ioctl(fd, WSKBDIO_GETKEYCLICK, &keyclick);
145 /* Optional; don't complain. */
146 }
147
148 scroll.which = 0;
149 if (field_by_value(&scroll.mode)->flags & FLG_GET)
150 scroll.which |= WSKBD_SCROLL_DOMODE;
151 if (field_by_value(&scroll.modifier)->flags & FLG_GET)
152 scroll.which |= WSKBD_SCROLL_DOMODIFIER;
153 if (scroll.which != 0 &&
154 ioctl(fd, WSKBDIO_GETSCROLL, &scroll) < 0)
155 err(1, "WSKBDIO_GETSCROLL");
156 }
157
158 void
159 keyboard_put_values(fd)
160 int fd;
161 {
162 bell.which = 0;
163 if (field_by_value(&bell.pitch)->flags & FLG_SET)
164 bell.which |= WSKBD_BELL_DOPITCH;
165 if (field_by_value(&bell.period)->flags & FLG_SET)
166 bell.which |= WSKBD_BELL_DOPERIOD;
167 if (field_by_value(&bell.volume)->flags & FLG_SET)
168 bell.which |= WSKBD_BELL_DOVOLUME;
169 if (bell.which != 0 && ioctl(fd, WSKBDIO_SETBELL, &bell) < 0)
170 err(1, "WSKBDIO_SETBELL");
171 if (bell.which & WSKBD_BELL_DOPITCH)
172 pr_field(field_by_value(&bell.pitch), " -> ");
173 if (bell.which & WSKBD_BELL_DOPERIOD)
174 pr_field(field_by_value(&bell.period), " -> ");
175 if (bell.which & WSKBD_BELL_DOVOLUME)
176 pr_field(field_by_value(&bell.volume), " -> ");
177
178 dfbell.which = 0;
179 if (field_by_value(&dfbell.pitch)->flags & FLG_SET)
180 dfbell.which |= WSKBD_BELL_DOPITCH;
181 if (field_by_value(&dfbell.period)->flags & FLG_SET)
182 dfbell.which |= WSKBD_BELL_DOPERIOD;
183 if (field_by_value(&dfbell.volume)->flags & FLG_SET)
184 dfbell.which |= WSKBD_BELL_DOVOLUME;
185 if (dfbell.which != 0 &&
186 ioctl(fd, WSKBDIO_SETDEFAULTBELL, &dfbell) < 0)
187 err(1, "WSKBDIO_SETDEFAULTBELL");
188 if (dfbell.which & WSKBD_BELL_DOPITCH)
189 pr_field(field_by_value(&dfbell.pitch), " -> ");
190 if (dfbell.which & WSKBD_BELL_DOPERIOD)
191 pr_field(field_by_value(&dfbell.period), " -> ");
192 if (dfbell.which & WSKBD_BELL_DOVOLUME)
193 pr_field(field_by_value(&dfbell.volume), " -> ");
194
195 if (field_by_value(&kbmap)->flags & FLG_SET) {
196 if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0)
197 err(1, "WSKBDIO_SETMAP");
198 pr_field(field_by_value(&kbmap), " -> ");
199 }
200
201 repeat.which = 0;
202 if (field_by_value(&repeat.del1)->flags & FLG_SET)
203 repeat.which |= WSKBD_KEYREPEAT_DODEL1;
204 if (field_by_value(&repeat.delN)->flags & FLG_SET)
205 repeat.which |= WSKBD_KEYREPEAT_DODELN;
206 if (repeat.which != 0 &&
207 ioctl(fd, WSKBDIO_SETKEYREPEAT, &repeat) < 0)
208 err(1, "WSKBDIO_SETKEYREPEAT");
209 if (repeat.which & WSKBD_KEYREPEAT_DODEL1)
210 pr_field(field_by_value(&repeat.del1), " -> ");
211 if (repeat.which & WSKBD_KEYREPEAT_DODELN)
212 pr_field(field_by_value(&repeat.delN), " -> ");
213
214 dfrepeat.which = 0;
215 if (field_by_value(&dfrepeat.del1)->flags & FLG_SET)
216 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1;
217 if (field_by_value(&dfrepeat.delN)->flags & FLG_SET)
218 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN;
219 if (dfrepeat.which != 0 &&
220 ioctl(fd, WSKBDIO_SETDEFAULTKEYREPEAT, &dfrepeat) < 0)
221 err(1, "WSKBDIO_SETDEFAULTKEYREPEAT");
222 if (dfrepeat.which &WSKBD_KEYREPEAT_DODEL1)
223 pr_field(field_by_value(&dfrepeat.del1), " -> ");
224 if (dfrepeat.which & WSKBD_KEYREPEAT_DODELN)
225 pr_field(field_by_value(&dfrepeat.delN), " -> ");
226
227 if (field_by_value(&ledstate)->flags & FLG_SET) {
228 if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0)
229 err(1, "WSKBDIO_SETLEDS");
230 pr_field(field_by_value(&ledstate), " -> ");
231 }
232
233 if (field_by_value(&kbdencoding)->flags & FLG_SET) {
234 if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0)
235 err(1, "WSKBDIO_SETENCODING");
236 pr_field(field_by_value(&kbdencoding), " -> ");
237 }
238
239 if (field_by_value(&keyclick)->flags & FLG_SET) {
240 if (ioctl(fd, WSKBDIO_SETKEYCLICK, &keyclick) < 0)
241 err(1, "WSKBDIO_SETKEYCLICK");
242 pr_field(field_by_value(&keyclick), " -> ");
243 }
244
245
246 scroll.which = 0;
247 if (field_by_value(&scroll.mode)->flags & FLG_SET)
248 scroll.which |= WSKBD_SCROLL_DOMODE;
249 if (field_by_value(&scroll.modifier)->flags & FLG_SET)
250 scroll.which |= WSKBD_SCROLL_DOMODIFIER;
251
252 if (scroll.which & WSKBD_SCROLL_DOMODE)
253 pr_field(field_by_value(&scroll.mode), " -> ");
254 if (scroll.which & WSKBD_SCROLL_DOMODIFIER)
255 pr_field(field_by_value(&scroll.modifier), " -> ");
256 if (scroll.which != 0 &&
257 ioctl(fd, WSKBDIO_SETSCROLL, &scroll) < 0)
258 err (1, "WSKBDIO_SETSCROLL");
259 }
260
261