summaryrefslogtreecommitdiff
path: root/hw/kdrive/linux
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2007-08-23 18:19:17 -0700
committerIan Romanick <idr@us.ibm.com>2007-08-23 18:19:17 -0700
commit8b6b40b7271acd81a9548f502c18f46f3b640640 (patch)
tree1462cb63501a8bdd8845d7c62e038b6a86b78fd5 /hw/kdrive/linux
parentab7a6d860d4a275a810a64b1ba7b13726ed10575 (diff)
parent3305d17195e3a0a5555300555bd7703312fa489f (diff)
Merge branch 'master' of git+ssh://git.freedesktop.org/git/xorg/xserver into pci-reworkpci-rework
Conflicts: hw/xfree86/common/xf86.h hw/xfree86/common/xf86Init.c hw/xfree86/common/xf86pciBus.c hw/xfree86/int10/generic.c hw/xfree86/int10/helper_exec.c hw/xfree86/loader/xf86sym.c hw/xfree86/os-support/bus/Pci.c hw/xfree86/os-support/bus/Pci.h hw/xfree86/os-support/bus/linuxPci.c hw/xfree86/os-support/linux/int10/linux.c
Diffstat (limited to 'hw/kdrive/linux')
-rw-r--r--hw/kdrive/linux/agp.c2
-rw-r--r--hw/kdrive/linux/bus.c2
-rw-r--r--hw/kdrive/linux/evdev.c315
-rw-r--r--hw/kdrive/linux/keyboard.c2
-rw-r--r--hw/kdrive/linux/klinux.h2
-rw-r--r--hw/kdrive/linux/linux.c4
-rw-r--r--hw/kdrive/linux/mouse.c2
-rw-r--r--hw/kdrive/linux/ms.c1
-rw-r--r--hw/kdrive/linux/ps2.c2
-rw-r--r--hw/kdrive/linux/ts.c2
-rw-r--r--hw/kdrive/linux/tslib.c2
11 files changed, 273 insertions, 63 deletions
diff --git a/hw/kdrive/linux/agp.c b/hw/kdrive/linux/agp.c
index 4fb0cb3f9..80fb7259b 100644
--- a/hw/kdrive/linux/agp.c
+++ b/hw/kdrive/linux/agp.c
@@ -35,8 +35,6 @@ of the copyright holder.
*/
-/* $RCSId: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c,v 3.4 2000/08/28 18:12:56 dawes Exp $ */
-
/*
* Author: Pontus Lidman <pontus.lidman@nokia.com> (adaption to KDrive) and others
*/
diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c
index 8cf5f901f..2d7a15751 100644
--- a/hw/kdrive/linux/bus.c
+++ b/hw/kdrive/linux/bus.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/bus.c,v 1.2 2001/06/29 14:00:41 keithp Exp $
- *
* Copyright © 2000 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 6c08cfa62..2eaa1e332 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Copyright © 2004 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
@@ -44,11 +42,8 @@
#define OFF(x) ((x)%BITS_PER_LONG)
#define LONG(x) ((x)/BITS_PER_LONG)
#define BIT(x) (1 << OFF(x))
-#define SETBIT(x,y) ((x)[LONG(y)] |= BIT(y))
-#define CLRBIT(x,y) ((x)[LONG(y)] &= ~BIT(y))
-#define ASSIGNBIT(x,y,z) ((x)[LONG(y)] = ((x)[LONG(y)] & ~BIT(y)) | (z << OFF(y)))
-typedef struct _kevdevMouse {
+typedef struct _kevdev {
/* current device state */
int rel[REL_MAX + 1];
int abs[ABS_MAX + 1];
@@ -67,23 +62,60 @@ typedef struct _kevdevMouse {
} Kevdev;
static void
-EvdevMotion (KdPointerInfo *pi)
+EvdevPtrBtn (KdPointerInfo *pi, struct input_event *ev)
+{
+ int flags = KD_MOUSE_DELTA | pi->buttonState;
+
+ if (ev->code >= BTN_MOUSE && ev->code < BTN_JOYSTICK) {
+ switch (ev->code) {
+ case BTN_LEFT:
+ if (ev->value == 1)
+ flags |= KD_BUTTON_1;
+ else
+ flags &= ~KD_BUTTON_1;
+ break;
+ case BTN_MIDDLE:
+ if (ev->value == 1)
+ flags |= KD_BUTTON_2;
+ else
+ flags &= ~KD_BUTTON_2;
+ break;
+ case BTN_RIGHT:
+ if (ev->value == 1)
+ flags |= KD_BUTTON_3;
+ else
+ flags &= ~KD_BUTTON_3;
+ break;
+ default:
+ /* Unknow button */
+ break;
+ }
+
+ KdEnqueuePointerEvent (pi, flags, 0, 0, 0);
+ }
+}
+static void
+EvdevPtrMotion (KdPointerInfo *pi, struct input_event *ev)
{
Kevdev *ke = pi->driverPrivate;
- int i;
+ int i;
+ int flags = KD_MOUSE_DELTA | pi->buttonState;
for (i = 0; i <= ke->max_rel; i++)
if (ke->rel[i])
{
int a;
- ErrorF ("rel");
for (a = 0; a <= ke->max_rel; a++)
{
- if (ISBITSET (ke->relbits, a))
- ErrorF (" %d=%d", a, ke->rel[a]);
- ke->rel[a] = 0;
+ if (ISBITSET (ke->relbits, a))
+ {
+ if (a == 0)
+ KdEnqueuePointerEvent(pi, flags, ke->rel[a], 0, 0);
+ else if (a == 1)
+ KdEnqueuePointerEvent(pi, flags, 0, ke->rel[a], 0);
+ }
+ ke->rel[a] = 0;
}
- ErrorF ("\n");
break;
}
for (i = 0; i < ke->max_abs; i++)
@@ -100,10 +132,30 @@ EvdevMotion (KdPointerInfo *pi)
ErrorF ("\n");
break;
}
+
+ if (ev->code == REL_WHEEL) {
+ for (i = 0; i < abs (ev->value); i++)
+ {
+ if (ev->value > 0)
+ flags |= KD_BUTTON_4;
+ else
+ flags |= KD_BUTTON_5;
+
+ KdEnqueuePointerEvent (pi, flags, 0, 0, 0);
+
+ if (ev->value > 0)
+ flags &= ~KD_BUTTON_4;
+ else
+ flags &= ~KD_BUTTON_5;
+
+ KdEnqueuePointerEvent (pi, flags, 0, 0, 0);
+ }
+ }
+
}
static void
-EvdevRead (int evdevPort, void *closure)
+EvdevPtrRead (int evdevPort, void *closure)
{
KdPointerInfo *pi = closure;
Kevdev *ke = pi->driverPrivate;
@@ -112,8 +164,12 @@ EvdevRead (int evdevPort, void *closure)
int n;
n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
- if (n <= 0)
+ if (n <= 0) {
+ if (errno == ENODEV)
+ DeleteInputDeviceRequest(pi->dixdev);
return;
+ }
+
n /= sizeof (struct input_event);
for (i = 0; i < n; i++)
{
@@ -121,26 +177,20 @@ EvdevRead (int evdevPort, void *closure)
case EV_SYN:
break;
case EV_KEY:
- EvdevMotion (pi);
- ASSIGNBIT(ke->key,events[i].code, events[i].value);
- if (events[i].code < 0x100)
- ErrorF ("key %d %d\n", events[i].code, events[i].value);
- else
- ErrorF ("key 0x%x %d\n", events[i].code, events[i].value);
+ EvdevPtrBtn (pi, &events[i]);
break;
case EV_REL:
ke->rel[events[i].code] += events[i].value;
+ EvdevPtrMotion (pi, &events[i]);
break;
case EV_ABS:
ke->abs[events[i].code] = events[i].value;
+ EvdevPtrMotion (pi, &events[i]);
break;
}
}
- EvdevMotion (pi);
}
-int EvdevInputType;
-
char *kdefaultEvdev[] = {
"/dev/input/event0",
"/dev/input/event1",
@@ -151,35 +201,37 @@ char *kdefaultEvdev[] = {
#define NUM_DEFAULT_EVDEV (sizeof (kdefaultEvdev) / sizeof (kdefaultEvdev[0]))
static Status
-EvdevInit (KdPointerInfo *pi)
+EvdevPtrInit (KdPointerInfo *pi)
{
int i;
int fd;
- int n = 0;
- char *prot;
if (!pi->path) {
for (i = 0; i < NUM_DEFAULT_EVDEV; i++) {
fd = open (kdefaultEvdev[i], 2);
- if (fd >= 0) {
- pi->path = KdSaveString (kdefaultEvdev[i]);
- break;
- }
+ if (fd >= 0) {
+ pi->path = KdSaveString (kdefaultEvdev[i]);
+ break;
}
+ }
}
else {
- fd = open (pi->path, 2);
+ fd = open (pi->path, O_RDWR);
if (fd < 0) {
ErrorF("Failed to open evdev device %s\n", pi->path);
return BadMatch;
}
}
+ close(fd);
+
+ pi->name = KdSaveString("Evdev mouse");
+
return Success;
}
static Status
-EvdevEnable (KdPointerInfo *pi)
+EvdevPtrEnable (KdPointerInfo *pi)
{
int fd;
@@ -263,20 +315,24 @@ EvdevEnable (KdPointerInfo *pi)
return BadValue;
}
}
- if (!KdRegisterFd (fd, EvdevRead, pi)) {
+ if (!KdRegisterFd (fd, EvdevPtrRead, pi)) {
xfree (ke);
close (fd);
return BadAlloc;
}
pi->driverPrivate = ke;
+ ke->fd = fd;
+
return Success;
}
static void
-EvdevDisable (KdPointerInfo *pi)
+EvdevPtrDisable (KdPointerInfo *pi)
{
Kevdev *ke;
+ ke = pi->driverPrivate;
+
if (!pi || !pi->driverPrivate)
return;
@@ -286,26 +342,195 @@ EvdevDisable (KdPointerInfo *pi)
}
static void
-EvdevFini (KdPointerInfo *pi)
+EvdevPtrFini (KdPointerInfo *pi)
+{
+}
+
+
+/*
+ * Evdev keyboard functions
+ */
+
+static void
+readMapping (KdKeyboardInfo *ki)
+{
+ int minScanCode, maxScanCode;
+
+ if (!ki)
+ return;
+
+ minScanCode = 0;
+ maxScanCode = 193;
+
+ ki->keySyms.mapWidth = 2;
+
+ ki->minScanCode = minScanCode;
+ ki->maxScanCode = maxScanCode;
+}
+
+static void
+EvdevKbdRead (int evdevPort, void *closure)
+{
+ KdKeyboardInfo *ki = closure;
+ struct input_event events[NUM_EVENTS];
+ int i, n;
+
+ n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
+ if (n <= 0) {
+ if (errno == ENODEV)
+ DeleteInputDeviceRequest(ki->dixdev);
+ return;
+ }
+
+ n /= sizeof (struct input_event);
+ for (i = 0; i < n; i++)
+ {
+ if (events[i].type == EV_KEY)
+ KdEnqueueKeyboardEvent (ki, events[i].code, !events[i].value);
+/* FIXME: must implement other types of events
+ else
+ ErrorF("Event type (%d) not delivered\n", events[i].type);
+*/
+ }
+}
+
+static Status
+EvdevKbdInit (KdKeyboardInfo *ki)
+{
+ int fd;
+
+ if (!ki->path) {
+ ErrorF("Couldn't find evdev device path\n");
+ return BadValue;
+ }
+ else {
+ fd = open (ki->path, O_RDWR);
+ if (fd < 0) {
+ ErrorF("Failed to open evdev device %s\n", ki->path);
+ return BadMatch;
+ }
+ }
+
+ close (fd);
+
+ ki->name = KdSaveString("Evdev keyboard");
+
+ readMapping(ki);
+
+ return Success;
+}
+
+static Status
+EvdevKbdEnable (KdKeyboardInfo *ki)
+{
+ unsigned long ev[NBITS(EV_MAX)];
+ Kevdev *ke;
+ int fd;
+
+ if (!ki || !ki->path)
+ return BadImplementation;
+
+ fd = open(ki->path, O_RDWR);
+ if (fd < 0)
+ return BadMatch;
+
+ if (ioctl (fd, EVIOCGBIT(0 /*EV*/, sizeof (ev)), ev) < 0) {
+ perror ("EVIOCGBIT 0");
+ close (fd);
+ return BadMatch;
+ }
+
+ ke = xalloc (sizeof (Kevdev));
+ if (!ke) {
+ close (fd);
+ return BadAlloc;
+ }
+ memset (ke, '\0', sizeof (Kevdev));
+
+ if (!KdRegisterFd (fd, EvdevKbdRead, ki)) {
+ xfree (ke);
+ close (fd);
+ return BadAlloc;
+ }
+ ki->driverPrivate = ke;
+ ke->fd = fd;
+
+ return Success;
+}
+
+static void
+EvdevKbdLeds (KdKeyboardInfo *ki, int leds)
+{
+/* struct input_event event;
+ Kevdev *ke;
+
+ ki->driverPrivate = ke;
+
+ memset(&event, 0, sizeof(event));
+
+ event.type = EV_LED;
+ event.code = LED_CAPSL;
+ event.value = leds & (1 << 0) ? 1 : 0;
+ write(ke->fd, (char *) &event, sizeof(event));
+
+ event.type = EV_LED;
+ event.code = LED_NUML;
+ event.value = leds & (1 << 1) ? 1 : 0;
+ write(ke->fd, (char *) &event, sizeof(event));
+
+ event.type = EV_LED;
+ event.code = LED_SCROLLL;
+ event.value = leds & (1 << 2) ? 1 : 0;
+ write(ke->fd, (char *) &event, sizeof(event));
+
+ event.type = EV_LED;
+ event.code = LED_COMPOSE;
+ event.value = leds & (1 << 3) ? 1 : 0;
+ write(ke->fd, (char *) &event, sizeof(event));
+*/
+}
+
+static void
+EvdevKbdBell (KdKeyboardInfo *ki, int volume, int frequency, int duration)
+{
+}
+
+static void
+EvdevKbdDisable (KdKeyboardInfo *ki)
+{
+ Kevdev *ke;
+
+ ke = ki->driverPrivate;
+
+ if (!ki || !ki->driverPrivate)
+ return;
+
+ KdUnregisterFd (ki, ke->fd, TRUE);
+ xfree (ke);
+ ki->driverPrivate = 0;
+}
+
+static void
+EvdevKbdFini (KdKeyboardInfo *ki)
{
}
KdPointerDriver LinuxEvdevMouseDriver = {
"evdev",
- EvdevInit,
- EvdevEnable,
- EvdevDisable,
- EvdevFini,
+ EvdevPtrInit,
+ EvdevPtrEnable,
+ EvdevPtrDisable,
+ EvdevPtrFini,
NULL,
};
-#if 0
-KdKeyboardFuncs LinuxEvdevKeyboardFuncs = {
- EvdevKbdLoad,
+KdKeyboardDriver LinuxEvdevKeyboardDriver = {
+ "evdev",
EvdevKbdInit,
+ EvdevKbdEnable,
EvdevKbdLeds,
EvdevKbdBell,
+ EvdevKbdDisable,
EvdevKbdFini,
- 0,
+ NULL,
};
-#endif
diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c
index ad9907a59..3193ab761 100644
--- a/hw/kdrive/linux/keyboard.c
+++ b/hw/kdrive/linux/keyboard.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/keyboard.c,v 1.10 2001/11/08 10:26:24 keithp Exp $
- *
* Copyright © 1999 Keith Packard
* XKB integration © 2006 Nokia Corporation, author: Tomas Frydrych <tf@o-hand.com>
*
diff --git a/hw/kdrive/linux/klinux.h b/hw/kdrive/linux/klinux.h
index 29ebe3aa9..349685241 100644
--- a/hw/kdrive/linux/klinux.h
+++ b/hw/kdrive/linux/klinux.h
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Copyright © 2003 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index c1fe185bd..23cd8f59f 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/linux.c,v 1.6 2001/07/24 21:26:17 keithp Exp $
- *
* Copyright © 1999 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
@@ -458,7 +456,9 @@ KdOsAddInputDrivers ()
#ifdef TSLIB
KdAddPointerDriver(&TsDriver);
#endif
+ KdAddPointerDriver(&LinuxEvdevMouseDriver);
KdAddKeyboardDriver(&LinuxKeyboardDriver);
+ KdAddKeyboardDriver(&LinuxEvdevKeyboardDriver);
}
static void
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index 77ec3b37b..1965342b8 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/mouse.c,v 1.6 2002/08/02 16:11:35 keithp Exp $
- *
* Copyright © 2001 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c
index e62cebc39..d0b47a3ee 100644
--- a/hw/kdrive/linux/ms.c
+++ b/hw/kdrive/linux/ms.c
@@ -20,7 +20,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* $RCSId: xc/programs/Xserver/hw/kdrive/linux/ms.c,v 1.1 2001/08/09 20:45:15 dawes Exp $ */
#ifdef HAVE_CONFIG_H
#include <kdrive-config.h>
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index 5d523a210..d361e82a1 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/ps2.c,v 1.6 2001/10/12 06:33:10 keithp Exp $
- *
* Copyright © 1999 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
diff --git a/hw/kdrive/linux/ts.c b/hw/kdrive/linux/ts.c
index 701fdc891..831953f02 100644
--- a/hw/kdrive/linux/ts.c
+++ b/hw/kdrive/linux/ts.c
@@ -1,6 +1,4 @@
/*
- * $RCSId: xc/programs/Xserver/hw/kdrive/linux/ts.c,v 1.9 2002/08/15 18:07:48 keithp Exp $
- *
* Derived from ps2.c by Jim Gettys
*
* Copyright © 1999 Keith Packard
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 41b74fabd..371aeced9 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -118,7 +118,7 @@ TslibEnable (KdPointerInfo *pi)
private->fd = ts_fd(private->tsDev);
if (!private->tsDev || ts_config(private->tsDev) || private->fd < 0) {
ErrorF("[tslib/TslibEnable] failed to open %s\n", pi->path);
- if (private->fd > 0);
+ if (private->fd >= 0)
close(private->fd);
return BadAlloc;
}