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