xref: /freebsd/share/man/man4/mouse.4 (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1.\"
2.\" Copyright (c) 1997
3.\" Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer as
11.\"    the first lines of this file unmodified.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd December 3, 1997
28.Dt MOUSE 4
29.Os
30.Sh NAME
31.Nm mouse
32.Nd mouse and pointing device drivers
33.Sh SYNOPSIS
34.In sys/mouse.h
35.Sh DESCRIPTION
36The mouse drivers
37.Xr psm 4 ,
38.Xr ums 4
39and
40.Xr sysmouse 4
41provide user programs with movement and button state information of the mouse.
42Currently there are specific device drivers for bus, InPort, PS/2, and USB mice.
43The serial mouse is not directly supported by a dedicated driver, but
44it is accessible via the serial device driver or via
45.Xr moused 8
46and
47.Xr sysmouse 4 .
48.Pp
49The user program simply opens a mouse device with a
50.Xr open 2
51call and reads
52mouse data from the device via
53.Xr read 2 .
54Movement and button states are usually encoded in fixed-length data packets.
55Some mouse devices may send data in variable length of packets.
56Actual protocol (data format) used by each driver differs widely.
57.Pp
58The mouse drivers may have ``non-blocking'' attribute which will make
59the driver return immediately if mouse data is not available.
60.Pp
61Mouse device drivers often offer several levels of operation.
62The current operation level can be examined and changed via
63.Xr ioctl 2
64commands.
65The level zero is the lowest level at which the driver offers the basic
66service to user programs.
67Most drivers provide horizontal and vertical movement of the mouse
68and state of up to three buttons at this level.
69At the level one, if supported by the driver, mouse data is encoded
70in the standard format
71.Dv MOUSE_PROTO_SYSMOUSE
72as follows:
73.Pp
74.Bl -tag -width Byte_1 -compact
75.It Byte 1
76.Bl -tag -width bit_7 -compact
77.It bit 7
78Always one.
79.It bit 6..3
80Always zero.
81.It bit 2
82Left button status; cleared if pressed, otherwise set.
83.It bit 1
84Middle button status; cleared if pressed, otherwise set.
85Always one,
86if the device does not have the middle button.
87.It bit 0
88Right button status; cleared if pressed, otherwise set.
89.El
90.It Byte 2
91The first half of horizontal movement count in two's complement;
92-128 through 127.
93.It Byte 3
94The first half of vertical movement count in two's complement;
95-128 through 127.
96.It Byte 4
97The second half of the horizontal movement count in two's complement;
98-128 through 127.
99To obtain the full horizontal movement count, add
100the byte 2 and 4.
101.It Byte 5
102The second half of the vertical movement count in two's complement;
103-128 through 127.
104To obtain the full vertical movement count, add
105the byte 3 and 5.
106.It Byte 6
107The bit 7 is always zero.
108The lower 7 bits encode the first half of
109Z axis movement count in two's complement; -64 through 63.
110.It Byte 7
111The bit 7 is always zero.
112The lower 7 bits encode the second half of
113the Z axis movement count in two's complement; -64 through 63.
114To obtain the full Z axis movement count, add the byte 6 and 7.
115.It Byte 8
116The bit 7 is always zero.
117The bits 0 through 6 reflect the state
118of the buttons 4 through 10.
119If a button is pressed, the corresponding bit is cleared.
120Otherwise
121the bit is set.
122.El
123.Pp
124The first 5 bytes of this format is compatible with the MouseSystems
125format.
126The additional 3 bytes have their MSBs always set to zero.
127Thus, if the user program can interpret the MouseSystems data format and
128tries to find the first byte of the format by detecting the bit pattern
12910000xxxb,
130it will discard the additional bytes, thus, be able to decode x, y
131and states of 3 buttons correctly.
132.Pp
133Device drivers may offer operation levels higher than one.
134Refer to manual pages of individual drivers for details.
135.Sh IOCTLS
136The following
137.Xr ioctl 2
138commands are defined for the mouse drivers.
139The degree of support
140varies from one driver to another.
141This section gives general
142description of the commands.
143Refer to manual pages of individual drivers for specific details.
144.Pp
145.Bl -tag -width MOUSE -compact
146.It Dv MOUSE_GETLEVEL Ar int *level
147.It Dv MOUSE_SETLEVEL Ar int *level
148These commands manipulate the operation level of the mouse driver.
149.Pp
150.It Dv MOUSE_GETHWINFO Ar mousehw_t *hw
151Returns the hardware information of the attached device in the following
152Except for the
153.Dv iftype
154field, the device driver may not always fill the structure with correct
155values.
156Consult manual pages of individual drivers for details of support.
157.Bd -literal
158typedef struct mousehw {
159    int buttons;    /* number of buttons */
160    int iftype;     /* I/F type */
161    int type;       /* mouse/track ball/pad... */
162    int model;      /* I/F dependent model ID */
163    int hwid;       /* I/F dependent hardware ID */
164} mousehw_t;
165.Ed
166.Pp
167The
168.Dv buttons
169field holds the number of buttons detected by the driver.
170The driver
171may put an arbitrary value, such as two, in this field, if it cannot
172determine the exact number.
173.Pp
174The
175.Dv iftype
176is the type of interface:
177.Dv MOUSE_IF_SERIAL ,
178.Dv MOUSE_IF_BUS ,
179.Dv MOUSE_IF_INPORT ,
180.Dv MOUSE_IF_PS2 ,
181.Dv MOUSE_IF_USB ,
182.Dv MOUSE_IF_SYSMOUSE
183or
184.Dv MOUSE_IF_UNKNOWN .
185.Pp
186The
187.Dv type
188tells the device type:
189.Dv MOUSE_MOUSE ,
190.Dv MOUSE_TRACKBALL ,
191.Dv MOUSE_STICK ,
192.Dv MOUSE_PAD ,
193or
194.Dv MOUSE_UNKNOWN .
195.Pp
196The
197.Dv model
198may be
199.Dv MOUSE_MODEL_GENERIC
200or one of
201.Dv MOUSE_MODEL_XXX
202constants.
203.Pp
204The
205.Dv hwid
206is the ID value returned by the pointing device.
207It
208depend on the interface type; refer to the manual page of
209specific mouse drivers for possible values.
210.Pp
211.It Dv MOUSE_GETMODE Ar mousemode_t *mode
212The command reports the current operation parameters of the mouse driver.
213.Bd -literal
214typedef struct mousemode {
215    int protocol;    /* MOUSE_PROTO_XXX */
216    int rate;        /* report rate (per sec) */
217    int resolution;  /* MOUSE_RES_XXX, -1 if unknown */
218    int accelfactor; /* acceleration factor */
219    int level;       /* driver operation level */
220    int packetsize;  /* the length of the data packet */
221    unsigned char syncmask[2]; /* sync. bits */
222} mousemode_t;
223.Ed
224.Pp
225The
226.Dv protocol
227field tells the format in which the device status is returned
228when the mouse data is read by the user program.
229It is one of
230.Dv MOUSE_PROTO_XXX
231constants.
232.Pp
233The
234.Dv rate
235field is the status report rate (reports/sec) at which the device will send
236movement reports to the host computer.
237-1 if unknown or not applicable.
238.Pp
239The
240.Dv resolution
241field holds a value specifying resolution of the pointing device.
242It is a positive value or one of
243.Dv MOUSE_RES_XXX
244constants.
245.Pp
246The
247.Dv accelfactor
248field holds a value to control acceleration feature.
249It must be zero or greater.
250If it is zero, acceleration is disabled.
251.Pp
252The
253.Dv packetsize
254field tells the length of the fixed-size data packet or the length
255of the fixed part of the variable-length packet.
256The size depends on the interface type, the device type and model, the
257protocol and the operation level of the driver.
258.Pp
259The array
260.Dv syncmask
261holds a bit mask and pattern to detect the first byte of the
262data packet.
263.Dv syncmask[0]
264is the bit mask to be ANDed with a byte.
265If the result is equal to
266.Dv syncmask[1] ,
267the byte is likely to be the first byte of the data packet.
268Note that this method of detecting the first byte is not 100% reliable,
269thus, should be taken only as an advisory measure.
270.Pp
271.It Dv MOUSE_SETMODE Ar mousemode_t *mode
272The command changes the current operation parameters of the mouse driver
273as specified in
274.Ar mode .
275Only
276.Dv rate ,
277.Dv resolution ,
278.Dv level
279and
280.Dv accelfactor
281may be modifiable.
282Setting values in the other field does not generate
283error and has no effect.
284.Pp
285If you do not want to change the current setting of a field, put -1
286there.
287You may also put zero in
288.Dv resolution
289and
290.Dv rate ,
291and the default value for the fields will be selected.
292.Pp
293.It Dv MOUSE_READDATA Ar mousedata_t *data
294The command reads the raw data from the device.
295.Bd -literal
296typedef struct mousedata {
297    int len;        /* # of data in the buffer */
298    int buf[16];    /* data buffer */
299} mousedata_t;
300.Ed
301.Pp
302The calling process must fill the
303.Dv len
304field with the number of bytes to be read into the buffer.
305This command may not be supported by all drivers.
306.Pp
307.It Dv MOUSE_READSTATE Ar mousedata_t *state
308The command reads the raw state data from the device.
309It uses the same structure as above.
310This command may not be supported by all drivers.
311.Pp
312.It Dv MOUSE_GETSTATUS Ar mousestatus_t *status
313The command returns the current state of buttons and
314movement counts in the following structure.
315.Bd -literal
316typedef struct mousestatus {
317    int flags;      /* state change flags */
318    int button;     /* button status */
319    int obutton;    /* previous button status */
320    int dx;         /* x movement */
321    int dy;         /* y movement */
322    int dz;         /* z movement */
323} mousestatus_t;
324.Ed
325.Pp
326The
327.Dv button
328and
329.Dv obutton
330fields hold the current and the previous state of the mouse buttons.
331When a button is pressed, the corresponding bit is set.
332The mouse drivers may support up to 31 buttons with the bit 0 through 31.
333Few button bits are defined as
334.Dv MOUSE_BUTTON1DOWN
335through
336.Dv MOUSE_BUTTON8DOWN .
337The first three buttons correspond to left, middle and right buttons.
338.Pp
339If the state of the button has changed since the last
340.Dv MOUSE_GETSTATUS
341call, the corresponding bit in the
342.Dv flags
343field will be set.
344If the mouse has moved since the last call, the
345.Dv MOUSE_POSCHANGED
346bit in the
347.Dv flags
348field will also be set.
349.Pp
350The other fields hold movement counts since the last
351.Dv MOUSE_GETSTATUS
352call.
353The internal counters will be reset after every call to this
354command.
355.El
356.Sh FILES
357.Bl -tag -width /dev/sysmouseXX -compact
358.It Pa /dev/cuau%d
359serial ports
360.It Pa /dev/psm%d
361PS/2 mouse device
362.It Pa /dev/sysmouse
363virtual mouse device
364.It Pa /dev/ums%d
365USB mouse device
366.El
367.Sh SEE ALSO
368.Xr ioctl 2 ,
369.Xr psm 4 ,
370.Xr sysmouse 4 ,
371.Xr ums 4 ,
372.Xr moused 8
373.\".Sh HISTORY
374.Sh AUTHORS
375This manual page was written by
376.An Kazutaka Yokota Aq Mt yokota@FreeBSD.org .
377