2 * Copyright © 1999 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #include <kdrive-config.h>
27 #include <X11/Xproto.h>
28 #include <X11/Xpoll.h>
30 #include "scrnintstr.h"
34 Ps2ReadBytes(int fd
, char *buf
, int len
, int min
)
42 n
= read(fd
, buf
, len
);
53 tv
.tv_usec
= 100 * 1000;
54 n
= select(fd
+ 1, &set
, 0, 0, &tv
);
61 const char *Ps2Names
[] = {
67 #define NUM_PS2_NAMES (sizeof (Ps2Names) / sizeof (Ps2Names[0]))
70 Ps2Read(int ps2Port
, void *closure
)
72 unsigned char buf
[3 * 200];
77 unsigned long left_button
= KD_BUTTON_1
;
78 unsigned long right_button
= KD_BUTTON_3
;
83 left_button
= KD_BUTTON_3
;
84 right_button
= KD_BUTTON_1
;
87 while ((n
= Ps2ReadBytes(ps2Port
, (char *) buf
, sizeof(buf
), 3)) > 0) {
90 flags
= KD_MOUSE_DELTA
;
94 flags
|= right_button
;
107 KdEnqueuePointerEvent(closure
, flags
, dx
, dy
, 0);
113 Ps2Init(KdPointerInfo
* pi
)
118 for (i
= 0; i
< NUM_PS2_NAMES
; i
++) {
119 ps2Port
= open(Ps2Names
[i
], 0);
121 pi
->path
= strdup(Ps2Names
[i
]);
127 ps2Port
= open(pi
->path
, 0);
135 pi
->name
= strdup("PS/2 Mouse");
141 Ps2Enable(KdPointerInfo
* pi
)
146 return BadImplementation
;
148 fd
= open(pi
->path
, 0);
152 if (!KdRegisterFd(fd
, Ps2Read
, pi
)) {
157 pi
->driverPrivate
= (void *) (intptr_t) fd
;
163 Ps2Disable(KdPointerInfo
* pi
)
165 KdUnregisterFd(pi
, (int) (intptr_t) pi
->driverPrivate
, TRUE
);
169 Ps2Fini(KdPointerInfo
* pi
)
173 KdPointerDriver Ps2MouseDriver
= {