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