xref: /titanic_41/usr/src/uts/common/sys/vuid_event.h (revision 7db6e34e0974b29ab599ed5dbc95a2f71810f321)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_VUID_EVENT_H
28 #define	_SYS_VUID_EVENT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/types32.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * This file describes a virtual user input device (vuid) interface.  This
41  * is an interface between input devices and their clients.  The interface
42  * defines an idealized user input device that may not correspond to any
43  * existing physical collection of input devices.
44  *
45  * It is targeted to input devices that gather command data from humans,
46  * e.g., mice, keyboards, tablets, joysticks, light pens, knobs, sliders,
47  * buttons, ascii terminals, etc.  The vuid interface is specifically not
48  * designed to support input devices that produce voluminous amounts of
49  * data, e.g., input scanners, disk drives, voice packets.
50  *
51  * Here are some of the properties that are expected of a typical client
52  * of vuid:
53  *
54  *	The client has a richer user interface than can be supported by
55  *	a simple ascii terminal.
56  *
57  *	The client serializes multiple input devices being used
58  *	by the user into a single stream of events.
59  *
60  *	The client preserves the entire state of its input so that
61  *	it may query this state.
62  *
63  * Here are some features that vuid provides to its clients:
64  *
65  *	A client may extend the capabilities of the predefined vuid by
66  *	adding input devices.  A client wants to be able to do this in
67  *	a way that fits smoothly with its existing input paradigm.
68  *
69  *	A client can write its code to be input device independent.  A
70  *	client can replace the underlaying physical devices and not
71  *	have to be concerned.  In fact, the vuid interface doesn't
72  *	really care about physical devices.  One physical device can
73  *	masquerade a many logical devices and many physical devices can
74  *	look like a single logical device.
75  *
76  * This file defines the protocol that makes up the virtual user input
77  * device.  This includes:
78  *
79  *	The vuid station codes and there meanings.
80  *
81  *	The form by which changes to vuid stations, i.e., firm events,
82  *	are communicated to clients (typically via the read system
83  *	call).
84  *
85  *	The form by which clients send commands to input devices that
86  *	support the vuid (typically via an ioctl system call to send
87  *	vuid instead of a native byte stream).
88  *
89  * Explicitly, this file does not define:
90  *
91  *	How to store the state of the vuid
92  *	(see ../sunwindowdev/vuid_state.h).
93  *
94  *	How to dynamically allocate additional vuid segments in order
95  *	to extend the vuid (one could statically allocate additional
96  *	vuid segments by treating this file as the central registry
97  *	of vuid segments).
98  */
99 
100 /*
101  * VUID_SEG_SIZE is the size of a virtual user input "device" address space
102  * segment.
103  */
104 #define	VUID_SEG_SIZE	(256)
105 
106 /*
107  * This is the central registry of virtual user input devices.
108  * To allocate a new vuid:
109  *
110  *	o Choose an unused portion of the address space.
111  *	  Vuids from 0x00 to 0x7F are reserved for Sun implementers.
112  *	  Vuids from 0x80 to 0xFF are reserved for Sun customers.
113  *
114  *	o Note the new device with a *_DEVID define.  Breifly describe
115  *	  the purpose/usage of the device.  Point to the place where
116  *	  more information can be found.
117  *
118  *	o Note the new device with a VUID_* entry in the Vuid_device
119  *	  enumeration.
120  *
121  *	o List the specific event codes in another header file that is
122  *	  specific to the new device (ASCII_DEVID, TOP_DEVID &
123  *	  WORKSTATION_DEVID events are listing here for historical
124  *	  reasons).
125  */
126 
127 #define	ASCII_DEVID		0x00
128 	/* Ascii codes, which include META codes and 8-bit EUC codes */
129 	/* (see below) */
130 #define	TOP_DEVID		0x01
131 	/* Top codes, which is ASCII with the 9th bit on (see below) */
132 #define	ISO_DEVID		0x02
133 	/* ISO characters 0x80 - 0xFF (backwards compatibility) */
134 /* ... Sun implementers add new device ids here ... */
135 #define	WHEEL_DEVID		0x78
136 #define	LIGHTPEN_DEVID		0x79
137 	/* Lightpen events for	Lightpen */
138 #define	BUTTON_DEVID		0x7A
139 	/* Button events from Sun button box */
140 #define	DIAL_DEVID		0x7B
141 	/* Dial events from Sun dial box */
142 #define	SUNVIEW_DEVID		0x7C
143 	/* Sunview Semantic events */
144 #define	PANEL_DEVID		0x7D
145 	/* Panel subwindow package event codes passed around internal */
146 	/* to the panel package (see <suntool/panel.h>) */
147 #define	SCROLL_DEVID		0x7E
148 	/* Scrollbar package event codes passed to scrollbar clients on */
149 	/* interesting scrollbar activity (see <suntool/scrollbar.h>) */
150 #define	WORKSTATION_DEVID	0x7F
151 	/* Virtual keyboard and locator (mouse) related event codes */
152 	/* that describe a basic "workstation" device collection (see below). */
153 	/* This device is a bit of a hodge podge for historical reasons; */
154 	/* the middle of the address space has SunWindows related events */
155 	/* in it (see <sunwindow/win_input.h >), and the virtual keyboard */
156 	/* and virtual locator are thrown together. */
157 /* ... Sun customers add new device ids here ... */
158 #define	LAST_DEVID		0xFF
159 	/* No more device ids beyond LAST_DEVID */
160 
161 typedef enum vuid_device {
162 	VUID_ASCII = ASCII_DEVID,
163 	VUID_TOP = TOP_DEVID,
164 	VUID_ISO = ISO_DEVID,
165 	VUID_WHEEL = WHEEL_DEVID,
166 	VUID_LIGHTPEN = LIGHTPEN_DEVID,
167 	VUID_DIAL = DIAL_DEVID,
168 	VUID_SUNVIEW = SUNVIEW_DEVID,
169 	VUID_PANEL = PANEL_DEVID,
170 	VUID_SCROLL = SCROLL_DEVID,
171 	VUID_WORKSTATION = WORKSTATION_DEVID,
172 	VUID_LAST = LAST_DEVID
173 } Vuid_device;
174 
175 #define	vuid_first(devid)	((devid) << 8)
176 #define	vuid_last(devid)	(((devid) << 8)+VUID_SEG_SIZE-1)
177 #define	vuid_in_range(devid, id) \
178 	    ((id >= vuid_first(devid)) && (id <= vuid_last(devid)))
179 
180 /*
181  * EUC (Extended UNIX Code) device related definitions:
182  */
183 #define	EUC_FIRST	(0)
184 #define	EUC_LAST	(255)
185 
186 /*
187  * Old ASCII definitions for backwards compatibility:
188  */
189 #define	ASCII_FIRST	(0)
190 #define	ASCII_LAST	(127)
191 #define	META_FIRST	(128)
192 #define	META_LAST	(255)
193 
194 /*
195  * Top device related definitions:
196  */
197 #define	TOP_FIRST	(256)
198 #define	TOP_LAST	(511)
199 
200 /*
201  * Old ISO definitions for backwards compatibility:
202  */
203 #define	ISO_FIRST	(512)
204 #define	ISO_LAST	(767)
205 
206 /*
207  * Workstation device related definitions.  First are virtual keyboard
208  * assignments.	 All events for the virtual keyboard have 0 (went up) or
209  * 1 (went down) values.
210  */
211 
212 #define	VKEY_FIRST	vuid_first(WORKSTATION_DEVID)
213 #define	VKEY_UP		0
214 #define	VKEY_DOWN	1
215 
216 #define	VKEY_KBD_CODES	(128)	/* The number of event codes in a subset of */
217 				/* the workstation device's address space */
218 				/* that belong to the virtual keyboard */
219 
220 #define	VKEY_FIRSTPSEUDO	(VKEY_FIRST)			/* 32512 */
221 /*
222  * VKEY_FIRSTPSEUDO thru VKEY_LASTPSEUDO are taken (for historical
223  * reasons) by SunWindows related codes (see <sunwindow/win_input.h >).
224  */
225 #define	VKEY_LASTPSEUDO		(VKEY_FIRSTPSEUDO+15)		/* 32527 */
226 
227 #define	VKEY_FIRSTSHIFT		(VKEY_LASTPSEUDO+1)		/* 32528 */
228 #define	SHIFT_CAPSLOCK		(VKEY_FIRSTSHIFT+0)		/* 32528 */
229 #define	SHIFT_LOCK		(VKEY_FIRSTSHIFT+1)		/* 32529 */
230 #define	SHIFT_LEFT		(VKEY_FIRSTSHIFT+2)		/* 32530 */
231 #define	SHIFT_RIGHT		(VKEY_FIRSTSHIFT+3)		/* 32531 */
232 #define	SHIFT_LEFTCTRL		(VKEY_FIRSTSHIFT+4)		/* 32532 */
233 /* SHIFT_CTRL is for compatability with previous releases */	/* 32532 */
234 #define	SHIFT_CTRL		SHIFT_LEFTCTRL			/* 32532 */
235 #define	SHIFT_RIGHTCTRL		(VKEY_FIRSTSHIFT+5)		/* 32533 */
236 #define	SHIFT_META		(VKEY_FIRSTSHIFT+6)		/* 32534 */
237 #define	SHIFT_TOP		(VKEY_FIRSTSHIFT+7)		/* 32535 */
238 #define	SHIFT_CMD		(VKEY_FIRSTSHIFT+8)		/* 32536 */
239 #define	SHIFT_ALTG		(VKEY_FIRSTSHIFT+9)		/* 32537 */
240 #define	SHIFT_ALT		(VKEY_FIRSTSHIFT+10)		/* 32538 */
241 #define	SHIFT_NUMLOCK		(VKEY_FIRSTSHIFT+11)		/* 32539 */
242 #define	VKEY_LASTSHIFT		(VKEY_FIRSTSHIFT+15)		/* 32543 */
243 
244 #define	VKEY_FIRSTFUNC		(VKEY_LASTSHIFT+1)		/* 32544 */
245 
246 #define	BUT_FIRST		(VKEY_FIRSTFUNC)		/* 32544 */
247 #define	BUT(i)			((BUT_FIRST)+(i)-1)		/* 32544+i-1 */
248 #define	BUT_LAST		(BUT_FIRST+9)			/* 32553 */
249 
250 #define	KEY_LEFTFIRST		((BUT_LAST)+1)			/* 32554 */
251 #define	KEY_LEFT(i)		((KEY_LEFTFIRST)+(i)-1)		/* 32554+i-1 */
252 #define	KEY_LEFTLAST		((KEY_LEFTFIRST)+15)		/* 32569 */
253 
254 #define	KEY_RIGHTFIRST		((KEY_LEFTLAST)+1)		/* 32570 */
255 #define	KEY_RIGHT(i)		((KEY_RIGHTFIRST)+(i)-1)	/* 32570+i-1 */
256 #define	KEY_RIGHTLAST		((KEY_RIGHTFIRST)+15)		/* 32585 */
257 
258 #define	KEY_TOPFIRST		((KEY_RIGHTLAST)+1)		/* 32586 */
259 #define	KEY_TOP(i)		((KEY_TOPFIRST)+(i)-1)		/* 32586+i-1 */
260 #define	KEY_TOPLAST		((KEY_TOPFIRST)+15)		/* 32601 */
261 
262 #define	KEY_BOTTOMLEFT		((KEY_TOPLAST)+1)		/* 32602 */
263 #define	KEY_BOTTOMRIGHT		((KEY_BOTTOMLEFT)+1)		/* 32603 */
264 #define	KEY_BOTTOMFIRST		((KEY_TOPLAST)+1)		/* 32602 */
265 #define	KEY_BOTTOM(i)		((KEY_BOTTOMFIRST)+(i)-1)	/* 32602+i-1 */
266 #define	KEY_BOTTOMLAST		((KEY_BOTTOMFIRST)+15)		/* 32617 */
267 
268 #define	VKEY_LASTFUNC		(VKEY_FIRSTFUNC+73)		/* 32617 */
269 
270 #define	VKEY_FIRSTPAD		(VKEY_LASTFUNC+1)		/* 32618 */
271 
272 #define	VKEY_PADEQUAL		(VKEY_FIRSTPAD+0)		/* 32618 */
273 #define	VKEY_PADSLASH		(VKEY_FIRSTPAD+1)		/* 32619 */
274 #define	VKEY_PADSTAR		(VKEY_FIRSTPAD+2)		/* 32620 */
275 #define	VKEY_PADMINUS		(VKEY_FIRSTPAD+3)		/* 32621 */
276 #define	VKEY_PADSEP		(VKEY_FIRSTPAD+4)		/* 32622 */
277 #define	VKEY_PAD7		(VKEY_FIRSTPAD+5)		/* 32623 */
278 #define	VKEY_PAD8		(VKEY_FIRSTPAD+6)		/* 32624 */
279 #define	VKEY_PAD9		(VKEY_FIRSTPAD+7)		/* 32625 */
280 #define	VKEY_PADPLUS		(VKEY_FIRSTPAD+8)		/* 32626 */
281 #define	VKEY_PAD4		(VKEY_FIRSTPAD+9)		/* 32627 */
282 #define	VKEY_PAD5		(VKEY_FIRSTPAD+10)		/* 32628 */
283 #define	VKEY_PAD6		(VKEY_FIRSTPAD+11)		/* 32629 */
284 #define	VKEY_PAD1		(VKEY_FIRSTPAD+12)		/* 32630 */
285 #define	VKEY_PAD2		(VKEY_FIRSTPAD+13)		/* 32631 */
286 #define	VKEY_PAD3		(VKEY_FIRSTPAD+14)		/* 32632 */
287 #define	VKEY_PAD0		(VKEY_FIRSTPAD+15)		/* 32633 */
288 #define	VKEY_PADDOT		(VKEY_FIRSTPAD+16)		/* 32634 */
289 #define	VKEY_PADENTER		(VKEY_FIRSTPAD+17)		/* 32635 */
290 
291 #define	VKEY_LASTPAD		(VKEY_FIRSTPAD+17)		/* 32635 */
292 
293 #define	VKEY_LAST		(VKEY_FIRST+VKEY_KBD_CODES-1)	/* 32639 */
294 
295 /*
296  * More workstation device definitions.	 These are virtual locator
297  * related event code assignments.  Values for these events are int.
298  * VLOC_BATCH's value is a uint_t that describes the number of events
299  * that follow that should be treated as a batch.
300  */
301 #define	MOUSE_DEVID	WORKSTATION_DEVID	/* Backward compatibility */
302 
303 #define	VLOC_FIRST		(VKEY_LAST+1)			/* 32640 */
304 #define	LOC_FIRST_DELTA		(VLOC_FIRST+0)			/* 32640 */
305 #define	LOC_X_DELTA		(VLOC_FIRST+0)			/* 32640 */
306 #define	LOC_Y_DELTA		(VLOC_FIRST+1)			/* 32641 */
307 #define	LOC_LAST_DELTA		(VLOC_FIRST+1)			/* 32641 */
308 
309 #define	LOC_FIRST_ABSOLUTE	(VLOC_FIRST+2)			/* 32642 */
310 #define	LOC_X_ABSOLUTE		(VLOC_FIRST+2)			/* 32642 */
311 #define	LOC_Y_ABSOLUTE		(VLOC_FIRST+3)			/* 32643 */
312 #define	LOC_LAST_ABSOLUTE	(VLOC_FIRST+3)			/* 32643 */
313 
314 #define	VLOC_BATCH		(VLOC_FIRST+4)			/* 32644 */
315 #define	VLOC_LAST		(VLOC_BATCH+1)			/* 32645 */
316 
317 #define	MOUSE_CAP_CHANGE_FIRST		(VLOC_LAST+1)		/* 32646 */
318 #define	MOUSE_CAP_CHANGE_NUM_BUT	(MOUSE_CAP_CHANGE_FIRST+0) /* 32646 */
319 #define	MOUSE_CAP_CHANGE_NUM_WHEEL	(MOUSE_CAP_CHANGE_FIRST+1) /* 32647 */
320 
321 #define	MOUSE_TYPE_ABSOLUTE	(VLOC_LAST+3)			/* 32648 */
322 
323 #define	MOUSE_LAST		(VLOC_LAST+3)			/* 32648 */
324 #define	KEYBOARD_LAYOUT_CHANGE	(MOUSE_LAST+1)			/* 32649 */
325 
326 /*
327  * Common names for certain input codes.  The buttons on the physical
328  * mouse are thought to actually belong to the virtual keyboard.
329  */
330 #define	MS_LEFT		BUT(1)					/* 32544 */
331 #define	MS_MIDDLE	BUT(2)					/* 32545 */
332 #define	MS_RIGHT	BUT(3)					/* 32546 */
333 
334 /*
335  * A firm_event structure is encoded in the byte stream of a device
336  * when the device has been asked to format its byte stream so.
337  * The time stamp is not defined to be meaningful except to compare
338  * with other Firm_event time stamps.
339  *
340  * The pair field is critical for a state maintainence package
341  * (such as vuid_state.h), one that is designed to not know anything
342  * about the semantics of particular events, to maintain correct data
343  * for corresponding absolute, delta and paired state variables.
344  *
345  * pair, when defined (as indicated by pair_type), is the associated
346  * state variable that should be updated due to this events generation.
347  * This is used to maintain a correspondence between an event that is a
348  * delta and a state that is an absolute value (with a known delta event
349  * defined) and visa versa, e.g., LOC_X_DELTA & LOC_X_ABSOLUTE.
350  * pair is also used to indicate another state variable that
351  * should be updated with the occurrence of this event, e.g., if id is
352  * '^G' then pair could be 'g' or 'G' depending on the state of the shift
353  * key.
354  */
355 typedef struct firm_event {
356 	ushort_t	id;	/* Event's unique id */
357 	uchar_t		pair_type;	/* Event pair's type */
358 #define	FE_PAIR_NONE		0	/* pair is not defined */
359 #define	FE_PAIR_SET		1	/* pair is accompanying id to set */
360 					/* to this events value */
361 #define	FE_PAIR_DELTA		2	/* pair is accompanying id that */
362 					/* should be set to the delta of */
363 					/* id's current value and the new */
364 					/* value indicated by this event */
365 #define	FE_PAIR_ABSOLUTE	3	/* pair is accompanying id that */
366 					/* should be set to the sum of its */
367 					/* current value and the delta */
368 					/* indicated by this event's value */
369 	uchar_t		pair;	/* Event id's associated delta|absolute|pair */
370 				/* offset within id's segment (minus id's */
371 				/* address) */
372 	int		value;	/* Event's value */
373 #if defined(_LP64) || defined(_I32LPx)
374 	struct timeval32 time;	/* Event's time stamp */
375 #else
376 	struct timeval time;
377 #endif
378 } Firm_event;
379 #define	FIRM_EVENT_NULL ((Firm_event *)0)
380 #define	vuid_id_addr(id)		((id) & 0xFF00)
381 #define	vuid_id_offset(id)		((id) & 0xFF)
382 #define	vuid_boolean_value(value)	(((value) == 0) || ((value) == 1))
383 #define	vuid_int_value(value)		(!(vuid_boolean_value((value))))
384 
385 /*
386  * Ioctls to input devices that support vuid.
387  */
388 
389 /*
390  * VUID*FORMAT ioctls are used to control which byte stream format that
391  * a input device should use.  An errno of ENOTTY or EINVAL indicates that
392  * a device can't speak Firm_events.
393  */
394 #define	VUIOC		('v'<<8)
395 #if defined(__i386) || defined(__i386_COMPAT)
396 #define	VUIDSFORMAT   (VUIOC|11) /* avoid conflict with VT_?????? */
397 #define	VUIDGFORMAT   (VUIOC|12) /* avoid conflict with VT_?????? */
398 #else
399 #define	VUIDSFORMAT   (VUIOC|1) /* Set input device byte stream format */
400 #define	VUIDGFORMAT   (VUIOC|2) /* Get input device byte stream format */
401 #endif
402 #define	VUID_NATIVE	0	/* Native byte stream format */
403 #define	VUID_FIRM_EVENT 1	/* struct firm_event byte stream format */
404 
405 /*
406  * VUID*ADDR ioctls are used to control which address a particular
407  * virtual input device segment has.  This is used to have an instancing
408  * capability, e.g., a second mouse.  An errno of ENOTTY indicates that
409  * a device can't deal with these commands.  An errno of ENODEV indicates
410  * that the requested virtual device has no events generated for it by
411  * this physical device.
412  *
413  * VUIDSADDR sets the virtual input device segment address indicated by
414  * default to next.
415  *
416  * VUIDGADDR gets the in force address of the virtual input device segment
417  * indicated by default into current.
418  */
419 typedef struct	vuid_addr_probe {
420 	short	base;		/* default vuid device addr directed too */
421 	union	{
422 		short	next;	/* next addr for default when VUIDSADDR */
423 		short	current; /* current addr of default when VUIDGADDR */
424 	} data;
425 } Vuid_addr_probe;
426 
427 #if defined(__i386) || defined(__i386_COMPAT)
428 #define	VUIDSADDR   (VUIOC|13)	/* avoid conflict with VT_?????? */
429 #define	VUIDGADDR   (VUIOC|14)	/* avoid conflict with VT_?????? */
430 #else
431 #define	VUIDSADDR   (VUIOC|3)	/* Set vuid address */
432 #define	VUIDGADDR   (VUIOC|4)	/* Get vuid address */
433 #endif
434 
435 #ifdef	__cplusplus
436 }
437 #endif
438 
439 #endif	/* _SYS_VUID_EVENT_H */
440