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