First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / linux / bus.c
blob2d7a15751d67688421eea0f6d8cacc1622ad8f40
1 /*
2 * Copyright © 2000 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.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #define NEED_EVENTS
27 #include <X11/X.h>
28 #include <X11/Xproto.h>
29 #include <X11/Xpoll.h>
30 #include "inputstr.h"
31 #include "scrnintstr.h"
32 #include "kdrive.h"
34 /* /dev/adbmouse is a busmouse */
36 static void
37 BusRead (int adbPort, void *closure)
39 unsigned char buf[3];
40 int n;
41 int dx, dy;
42 unsigned long flags;
44 n = read (adbPort, buf, 3);
45 if (n == 3)
47 flags = KD_MOUSE_DELTA;
48 dx = (char) buf[1];
49 dy = -(char) buf[2];
50 if ((buf[0] & 4) == 0)
51 flags |= KD_BUTTON_1;
52 if ((buf[0] & 2) == 0)
53 flags |= KD_BUTTON_2;
54 if ((buf[0] & 1) == 0)
55 flags |= KD_BUTTON_3;
56 KdEnqueuePointerEvent (closure, flags, dx, dy, 0);
60 char *BusNames[] = {
61 "/dev/adbmouse",
62 "/dev/mouse",
65 #define NUM_BUS_NAMES (sizeof (BusNames) / sizeof (BusNames[0]))
67 static int
68 BusInit (KdPointerInfo *pi)
70 int i, fd = 0;
72 if (!pi->path || (strcmp(pi->path, "auto") == 0))
74 for (i = 0; i < NUM_BUS_NAMES; i++)
76 if ((fd = open (BusNames[i], 0)) > 0)
78 close(fd);
79 if (pi->path)
80 xfree(pi->path);
81 pi->path = KdSaveString(BusNames[i]);
82 return Success;
86 else
88 if ((fd = open(pi->path, 0)) > 0)
90 close(fd);
91 return Success;
95 return !Success;
98 static int
99 BusEnable (KdPointerInfo *pi)
101 int fd = open(pi->path, 0);
103 if (fd > 0)
105 KdRegisterFd(fd, BusRead, pi);
106 pi->driverPrivate = (void *)fd;
107 return Success;
109 else
111 return !Success;
115 static void
116 BusDisable (KdPointerInfo *pi)
118 KdUnregisterFd(pi, (int)pi->driverPrivate, TRUE);
121 static void
122 BusFini (KdPointerInfo *pi)
124 return;
127 KdPointerDriver BusMouseDriver = {
128 "bus",
129 BusInit,
130 BusEnable,
131 BusDisable,
132 BusFini,
133 NULL