xref: /freebsd/share/man/man4/mouse.4 (revision 6d249eee2769b135d56fac673f6b297b9416ed42)
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.\" $FreeBSD$
28.\"
29.Dd December 3, 1997
30.Dt MOUSE 4
31.Os FreeBSD
32.Sh NAME
33.Nm mouse
34.Nd mouse and pointing device drivers
35.Sh SYNOPSIS
36.Fd #include <machine/mouse.h>
37.Sh DESCRIPTION
38The mouse drivers
39.Xr mse 4 ,
40.Xr psm 4 ,
41.Xr ums 4
42and
43.Xr sysmouse 4
44provide user programs with movement and button state information of the mouse.
45Currently there are specific device drivers for bus, InPort, PS/2, and USB mice.
46The serial mouse is not directly supported by a dedicated driver, but
47it is accessible via the serial device driver or via
48.Xr moused 8
49and
50.Xr sysmouse 4 .
51.Pp
52The user program simply opens a mouse device with a
53.Xr open 2
54call and reads
55mouse data from the device via
56.Xr read 2 .
57Movement and button states are usually encoded in fixed-length data packets.
58Some mouse devices may send data in variable length of packets.
59Actual protocol (data format) used by each driver differs widely.
60.Pp
61The mouse drivers may have ``non-blocking'' attribute which will make
62the driver return immediately if mouse data is not available.
63.Pp
64Mouse device drivers often offer several levels of operation.
65The current operation level can be examined and changed via
66.Xr ioctl 2
67commands.
68The level zero is the lowest level at which the driver offers the basic
69service to user programs.
70Most drivers provide horizontal and vertical movement of the mouse
71and state of up to three buttons at this level.
72At the level one, if supported by the driver, mouse data is encoded
73in the standard format
74.Dv MOUSE_PROTO_SYSMOUSE
75as follows:
76.Pp
77.Bl -tag -width Byte_1 -compact
78.It Byte 1
79.Bl -tag -width bit_7 -compact
80.It bit 7
81Always one.
82.It bit 6..3
83Always zero.
84.It bit 2
85Left button status; cleared if pressed, otherwise set.
86.It bit 1
87Middle button status; cleared if pressed, otherwise set.
88Always one,
89if the device does not have the middle button.
90.It bit 0
91Right button status; cleared if pressed, otherwise set.
92.El
93.It Byte 2
94The first half of horizontal movement count in two's complement;
95-128 through 127.
96.It Byte 3
97The first half of vertical movement count in two's complement;
98-128 through 127.
99.It Byte 4
100The second half of the horizontal movement count in two's complement;
101-128 through 127. To obtain the full horizontal movement count, add
102the byte 2 and 4.
103.It Byte 5
104The second half of the vertical movement count in two's complement;
105-128 through 127. To obtain the full vertical movement count, add
106the byte 3 and 5.
107.It Byte 6
108The bit 7 is always zero.
109The lower 7 bits encode the first half of
110Z axis movement count in two's complement; -64 through 63.
111.It Byte 7
112The bit 7 is always zero.
113The lower 7 bits encode the second half of
114the Z axis movement count in two's complement; -64 through 63.
115To obtain the full Z axis movement count, add the byte 6 and 7.
116.It Byte 8
117The bit 7 is always zero.
118The bits 0 through 6 reflect the state
119of the buttons 4 through 10.
120If a button is pressed, the corresponding bit is cleared.
121Otherwise
122the bit is set.
123.El
124.Pp
125The first 5 bytes of this format is compatible with the MouseSystems
126format.
127The additional 3 bytes have their MSBs always set to zero.
128Thus, if the user program can interpret the MouseSystems data format and
129tries to find the first byte of the format by detecting the bit pattern
13010000xxxb,
131it will discard the additional bytes, thus, be able to decode x, y
132and states of 3 buttons correctly.
133.Pp
134Device drivers may offer operation levels higher than one.
135Refer to manual pages of individual drivers for details.
136.Sh IOCTLS
137The following
138.Xr ioctl 2
139commands are defined for the mouse drivers.
140The degree of support
141varies from one driver to another.
142This section gives general
143description of the commands.
144Refer to manual pages of individual drivers for specific details.
145.Pp
146.Bl -tag -width MOUSE -compact
147.It Dv MOUSE_GETLEVEL Ar int *level
148.It Dv MOUSE_SETLEVEL Ar int *level
149These commands manipulate the operation level of the mouse driver.
150.Pp
151.It Dv MOUSE_GETHWINFO Ar mousehw_t *hw
152Returns the hardware information of the attached device in the following
153Except for the
154.Dv iftype
155field, the device driver may not always fill the structure with correct
156values.
157Consult manual pages of individual drivers for details of support.
158.Bd -literal
159typedef struct mousehw {
160    int buttons;    /* number of buttons */
161    int iftype;     /* I/F type */
162    int type;       /* mouse/track ball/pad... */
163    int model;      /* I/F dependent model ID */
164    int hwid;       /* I/F dependent hardware ID */
165} mousehw_t;
166.Ed
167.Pp
168The
169.Dv buttons
170field holds the number of buttons detected by the driver.
171The driver
172may put an arbitrary value, such as two, in this field, if it cannot
173determine the exact number.
174.Pp
175The
176.Dv iftype
177is the type of interface:
178.Dv MOUSE_IF_SERIAL ,
179.Dv MOUSE_IF_BUS ,
180.Dv MOUSE_IF_INPORT ,
181.Dv MOUSE_IF_PS2 ,
182.Dv MOUSE_IF_USB ,
183.Dv MOUSE_IF_SYSMOUSE
184or
185.Dv MOUSE_IF_UNKNOWN .
186.Pp
187The
188.Dv type
189tells the device type:
190.Dv MOUSE_MOUSE ,
191.Dv MOUSE_TRACKBALL ,
192.Dv MOUSE_STICK ,
193.Dv MOUSE_PAD ,
194or
195.Dv MOUSE_UNKNOWN .
196.Pp
197The
198.Dv model
199may be
200.Dv MOUSE_MODEL_GENERIC
201or one of
202.Dv MOUSE_MODEL_XXX
203constants.
204.Pp
205The
206.Dv hwid
207is the ID value returned by the pointing device.
208It
209depend on the interface type; refer to the manual page of
210specific mouse drivers for possible values.
211.Pp
212.It Dv MOUSE_GETMODE Ar mousemode_t *mode
213The command reports the current operation parameters of the mouse driver.
214.Bd -literal
215typedef struct mousemode {
216    int protocol;    /* MOUSE_PROTO_XXX */
217    int rate;        /* report rate (per sec) */
218    int resolution;  /* MOUSE_RES_XXX, -1 if unknown */
219    int accelfactor; /* acceleration factor */
220    int level;       /* driver operation level */
221    int packetsize;  /* the length of the data packet */
222    unsigned char syncmask[2]; /* sync. bits */
223} mousemode_t;
224.Ed
225.Pp
226The
227.Dv protocol
228field tells the format in which the device status is returned
229when the mouse data is read by the user program.
230It is one of
231.Dv MOUSE_PROTO_XXX
232constants.
233.Pp
234The
235.Dv rate
236field is the status report rate (reports/sec) at which the device will send
237movement reports to the host computer. -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_GETVARS Ar mousevar_t *vars
294.\" Get internal variables of the mouse driver.
295.\" The variables which can be manipulated through these commands
296.\" are specific to each driver.
297.\" This command may not be supported by all drivers.
298.\" .Bd -literal
299.\" typedef struct mousevar {
300.\"     int var[16];    /* internal variables */
301.\" } mousevar_t;
302.\" .Ed
303.\" .Pp
304.\" If the commands are supported, the first element of the array is
305.\" filled with a signature value.
306.\" Apart from the signature data, there is currently no standard concerning
307.\" the other elements of the buffer.
308.\" .Pp
309.\" .It Dv MOUSE_SETVARS Ar mousevar_t *vars
310.\" Get internal variables of the mouse driver.
311.\" The first element of the array must be a signature value.
312.\" This command may not be supported by all drivers.
313.Pp
314.It Dv MOUSE_READDATA Ar mousedata_t *data
315The command reads the raw data from the device.
316.Bd -literal
317typedef struct mousedata {
318    int len;        /* # of data in the buffer */
319    int buf[16];    /* data buffer */
320} mousedata_t;
321.Ed
322.Pp
323The calling process must fill the
324.Dv len
325field with the number of bytes to be read into the buffer.
326This command may not be supported by all drivers.
327.Pp
328.It Dv MOUSE_READSTATE Ar mousedata_t *state
329The command reads the raw state data from the device.
330It uses the same structure as above.
331This command may not be supported by all drivers.
332.Pp
333.It Dv MOUSE_GETSTATUS Ar mousestatus_t *status
334The command returns the current state of buttons and
335movement counts in the following structure.
336.Bd -literal
337typedef struct mousestatus {
338    int flags;      /* state change flags */
339    int button;     /* button status */
340    int obutton;    /* previous button status */
341    int dx;         /* x movement */
342    int dy;         /* y movement */
343    int dz;         /* z movement */
344} mousestatus_t;
345.Ed
346.Pp
347The
348.Dv button
349and
350.Dv obutton
351fields hold the current and the previous state of the mouse buttons.
352When a button is pressed, the corresponding bit is set.
353The mouse drivers may support up to 31 buttons with the bit 0 through 31.
354Few button bits are defined as
355.Dv MOUSE_BUTTON1DOWN
356through
357.Dv MOUSE_BUTTON8DOWN .
358The first three buttons correspond to left, middle and right buttons.
359.Pp
360If the state of the button has changed since the last
361.Dv MOUSE_GETSTATUS
362call, the corresponding bit in the
363.Dv flags
364field will be set.
365If the mouse has moved since the last call, the
366.Dv MOUSE_POSCHANGED
367bit in the
368.Dv flags
369field will also be set.
370.Pp
371The other fields hold movement counts since the last
372.Dv MOUSE_GETSTATUS
373call.
374The internal counters will be reset after every call to this
375command.
376.El
377.Sh FILES
378.Bl -tag -width /dev/sysmouseXX -compact
379.It Pa /dev/cuaa%d
380serial ports
381.It Pa /dev/mse%d
382bus and InPort mouse device
383.It Pa /dev/psm%d
384PS/2 mouse device
385.It Pa /dev/sysmouse
386virtual mouse device
387.It Pa /dev/ums%d
388USB mouse device
389.El
390.Sh SEE ALSO
391.Xr ioctl 2 ,
392.Xr mse 4 ,
393.Xr psm 4 ,
394.Xr sysmouse 4 ,
395.Xr ums 4 ,
396.Xr moused 8
397.\".Sh HISTORY
398.Sh AUTHORS
399This manual page was written by
400.An Kazutaka Yokota Aq yokota@FreeBSD.org .
401