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