2 Copyright (c) 2001 by Juliusz Chroboczek
3 Copyright (c) 1999 by Keith Packard
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include <kdrive-config.h>
30 #include <X11/Xproto.h>
31 #include <X11/Xpoll.h>
33 #include "scrnintstr.h"
37 MsReadBytes(int fd
, char *buf
, int len
, int min
)
45 n
= read(fd
, buf
, len
);
56 tv
.tv_usec
= 100 * 1000;
57 n
= select(fd
+ 1, &set
, 0, 0, &tv
);
65 MsRead(int port
, void *closure
)
67 unsigned char buf
[3 * 200];
73 while ((n
= MsReadBytes(port
, (char *) buf
, sizeof(buf
), 3)) > 0) {
76 flags
= KD_MOUSE_DELTA
;
83 dx
= (char) (((b
[0] & 0x03) << 6) | (b
[1] & 0x3F));
84 dy
= (char) (((b
[0] & 0x0C) << 4) | (b
[2] & 0x3F));
87 KdEnqueuePointerEvent(closure
, flags
, dx
, dy
, 0);
93 MsInit(KdPointerInfo
* pi
)
96 return BadImplementation
;
98 if (!pi
->path
|| strcmp(pi
->path
, "auto"))
99 pi
->path
= strdup("/dev/mouse");
101 pi
->name
= strdup("Microsoft protocol mouse");
107 MsEnable(KdPointerInfo
* pi
)
113 port
= open(pi
->path
, O_RDWR
| O_NONBLOCK
);
115 ErrorF("Couldn't open %s (%d)\n", pi
->path
, (int) errno
);
118 else if (port
== 0) {
119 ErrorF("Opening %s returned 0! Please complain to Keith.\n", pi
->path
);
124 ErrorF("%s is not a tty\n", pi
->path
);
128 ret
= tcgetattr(port
, &t
);
130 ErrorF("Couldn't tcgetattr(%s): %d\n", pi
->path
, errno
);
133 t
.c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
| INLCR
|
134 IGNCR
| ICRNL
| IXON
| IXOFF
);
136 t
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
137 t
.c_cflag
&= ~(CSIZE
| PARENB
);
138 t
.c_cflag
|= CS8
| CLOCAL
| CSTOPB
;
140 cfsetispeed(&t
, B1200
);
141 cfsetospeed(&t
, B1200
);
144 ret
= tcsetattr(port
, TCSANOW
, &t
);
146 ErrorF("Couldn't tcsetattr(%s): %d\n", pi
->path
, errno
);
149 if (KdRegisterFd(port
, MsRead
, pi
))
151 pi
->driverPrivate
= (void *) (intptr_t) port
;
161 MsDisable(KdPointerInfo
* pi
)
163 KdUnregisterFd(pi
, (int) (intptr_t) pi
->driverPrivate
, TRUE
);
167 MsFini(KdPointerInfo
* pi
)
171 KdPointerDriver MsMouseDriver
= {