xref: /freebsd/share/man/man4/mouse.4 (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
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
32.Sh NAME
33.Nm mouse
34.Nd mouse and pointing device drivers
35.Sh SYNOPSIS
36.In sys/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.
102To obtain the full horizontal movement count, add
103the byte 2 and 4.
104.It Byte 5
105The second half of the vertical movement count in two's complement;
106-128 through 127.
107To obtain the full vertical movement count, add
108the byte 3 and 5.
109.It Byte 6
110The bit 7 is always zero.
111The lower 7 bits encode the first half of
112Z axis movement count in two's complement; -64 through 63.
113.It Byte 7
114The bit 7 is always zero.
115The lower 7 bits encode the second half of
116the Z axis movement count in two's complement; -64 through 63.
117To obtain the full Z axis movement count, add the byte 6 and 7.
118.It Byte 8
119The bit 7 is always zero.
120The bits 0 through 6 reflect the state
121of the buttons 4 through 10.
122If a button is pressed, the corresponding bit is cleared.
123Otherwise
124the bit is set.
125.El
126.Pp
127The first 5 bytes of this format is compatible with the MouseSystems
128format.
129The additional 3 bytes have their MSBs always set to zero.
130Thus, if the user program can interpret the MouseSystems data format and
131tries to find the first byte of the format by detecting the bit pattern
13210000xxxb,
133it will discard the additional bytes, thus, be able to decode x, y
134and states of 3 buttons correctly.
135.Pp
136Device drivers may offer operation levels higher than one.
137Refer to manual pages of individual drivers for details.
138.Sh IOCTLS
139The following
140.Xr ioctl 2
141commands are defined for the mouse drivers.
142The degree of support
143varies from one driver to another.
144This section gives general
145description of the commands.
146Refer to manual pages of individual drivers for specific details.
147.Pp
148.Bl -tag -width MOUSE -compact
149.It Dv MOUSE_GETLEVEL Ar int *level
150.It Dv MOUSE_SETLEVEL Ar int *level
151These commands manipulate the operation level of the mouse driver.
152.Pp
153.It Dv MOUSE_GETHWINFO Ar mousehw_t *hw
154Returns the hardware information of the attached device in the following
155Except for the
156.Dv iftype
157field, the device driver may not always fill the structure with correct
158values.
159Consult manual pages of individual drivers for details of support.
160.Bd -literal
161typedef struct mousehw {
162    int buttons;    /* number of buttons */
163    int iftype;     /* I/F type */
164    int type;       /* mouse/track ball/pad... */
165    int model;      /* I/F dependent model ID */
166    int hwid;       /* I/F dependent hardware ID */
167} mousehw_t;
168.Ed
169.Pp
170The
171.Dv buttons
172field holds the number of buttons detected by the driver.
173The driver
174may put an arbitrary value, such as two, in this field, if it cannot
175determine the exact number.
176.Pp
177The
178.Dv iftype
179is the type of interface:
180.Dv MOUSE_IF_SERIAL ,
181.Dv MOUSE_IF_BUS ,
182.Dv MOUSE_IF_INPORT ,
183.Dv MOUSE_IF_PS2 ,
184.Dv MOUSE_IF_USB ,
185.Dv MOUSE_IF_SYSMOUSE
186or
187.Dv MOUSE_IF_UNKNOWN .
188.Pp
189The
190.Dv type
191tells the device type:
192.Dv MOUSE_MOUSE ,
193.Dv MOUSE_TRACKBALL ,
194.Dv MOUSE_STICK ,
195.Dv MOUSE_PAD ,
196or
197.Dv MOUSE_UNKNOWN .
198.Pp
199The
200.Dv model
201may be
202.Dv MOUSE_MODEL_GENERIC
203or one of
204.Dv MOUSE_MODEL_XXX
205constants.
206.Pp
207The
208.Dv hwid
209is the ID value returned by the pointing device.
210It
211depend on the interface type; refer to the manual page of
212specific mouse drivers for possible values.
213.Pp
214.It Dv MOUSE_GETMODE Ar mousemode_t *mode
215The command reports the current operation parameters of the mouse driver.
216.Bd -literal
217typedef struct mousemode {
218    int protocol;    /* MOUSE_PROTO_XXX */
219    int rate;        /* report rate (per sec) */
220    int resolution;  /* MOUSE_RES_XXX, -1 if unknown */
221    int accelfactor; /* acceleration factor */
222    int level;       /* driver operation level */
223    int packetsize;  /* the length of the data packet */
224    unsigned char syncmask[2]; /* sync. bits */
225} mousemode_t;
226.Ed
227.Pp
228The
229.Dv protocol
230field tells the format in which the device status is returned
231when the mouse data is read by the user program.
232It is one of
233.Dv MOUSE_PROTO_XXX
234constants.
235.Pp
236The
237.Dv rate
238field is the status report rate (reports/sec) at which the device will send
239movement reports to the host computer.
240-1 if unknown or not applicable.
241.Pp
242The
243.Dv resolution
244field holds a value specifying resolution of the pointing device.
245It is a positive value or one of
246.Dv MOUSE_RES_XXX
247constants.
248.Pp
249The
250.Dv accelfactor
251field holds a value to control acceleration feature.
252It must be zero or greater.
253If it is zero, acceleration is disabled.
254.Pp
255The
256.Dv packetsize
257field tells the length of the fixed-size data packet or the length
258of the fixed part of the variable-length packet.
259The size depends on the interface type, the device type and model, the
260protocol and the operation level of the driver.
261.Pp
262The array
263.Dv syncmask
264holds a bit mask and pattern to detect the first byte of the
265data packet.
266.Dv syncmask[0]
267is the bit mask to be ANDed with a byte.
268If the result is equal to
269.Dv syncmask[1] ,
270the byte is likely to be the first byte of the data packet.
271Note that this method of detecting the first byte is not 100% reliable,
272thus, should be taken only as an advisory measure.
273.Pp
274.It Dv MOUSE_SETMODE Ar mousemode_t *mode
275The command changes the current operation parameters of the mouse driver
276as specified in
277.Ar mode .
278Only
279.Dv rate ,
280.Dv resolution ,
281.Dv level
282and
283.Dv accelfactor
284may be modifiable.
285Setting values in the other field does not generate
286error and has no effect.
287.Pp
288If you do not want to change the current setting of a field, put -1
289there.
290You may also put zero in
291.Dv resolution
292and
293.Dv rate ,
294and the default value for the fields will be selected.
295.\" .Pp
296.\" .It Dv MOUSE_GETVARS Ar mousevar_t *vars
297.\" Get internal variables of the mouse driver.
298.\" The variables which can be manipulated through these commands
299.\" are specific to each driver.
300.\" This command may not be supported by all drivers.
301.\" .Bd -literal
302.\" typedef struct mousevar {
303.\"     int var[16];    /* internal variables */
304.\" } mousevar_t;
305.\" .Ed
306.\" .Pp
307.\" If the commands are supported, the first element of the array is
308.\" filled with a signature value.
309.\" Apart from the signature data, there is currently no standard concerning
310.\" the other elements of the buffer.
311.\" .Pp
312.\" .It Dv MOUSE_SETVARS Ar mousevar_t *vars
313.\" Get internal variables of the mouse driver.
314.\" The first element of the array must be a signature value.
315.\" This command may not be supported by all drivers.
316.Pp
317.It Dv MOUSE_READDATA Ar mousedata_t *data
318The command reads the raw data from the device.
319.Bd -literal
320typedef struct mousedata {
321    int len;        /* # of data in the buffer */
322    int buf[16];    /* data buffer */
323} mousedata_t;
324.Ed
325.Pp
326The calling process must fill the
327.Dv len
328field with the number of bytes to be read into the buffer.
329This command may not be supported by all drivers.
330.Pp
331.It Dv MOUSE_READSTATE Ar mousedata_t *state
332The command reads the raw state data from the device.
333It uses the same structure as above.
334This command may not be supported by all drivers.
335.Pp
336.It Dv MOUSE_GETSTATUS Ar mousestatus_t *status
337The command returns the current state of buttons and
338movement counts in the following structure.
339.Bd -literal
340typedef struct mousestatus {
341    int flags;      /* state change flags */
342    int button;     /* button status */
343    int obutton;    /* previous button status */
344    int dx;         /* x movement */
345    int dy;         /* y movement */
346    int dz;         /* z movement */
347} mousestatus_t;
348.Ed
349.Pp
350The
351.Dv button
352and
353.Dv obutton
354fields hold the current and the previous state of the mouse buttons.
355When a button is pressed, the corresponding bit is set.
356The mouse drivers may support up to 31 buttons with the bit 0 through 31.
357Few button bits are defined as
358.Dv MOUSE_BUTTON1DOWN
359through
360.Dv MOUSE_BUTTON8DOWN .
361The first three buttons correspond to left, middle and right buttons.
362.Pp
363If the state of the button has changed since the last
364.Dv MOUSE_GETSTATUS
365call, the corresponding bit in the
366.Dv flags
367field will be set.
368If the mouse has moved since the last call, the
369.Dv MOUSE_POSCHANGED
370bit in the
371.Dv flags
372field will also be set.
373.Pp
374The other fields hold movement counts since the last
375.Dv MOUSE_GETSTATUS
376call.
377The internal counters will be reset after every call to this
378command.
379.El
380.Sh FILES
381.Bl -tag -width /dev/sysmouseXX -compact
382.It Pa /dev/cuau%d
383serial ports
384.It Pa /dev/mse%d
385bus and InPort mouse device
386.It Pa /dev/psm%d
387PS/2 mouse device
388.It Pa /dev/sysmouse
389virtual mouse device
390.It Pa /dev/ums%d
391USB mouse device
392.El
393.Sh SEE ALSO
394.Xr ioctl 2 ,
395.Xr mse 4 ,
396.Xr psm 4 ,
397.Xr sysmouse 4 ,
398.Xr ums 4 ,
399.Xr moused 8
400.\".Sh HISTORY
401.Sh AUTHORS
402This manual page was written by
403.An Kazutaka Yokota Aq Mt yokota@FreeBSD.org .
404