xref: /freebsd/share/man/man4/sysmouse.4 (revision 8d20be1e22095c27faf8fe8b2f0d089739cc742e)
1.\" Copyright 1997 John-Mark Gurney.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\" 3. Neither the name of the author nor the names of any co-contributors
12.\"    may be used to endorse or promote products derived from this software
13.\"    without specific prior written permission.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY John-Mark Gurney AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.\" $FreeBSD$
28.\"
29.Dd January 16, 2010
30.Dt SYSMOUSE 4
31.Os
32.Sh NAME
33.Nm sysmouse
34.\" .Nd supplies mouse data from syscons for other applications
35.Nd virtualized mouse driver
36.Sh SYNOPSIS
37.In sys/mouse.h
38.In sys/consio.h
39.Sh DESCRIPTION
40The console driver, in conjunction with the mouse daemon
41.Xr moused 8 ,
42supplies mouse data to the user process in the standardized way via the
43.Nm
44driver.
45This arrangement makes it possible for the console and the user process
46(such as the
47.Tn X\ Window System )
48to share the mouse.
49.Pp
50The user process which wants to utilize mouse operation simply opens
51.Pa /dev/sysmouse
52with a
53.Xr open 2
54call and reads
55mouse data from the device via
56.Xr read 2 .
57Make sure that
58.Xr moused 8
59is running, otherwise the user process will not see any data coming from
60the mouse.
61.Pp
62.Ss Operation Levels
63The
64.Nm
65driver has two levels of operation.
66The current operation level can be referred to and changed via ioctl calls.
67.Pp
68The level zero, the basic level, is the lowest level at which the driver
69offers the basic service to user programs.
70The
71.Nm
72driver
73provides horizontal and vertical movement of the mouse
74and state of up to three buttons in the
75.Tn MouseSystems
76format as 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.
103To obtain the full horizontal movement count, add
104the byte 2 and 4.
105.It Byte 5
106The second half of the vertical movement count in two's complement;
107\-128 through 127.
108To obtain the full vertical movement count, add
109the byte 3 and 5.
110.El
111.Pp
112At the level one, the extended level, mouse data is encoded
113in the standard format
114.Dv MOUSE_PROTO_SYSMOUSE
115as defined in
116.Xr mouse 4 .
117.\" .Ss Acceleration
118.\" The
119.\" .Nm
120.\" driver can somewhat `accelerate' the movement of the pointing device.
121.\" The faster you move the device, the further the pointer
122.\" travels on the screen.
123.\" The driver has an internal variable which governs the effect of
124.\" the acceleration. Its value can be modified via the driver flag
125.\" or via an ioctl call.
126.Sh IOCTLS
127This section describes two classes of
128.Xr ioctl 2
129commands:
130commands for the
131.Nm
132driver itself, and commands for the console and the console control drivers.
133.Ss Sysmouse Ioctls
134There are a few commands for mouse drivers.
135General description of the commands is given in
136.Xr mouse 4 .
137Following are the features specific to the
138.Nm
139driver.
140.Pp
141.Bl -tag -width MOUSE -compact
142.It Dv MOUSE_GETLEVEL Ar int *level
143.It Dv MOUSE_SETLEVEL Ar int *level
144These commands manipulate the operation level of the mouse driver.
145.Pp
146.It Dv MOUSE_GETHWINFO Ar mousehw_t *hw
147Returns the hardware information of the attached device in the following
148structure.
149Only the
150.Va iftype
151field is guaranteed to be filled with the correct value in the current
152version of the
153.Nm
154driver.
155.Bd -literal
156typedef struct mousehw {
157    int buttons;    /* number of buttons */
158    int iftype;     /* I/F type */
159    int type;       /* mouse/track ball/pad... */
160    int model;      /* I/F dependent model ID */
161    int hwid;       /* I/F dependent hardware ID */
162} mousehw_t;
163.Ed
164.Pp
165The
166.Va buttons
167field holds the number of buttons detected by the driver.
168.Pp
169The
170.Va iftype
171is always
172.Dv MOUSE_IF_SYSMOUSE .
173.Pp
174The
175.Va type
176tells the device type:
177.Dv MOUSE_MOUSE ,
178.Dv MOUSE_TRACKBALL ,
179.Dv MOUSE_STICK ,
180.Dv MOUSE_PAD ,
181or
182.Dv MOUSE_UNKNOWN .
183.Pp
184The
185.Va model
186is always
187.Dv MOUSE_MODEL_GENERIC
188at the operation level 0.
189It may be
190.Dv MOUSE_MODEL_GENERIC
191or one of
192.Dv MOUSE_MODEL_XXX
193constants at higher operation levels.
194.Pp
195The
196.Va hwid
197is always zero.
198.Pp
199.It Dv MOUSE_GETMODE Ar mousemode_t *mode
200The command gets the current operation parameters of the mouse
201driver.
202.Bd -literal
203typedef struct mousemode {
204    int protocol;    /* MOUSE_PROTO_XXX */
205    int rate;        /* report rate (per sec) */
206    int resolution;  /* MOUSE_RES_XXX, -1 if unknown */
207    int accelfactor; /* acceleration factor */
208    int level;       /* driver operation level */
209    int packetsize;  /* the length of the data packet */
210    unsigned char syncmask[2]; /* sync. bits */
211} mousemode_t;
212.Ed
213.Pp
214The
215.Va protocol
216field tells the format in which the device status is returned
217when the mouse data is read by the user program.
218It is
219.Dv MOUSE_PROTO_MSC
220at the operation level zero.
221.Dv MOUSE_PROTO_SYSMOUSE
222at the operation level one.
223.Pp
224The
225.Va rate
226is always set to \-1.
227.Pp
228The
229.Va resolution
230is always set to \-1.
231.Pp
232The
233.Va accelfactor
234is always 0.
235.Pp
236The
237.Va packetsize
238field specifies the length of the data packet.
239It depends on the
240operation level.
241.Pp
242.Bl -tag -width level_0__ -compact
243.It Em level 0
2445 bytes
245.It Em level 1
2468 bytes
247.El
248.Pp
249The array
250.Va syncmask
251holds a bit mask and pattern to detect the first byte of the
252data packet.
253.Va syncmask[0]
254is the bit mask to be ANDed with a byte.
255If the result is equal to
256.Va syncmask[1] ,
257the byte is likely to be the first byte of the data packet.
258Note that this method of detecting the first byte is not 100% reliable;
259thus, it should be taken only as an advisory measure.
260.Pp
261.It Dv MOUSE_SETMODE Ar mousemode_t *mode
262The command changes the current operation parameters of the mouse driver
263as specified in
264.Ar mode .
265Only
266.Va level
267may be modifiable.
268Setting values in the other field does not generate
269error and has no effect.
270.\" .Pp
271.\" .It Dv MOUSE_GETVARS Ar mousevar_t *vars
272.\" .It Dv MOUSE_SETVARS Ar mousevar_t *vars
273.\" These commands are not supported by the
274.\" .Nm
275.\" driver.
276.Pp
277.It Dv MOUSE_READDATA Ar mousedata_t *data
278.It Dv MOUSE_READSTATE Ar mousedata_t *state
279These commands are not supported by the
280.Nm
281driver.
282.Pp
283.It Dv MOUSE_GETSTATUS Ar mousestatus_t *status
284The command returns the current state of buttons and
285movement counts in the structure as defined in
286.Xr mouse 4 .
287.El
288.Ss Console and Consolectl Ioctls
289The user process issues console
290.Fn ioctl
291calls to the current virtual console in order to control
292the mouse pointer.
293The console
294.Fn ioctl
295also provides a method for the user process to receive a
296.Xr signal 3
297when a button is pressed.
298.Pp
299The mouse daemon
300.Xr moused 8
301uses
302.Fn ioctl
303calls to the console control device
304.Pa /dev/consolectl
305to inform the console of mouse actions including mouse movement
306and button status.
307.Pp
308Both classes of
309.Fn ioctl
310commands are defined as
311.Dv CONS_MOUSECTL
312which takes the following argument.
313.Bd -literal
314struct mouse_info {
315    int operation;
316    union {
317        struct mouse_data data;
318        struct mouse_mode mode;
319        struct mouse_event event;
320    } u;
321};
322.Ed
323.Pp
324.Bl -tag -width operation -compact
325.It Va operation
326This can be one of
327.Pp
328.Bl -tag -width MOUSE_MOVEABS -compact
329.It Dv MOUSE_SHOW
330Enables and displays mouse cursor.
331.It Dv MOUSE_HIDE
332Disables and hides mouse cursor.
333.It Dv MOUSE_MOVEABS
334Moves mouse cursor to position supplied in
335.Va u.data .
336.It Dv MOUSE_MOVEREL
337Adds position supplied in
338.Va u.data
339to current position.
340.It Dv MOUSE_GETINFO
341Returns current mouse position in the current virtual console
342and button status in
343.Va u.data .
344.It Dv MOUSE_MODE
345This sets the
346.Xr signal 3
347to be delivered to the current process when a button is pressed.
348The signal to be delivered is set in
349.Va u.mode .
350.El
351.Pp
352The above operations are for virtual consoles.
353The operations defined
354below are for the console control device and are used by
355.Xr moused 8
356to pass mouse data to the console driver.
357.Pp
358.Bl -tag -width MOUSE_MOVEABS -compact
359.It Dv MOUSE_ACTION
360.It Dv MOUSE_MOTION_EVENT
361These operations take the information in
362.Va u.data
363and act upon it.
364Mouse data will be sent to the
365.Nm
366driver if it is open.
367.Dv MOUSE_ACTION
368also processes button press actions and sends signal to the process if
369requested or performs cut and paste operations
370if the current console is a text interface.
371.It Dv MOUSE_BUTTON_EVENT
372.Va u.data
373specifies a button and its click count.
374The console driver will
375use this information for signal delivery if requested or
376for cut and paste operations if the console is in text mode.
377.El
378.Pp
379.Dv MOUSE_MOTION_EVENT
380and
381.Dv MOUSE_BUTTON_EVENT
382are newer interface and are designed to be used together.
383They are intended to replace functions performed by
384.Dv MOUSE_ACTION
385alone.
386.Pp
387.It Va u
388This union is one of
389.Pp
390.Bl -tag -width data -compact
391.It Va data
392.Bd -literal
393struct mouse_data {
394    int x;
395    int y;
396    int z;
397    int buttons;
398};
399.Ed
400.Pp
401.Va x , y
402and
403.Va z
404represent movement of the mouse along respective directions.
405.Va buttons
406tells the state of buttons.
407It encodes up to 31 buttons in the bit 0 though
408the bit 30.
409If a button is held down, the corresponding bit is set.
410.Pp
411.It Va mode
412.Bd -literal
413struct mouse_mode {
414    int mode;
415    int signal;
416};
417.Ed
418.Pp
419The
420.Va signal
421field specifies the signal to be delivered to the process.
422It must be
423one of the values defined in
424.In signal.h .
425The
426.Va mode
427field is currently unused.
428.Pp
429.It Va event
430.Bd -literal
431struct mouse_event {
432    int id;
433    int value;
434};
435.Ed
436.Pp
437The
438.Va id
439field specifies a button number as in
440.Va u.data.buttons .
441Only one bit/button is set.
442The
443.Va value
444field
445holds the click count: the number of times the user has clicked the button
446successively.
447.Pp
448.El
449.El
450.Sh FILES
451.Bl -tag -width /dev/consolectl -compact
452.It Pa /dev/consolectl
453device to control the console
454.It Pa /dev/sysmouse
455virtualized mouse driver
456.It Pa /dev/ttyv%d
457virtual consoles
458.El
459.Sh SEE ALSO
460.Xr vidcontrol 1 ,
461.Xr ioctl 2 ,
462.Xr signal 3 ,
463.Xr mouse 4 ,
464.Xr moused 8
465.Sh HISTORY
466The
467.Nm
468driver first appeared in
469.Fx 2.2 .
470.Sh AUTHORS
471.An -nosplit
472This
473manual page was written by
474.An John-Mark Gurney Aq gurney_j@efn.org
475and
476.An Kazutaka Yokota Aq yokota@FreeBSD.org .
477