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 won't 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. To 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. To obtain the full vertical movement count, add 108the byte 3 and 5. 109.El 110.Pp 111At the level one, the extended level, mouse data is encoded 112in the standard format 113.Dv MOUSE_PROTO_SYSMOUSE 114as 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 126This section describes two classes of 127.Xr ioctl 2 128commands: 129commands for the 130.Nm 131driver itself, and commands for the console and the console control drivers. 132.Ss Sysmouse Ioctls 133There are a few commands for mouse drivers. 134General description of the commands is given in 135.Xr mouse 4 . 136Following are the features specific to the 137.Nm 138driver. 139.Pp 140.Bl -tag -width MOUSE -compact 141.It Dv MOUSE_GETLEVEL Ar int *level 142.It Dv MOUSE_SETLEVEL Ar int *level 143These commands manipulate the operation level of the mouse driver. 144.Pp 145.It Dv MOUSE_GETHWINFO Ar mousehw_t *hw 146Returns the hardware information of the attached device in the following 147structure. Only the 148.Dv iftype 149field is guaranteed to be filled with the correct value in the current 150version of the 151.Nm 152driver. 153.Bd -literal 154typedef 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 163The 164.Dv buttons 165field holds the number of buttons detected by the driver. 166.Pp 167The 168.Dv iftype 169is always 170.Dv MOUSE_IF_SYSMOUSE . 171.Pp 172The 173.Dv type 174tells the device type: 175.Dv MOUSE_MOUSE , 176.Dv MOUSE_TRACKBALL , 177.Dv MOUSE_STICK , 178.Dv MOUSE_PAD , 179or 180.Dv MOUSE_UNKNOWN . 181.Pp 182The 183.Dv model 184is always 185.Dv MOUSE_MODEL_GENERIC 186at the operation level 0. 187It may be 188.Dv MOUSE_MODEL_GENERIC 189or one of 190.Dv MOUSE_MODEL_XXX 191constants at higher operation levels. 192.Pp 193The 194.Dv hwid 195is always zero. 196.Pp 197.It Dv MOUSE_GETMODE Ar mousemode_t *mode 198The command gets the current operation parameters of the mouse 199driver. 200.Bd -literal 201typedef 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 212The 213.Dv protocol 214field tells the format in which the device status is returned 215when the mouse data is read by the user program. 216It is 217.Dv MOUSE_PROTO_MSC 218at the operation level zero. 219.Dv MOUSE_PROTO_SYSMOUSE 220at the operation level one. 221.Pp 222The 223.Dv rate 224is always set to -1. 225.Pp 226The 227.Dv resolution 228is always set to -1. 229.Pp 230The 231.Dv accelfactor 232is always 0. 233.Pp 234The 235.Dv packetsize 236field specifies the length of the data packet. 237It depends on the 238operation level. 239.Pp 240.Bl -tag -width level_0__ -compact 241.It Em level 0 2425 bytes 243.It Em level 1 2448 bytes 245.El 246.Pp 247The array 248.Dv syncmask 249holds a bit mask and pattern to detect the first byte of the 250data packet. 251.Dv syncmask[0] 252is the bit mask to be ANDed with a byte. 253If the result is equal to 254.Dv syncmask[1] , 255the byte is likely to be the first byte of the data packet. 256Note that this method of detecting the first byte is not 100% reliable; 257thus, it should be taken only as an advisory measure. 258.Pp 259.It Dv MOUSE_SETMODE Ar mousemode_t *mode 260The command changes the current operation parameters of the mouse driver 261as specified in 262.Ar mode . 263Only 264.Dv level 265may be modifiable. 266Setting values in the other field does not generate 267error 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 277These commands are not supported by the 278.Nm 279driver. 280.Pp 281.It Dv MOUSE_GETSTATUS Ar mousestatus_t *status 282The command returns the current state of buttons and 283movement counts in the structure as defined in 284.Xr mouse 4 . 285.El 286.Ss Console and Consolectl Ioctls 287The user process issues console 288.Fn ioctl 289calls to the current virtual console in order to control 290the mouse pointer. 291The console 292.Fn ioctl 293also provides a method for the user process to receive a 294.Xr signal 3 295when a button is pressed. 296.Pp 297The mouse daemon 298.Xr moused 8 299uses 300.Fn ioctl 301calls to the console control device 302.Pa /dev/consolectl 303to inform the console of mouse actions including mouse movement 304and button status. 305.Pp 306Both classes of 307.Fn ioctl 308commands are defined as 309.Dv CONS_MOUSECTL 310which takes the following argument. 311.Bd -literal 312struct 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 324This can be one of 325.Pp 326.Bl -tag -width MOUSE_MOVEABS -compact 327.It Dv MOUSE_SHOW 328Enables and displays mouse cursor. 329.It Dv MOUSE_HIDE 330Disables and hides mouse cursor. 331.It Dv MOUSE_MOVEABS 332Moves mouse cursor to position supplied in 333.Dv u.data . 334.It Dv MOUSE_MOVEREL 335Adds position supplied in 336.Dv u.data 337to current position. 338.It Dv MOUSE_GETINFO 339Returns current mouse position in the current virtual console 340and button status in 341.Dv u.data . 342.It Dv MOUSE_MODE 343This sets the 344.Xr signal 3 345to be delivered to the current process when a button is pressed. 346The signal to be delivered is set in 347.Dv u.mode . 348.El 349.Pp 350The above operations are for virtual consoles. 351The operations defined 352below are for the console control device and are used by 353.Xr moused 8 354to 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 359These operations take the information in 360.Dv u.data 361and act upon it. Mouse data will be sent to the 362.Nm 363driver if it is open. 364.Dv MOUSE_ACTION 365also processes button press actions and sends signal to the process if 366requested or performs cut and paste operations 367if the current console is a text interface. 368.It Dv MOUSE_BUTTONEVENT 369.Dv u.data 370specifies a button and its click count. 371The console driver will 372use this information for signal delivery if requested or 373for cut and paste operations if the console is in text mode. 374.El 375.Pp 376.Dv MOUSE_MOTIONEVENT 377and 378.Dv MOUSE_BUTTONEVENT 379are newer interface and are designed to be used together. 380They are intended to replace functions performed by 381.Dv MOUSE_ACTION 382alone. 383.Pp 384.It Dv u 385This union is one of 386.Pp 387.Bl -tag -width data -compact 388.It Dv data 389.Bd -literal 390struct 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 400and 401.Dv z 402represent movement of the mouse along respective directions. 403.Dv buttons 404tells the state of buttons. 405It encodes up to 31 buttons in the bit 0 though 406the bit 30. If a button is held down, the corresponding bit is set. 407.Pp 408.It Dv mode 409.Bd -literal 410struct mouse_mode { 411 int mode; 412 int signal; 413}; 414.Ed 415.Pp 416The 417.Dv signal 418field specifies the signal to be delivered to the process. 419It must be 420one of the values defined in 421.Ao Pa signal.h Ac . 422The 423.Dv mode 424field is currently unused. 425.Pp 426.It Dv event 427.Bd -literal 428struct mouse_event { 429 int id; 430 int value; 431}; 432.Ed 433.Pp 434The 435.Dv id 436field specifies a button number as in 437.Dv u.data.buttons . 438Only one bit/button is set. 439The 440.Dv value 441field 442holds the click count: the number of times the user has clicked the button 443successively. 444.Pp 445.El 446.El 447.Sh FILES 448.Bl -tag -width /dev/consolectl -compact 449.It Pa /dev/consolectl 450device to control the console 451.It Pa /dev/sysmouse 452virtualized mouse driver 453.It Pa /dev/ttyv%d 454virtual consoles 455.El 456.Sh SEE ALSO 457.Xr vidcontrol 1 , 458.Xr ioctl 2 , 459.Xr signal 3 , 460.Xr mouse 4 , 461.Xr moused 8 462.Sh HISTORY 463The 464.Nm 465manual page example first appeared in 466.Fx 2.2 . 467.Sh AUTHORS 468.An -nosplit 469This 470manual page was written by 471.An John-Mark Gurney Aq gurney_j@efn.org 472and 473.An Kazutaka Yokota Aq yokota@FreeBSD.org . 474