1/* $NetBSD:  $ */
2/*-
3 * Copyright (c) 1992, 1993 Erik Forsberg.
4 * Copyright (c) 1996, 1997 Kazutaka YOKOTA
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 *
13 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
16 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * $FreeBSD: src/sys/sys/mouse.h,v 1.18 2001/07/05 08:52:40 dd Exp $
25 */
26
27#ifndef _SYS_MOUSE_H_
28#define _SYS_MOUSE_H_
29
30#include <sys/types.h>
31#include <sys/ioccom.h>
32
33#if 0
34/* ioctls */
35#define MOUSE_GETSTATUS		_IOR('M', 0, mousestatus_t)
36#define MOUSE_GETHWINFO		_IOR('M', 1, mousehw_t)
37#define MOUSE_GETMODE		_IOR('M', 2, mousemode_t)
38#define MOUSE_SETMODE		_IOW('M', 3, mousemode_t)
39#define MOUSE_GETLEVEL		_IOR('M', 4, int)
40#define MOUSE_SETLEVEL		_IOW('M', 5, int)
41#define MOUSE_GETVARS		_IOR('M', 6, mousevar_t)
42#define MOUSE_SETVARS		_IOW('M', 7, mousevar_t)
43#define MOUSE_READSTATE		_IOWR('M', 8, mousedata_t)
44#define MOUSE_READDATA		_IOWR('M', 9, mousedata_t)
45
46#if notyet
47#define MOUSE_SETRESOLUTION	_IOW('M', 10, int)
48#define MOUSE_SETSCALING	_IOW('M', 11, int)
49#define MOUSE_SETRATE		_IOW('M', 12, int)
50#define MOUSE_GETHWID		_IOR('M', 13, int)
51#endif
52#endif
53
54/* mouse status block */
55typedef struct mousestatus {
56    int     flags;		/* state change flags */
57    int     button;		/* button status */
58    int     obutton;		/* previous button status */
59    int     dx;			/* x movement */
60    int     dy;			/* y movement */
61    int     dz;			/* z movement */
62} mousestatus_t;
63
64/* button */
65#define MOUSE_BUTTON1DOWN	0x0001	/* left */
66#define MOUSE_BUTTON2DOWN	0x0002	/* middle */
67#define MOUSE_BUTTON3DOWN	0x0004	/* right */
68#define MOUSE_BUTTON4DOWN	0x0008
69#define MOUSE_BUTTON5DOWN	0x0010
70#define MOUSE_BUTTON6DOWN	0x0020
71#define MOUSE_BUTTON7DOWN	0x0040
72#define MOUSE_BUTTON8DOWN	0x0080
73#define MOUSE_MAXBUTTON		31
74#define MOUSE_STDBUTTONS	0x0007		/* buttons 1-3 */
75#define MOUSE_EXTBUTTONS	0x7ffffff8	/* the others (28 of them!) */
76#define MOUSE_BUTTONS		(MOUSE_STDBUTTONS | MOUSE_EXTBUTTONS)
77
78/* flags */
79#define MOUSE_STDBUTTONSCHANGED	MOUSE_STDBUTTONS
80#define MOUSE_EXTBUTTONSCHANGED	MOUSE_EXTBUTTONS
81#define MOUSE_BUTTONSCHANGED	MOUSE_BUTTONS
82#define MOUSE_POSCHANGED	0x80000000
83
84typedef struct mousehw {
85	int buttons;		/* -1 if unknown */
86	int iftype;		/* MOUSE_IF_XXX */
87	int type;		/* mouse/track ball/pad... */
88	int model;		/* I/F dependent model ID: MOUSE_MODEL_XXX */
89	int hwid;		/* I/F dependent hardware ID
90				 * for the PS/2 mouse, it will be PSM_XXX_ID
91				 */
92} mousehw_t;
93
94/* iftype */
95#define MOUSE_IF_UNKNOWN	(-1)
96#define MOUSE_IF_SERIAL		0
97#define MOUSE_IF_BUS		1
98#define MOUSE_IF_INPORT		2
99#define MOUSE_IF_PS2		3
100#define MOUSE_IF_SYSMOUSE	4
101#define MOUSE_IF_USB		5
102
103/* type */
104#define MOUSE_UNKNOWN		(-1)	/* should be treated as a mouse */
105#define MOUSE_MOUSE		0
106#define MOUSE_TRACKBALL		1
107#define MOUSE_STICK		2
108#define MOUSE_PAD		3
109
110/* model */
111#define MOUSE_MODEL_UNKNOWN		(-1)
112#define MOUSE_MODEL_GENERIC		0
113#define MOUSE_MODEL_GLIDEPOINT		1
114#define MOUSE_MODEL_NETSCROLL		2
115#define MOUSE_MODEL_NET			3
116#define MOUSE_MODEL_INTELLI		4
117#define MOUSE_MODEL_THINK		5
118#define MOUSE_MODEL_EASYSCROLL		6
119#define MOUSE_MODEL_MOUSEMANPLUS	7
120#define MOUSE_MODEL_KIDSPAD		8
121#define MOUSE_MODEL_VERSAPAD		9
122#define MOUSE_MODEL_EXPLORER		10
123#define MOUSE_MODEL_4D			11
124#define MOUSE_MODEL_4DPLUS		12
125
126typedef struct mousemode {
127	int protocol;		/* MOUSE_PROTO_XXX */
128	int rate;		/* report rate (per sec), -1 if unknown */
129	int resolution;		/* MOUSE_RES_XXX, -1 if unknown */
130	int accelfactor;	/* accelation factor (must be 1 or greater) */
131	int level;		/* driver operation level */
132	int packetsize;		/* the length of the data packet */
133	unsigned char syncmask[2]; /* sync. data bits in the header byte */
134} mousemode_t;
135
136/* protocol */
137/*
138 * Serial protocols:
139 *   Microsoft, MouseSystems, Logitech, MM series, MouseMan, Hitachi Tablet,
140 *   GlidePoint, IntelliMouse, Thinking Mouse, MouseRemote, Kidspad,
141 *   VersaPad
142 * Bus mouse protocols:
143 *   bus, InPort
144 * PS/2 mouse protocol:
145 *   PS/2
146 */
147#define MOUSE_PROTO_UNKNOWN	(-1)
148#define MOUSE_PROTO_MS		0	/* Microsoft Serial, 3 bytes */
149#define MOUSE_PROTO_MSC		1	/* Mouse Systems, 5 bytes */
150#define MOUSE_PROTO_LOGI	2	/* Logitech, 3 bytes */
151#define MOUSE_PROTO_MM		3	/* MM series, 3 bytes */
152#define MOUSE_PROTO_LOGIMOUSEMAN 4	/* Logitech MouseMan 3/4 bytes */
153#define MOUSE_PROTO_BUS		5	/* MS/Logitech bus mouse */
154#define MOUSE_PROTO_INPORT	6	/* MS/ATI InPort mouse */
155#define MOUSE_PROTO_PS2		7	/* PS/2 mouse, 3 bytes */
156#define MOUSE_PROTO_HITTAB	8	/* Hitachi Tablet 3 bytes */
157#define MOUSE_PROTO_GLIDEPOINT	9	/* ALPS GlidePoint, 3/4 bytes */
158#define MOUSE_PROTO_INTELLI	10	/* MS IntelliMouse, 4 bytes */
159#define MOUSE_PROTO_THINK	11	/* Kensignton Thinking Mouse, 3/4 bytes */
160#define MOUSE_PROTO_SYSMOUSE	12	/* /dev/sysmouse */
161#define MOUSE_PROTO_X10MOUSEREM	13	/* X10 MouseRemote, 3 bytes */
162#define MOUSE_PROTO_KIDSPAD	14	/* Genius Kidspad */
163#define MOUSE_PROTO_VERSAPAD	15	/* Interlink VersaPad, 6 bytes */
164
165#define MOUSE_RES_UNKNOWN	(-1)
166#define MOUSE_RES_DEFAULT	0
167#define MOUSE_RES_LOW		(-2)
168#define MOUSE_RES_MEDIUMLOW	(-3)
169#define MOUSE_RES_MEDIUMHIGH	(-4)
170#define MOUSE_RES_HIGH		(-5)
171
172typedef struct mousedata {
173	int len;		/* # of data in the buffer */
174	int buf[16];		/* data buffer */
175} mousedata_t;
176
177#if (defined(MOUSE_GETVARS))
178
179typedef struct mousevar {
180	int var[16];
181} mousevar_t;
182
183/* magic numbers in var[0] */
184#define MOUSE_VARS_PS2_SIG	0x00325350	/* 'PS2' */
185#define MOUSE_VARS_BUS_SIG	0x00535542	/* 'BUS' */
186#define MOUSE_VARS_INPORT_SIG	0x00504e49	/* 'INP' */
187
188#endif /* MOUSE_GETVARS */
189
190/* Microsoft Serial mouse data packet */
191#define MOUSE_MSS_PACKETSIZE	3
192#define MOUSE_MSS_SYNCMASK	0x40
193#define MOUSE_MSS_SYNC		0x40
194#define MOUSE_MSS_BUTTONS	0x30
195#define MOUSE_MSS_BUTTON1DOWN	0x20	/* left */
196#define MOUSE_MSS_BUTTON2DOWN	0x00	/* no middle button */
197#define MOUSE_MSS_BUTTON3DOWN	0x10	/* right */
198
199/* Logitech MouseMan data packet (M+ protocol) */
200#define MOUSE_LMAN_BUTTON2DOWN	0x20	/* middle button, the 4th byte */
201
202/* ALPS GlidePoint extension (variant of M+ protocol) */
203#define MOUSE_ALPS_BUTTON2DOWN	0x20	/* middle button, the 4th byte */
204#define MOUSE_ALPS_TAP		0x10	/* `tapping' action, the 4th byte */
205
206/* Kinsington Thinking Mouse extension (variant of M+ protocol) */
207#define MOUSE_THINK_BUTTON2DOWN 0x20	/* lower-left button, the 4th byte */
208#define MOUSE_THINK_BUTTON4DOWN 0x10	/* lower-right button, the 4th byte */
209
210/* MS IntelliMouse (variant of MS Serial) */
211#define MOUSE_INTELLI_PACKETSIZE 4
212#define MOUSE_INTELLI_BUTTON2DOWN 0x10	/* middle button in the 4th byte */
213
214/* Mouse Systems Corp. mouse data packet */
215#define MOUSE_MSC_PACKETSIZE	5
216#define MOUSE_MSC_SYNCMASK	0xf8
217#define MOUSE_MSC_SYNC		0x80
218#define MOUSE_MSC_BUTTONS	0x07
219#define MOUSE_MSC_BUTTON1UP	0x04	/* left */
220#define MOUSE_MSC_BUTTON2UP	0x02	/* middle */
221#define MOUSE_MSC_BUTTON3UP	0x01	/* right */
222#define MOUSE_MSC_MAXBUTTON	3
223
224/* MM series mouse data packet */
225#define MOUSE_MM_PACKETSIZE	3
226#define MOUSE_MM_SYNCMASK	0xe0
227#define MOUSE_MM_SYNC		0x80
228#define MOUSE_MM_BUTTONS	0x07
229#define MOUSE_MM_BUTTON1DOWN	0x04	/* left */
230#define MOUSE_MM_BUTTON2DOWN	0x02	/* middle */
231#define MOUSE_MM_BUTTON3DOWN	0x01	/* right */
232#define MOUSE_MM_XPOSITIVE	0x10
233#define MOUSE_MM_YPOSITIVE	0x08
234
235/* PS/2 mouse data packet */
236#define MOUSE_PS2_PACKETSIZE	3
237#define MOUSE_PS2_SYNCMASK	0xc8
238#define MOUSE_PS2_SYNC		0x08
239#define MOUSE_PS2_BUTTONS	0x07	/* 0x03 for 2 button mouse */
240#define MOUSE_PS2_BUTTON1DOWN	0x01	/* left */
241#define MOUSE_PS2_BUTTON2DOWN	0x04	/* middle */
242#define MOUSE_PS2_BUTTON3DOWN	0x02	/* right */
243#define MOUSE_PS2_TAP		MOUSE_PS2_SYNC /* GlidePoint (PS/2) `tapping'
244					        * Yes! this is the same bit
245						* as SYNC!
246					 	*/
247
248#define MOUSE_PS2_XNEG		0x10
249#define MOUSE_PS2_YNEG		0x20
250#define MOUSE_PS2_XOVERFLOW	0x40
251#define MOUSE_PS2_YOVERFLOW	0x80
252
253/* Logitech MouseMan+ (PS/2) data packet (PS/2++ protocol) */
254#define MOUSE_PS2PLUS_SYNCMASK	0x48
255#define MOUSE_PS2PLUS_SYNC	0x48
256#define MOUSE_PS2PLUS_ZNEG	0x08	/* sign bit */
257#define MOUSE_PS2PLUS_BUTTON4DOWN 0x10	/* 4th button on MouseMan+ */
258#define MOUSE_PS2PLUS_BUTTON5DOWN 0x20
259
260/* IBM ScrollPoint (PS/2) also uses PS/2++ protocol */
261#define MOUSE_SPOINT_ZNEG	0x80	/* sign bits */
262#define MOUSE_SPOINT_WNEG	0x08
263
264/* MS IntelliMouse (PS/2) data packet */
265#define MOUSE_PS2INTELLI_PACKETSIZE 4
266/* some compatible mice have additional buttons */
267#define MOUSE_PS2INTELLI_BUTTON4DOWN 0x40
268#define MOUSE_PS2INTELLI_BUTTON5DOWN 0x80
269
270/* MS IntelliMouse Explorer (PS/2) data packet (variation of IntelliMouse) */
271#define MOUSE_EXPLORER_ZNEG	0x08	/* sign bit */
272/* IntelliMouse Explorer has additional button data in the fourth byte */
273#define MOUSE_EXPLORER_BUTTON4DOWN 0x10
274#define MOUSE_EXPLORER_BUTTON5DOWN 0x20
275
276/* Interlink VersaPad (serial I/F) data packet */
277#define MOUSE_VERSA_PACKETSIZE	6
278#define MOUSE_VERSA_IN_USE	0x04
279#define MOUSE_VERSA_SYNCMASK	0xc3
280#define MOUSE_VERSA_SYNC	0xc0
281#define MOUSE_VERSA_BUTTONS	0x30
282#define MOUSE_VERSA_BUTTON1DOWN	0x20	/* left */
283#define MOUSE_VERSA_BUTTON2DOWN	0x00	/* middle */
284#define MOUSE_VERSA_BUTTON3DOWN	0x10	/* right */
285#define MOUSE_VERSA_TAP		0x08
286
287/* Interlink VersaPad (PS/2 I/F) data packet */
288#define MOUSE_PS2VERSA_PACKETSIZE	6
289#define MOUSE_PS2VERSA_IN_USE		0x10
290#define MOUSE_PS2VERSA_SYNCMASK		0xe8
291#define MOUSE_PS2VERSA_SYNC		0xc8
292#define MOUSE_PS2VERSA_BUTTONS		0x05
293#define MOUSE_PS2VERSA_BUTTON1DOWN	0x04	/* left */
294#define MOUSE_PS2VERSA_BUTTON2DOWN	0x00	/* middle */
295#define MOUSE_PS2VERSA_BUTTON3DOWN	0x01	/* right */
296#define MOUSE_PS2VERSA_TAP		0x02
297
298/* A4 Tech 4D Mouse (PS/2) data packet */
299#define MOUSE_4D_PACKETSIZE		3
300#define MOUSE_4D_WHEELBITS		0xf0
301
302/* A4 Tech 4D+ Mouse (PS/2) data packet */
303#define MOUSE_4DPLUS_PACKETSIZE		3
304#define MOUSE_4DPLUS_ZNEG		0x04	/* sign bit */
305#define MOUSE_4DPLUS_BUTTON4DOWN	0x08
306
307/* sysmouse extended data packet */
308/*
309 * /dev/sysmouse sends data in two formats, depending on the protocol
310 * level.  At the level 0, format is exactly the same as MousSystems'
311 * five byte packet.  At the level 1, the first five bytes are the same
312 * as at the level 0.  There are additional three bytes which shows
313 * `dz' and the states of additional buttons.  `dz' is expressed as the
314 * sum of the byte 5 and 6 which contain signed seven bit values.
315 * The states of the button 4 though 10 are in the bit 0 though 6 in
316 * the byte 7 respectively: 1 indicates the button is up.
317 */
318#define MOUSE_SYS_PACKETSIZE	8
319#define MOUSE_SYS_SYNCMASK	0xf8
320#define MOUSE_SYS_SYNC		0x80
321#define MOUSE_SYS_BUTTON1UP	0x04	/* left, 1st byte */
322#define MOUSE_SYS_BUTTON2UP	0x02	/* middle, 1st byte */
323#define MOUSE_SYS_BUTTON3UP	0x01	/* right, 1st byte */
324#define MOUSE_SYS_BUTTON4UP	0x0001	/* 7th byte */
325#define MOUSE_SYS_BUTTON5UP	0x0002
326#define MOUSE_SYS_BUTTON6UP	0x0004
327#define MOUSE_SYS_BUTTON7UP	0x0008
328#define MOUSE_SYS_BUTTON8UP	0x0010
329#define MOUSE_SYS_BUTTON9UP	0x0020
330#define MOUSE_SYS_BUTTON10UP	0x0040
331#define MOUSE_SYS_MAXBUTTON	10
332#define MOUSE_SYS_STDBUTTONS	0x07
333#define MOUSE_SYS_EXTBUTTONS	0x7f	/* the others */
334
335/* Mouse remote socket */
336#define _PATH_MOUSEREMOTE	"/var/run/MouseRemote"
337
338#endif /* _SYS_MOUSE_H_ */
339
340
341/* mouse cursor ioctl */
342struct mouse_data {
343	int		x;
344	int 		y;
345	int 		z;
346	int 		buttons;
347};
348typedef struct mouse_data mouse_data_t;
349
350struct mouse_mode {
351	int		mode;
352	int		signal;
353};
354typedef struct mouse_mode mouse_mode_t;
355
356struct mouse_event {
357	int		id;			/* one based */
358	int		value;
359};
360typedef struct mouse_event mouse_event_t;
361
362struct mouse_info {
363	int		operation;
364#define MOUSE_SHOW	0x01
365#define MOUSE_HIDE	0x02
366#define MOUSE_MOVEABS	0x03
367#define MOUSE_MOVEREL	0x04
368#define MOUSE_GETINFO	0x05
369#define MOUSE_MODE	0x06
370#define MOUSE_ACTION	0x07
371#define MOUSE_MOTION_EVENT	0x08
372#define MOUSE_BUTTON_EVENT	0x09
373#define MOUSE_MOUSECHAR	0x0a
374	union {
375		mouse_data_t	data;
376		mouse_mode_t	mode;
377		mouse_event_t	event;
378		int		mouse_char;
379	}		u;
380};
381typedef struct mouse_info mouse_info_t;
382