[PATCH] Re-check to see if we can re-add KDrive / Xephyr input devices which get disconnected
andrew at amxl.com
andrew at amxl.com
Fri Jan 14 21:12:31 PST 2011
From: Andrew Miller <ak.miller at auckland.ac.nz>
---
hw/kdrive/ephyr/ephyr.c | 2 +
hw/kdrive/fake/kbd.c | 1 +
hw/kdrive/fake/mouse.c | 2 +
hw/kdrive/linux/evdev.c | 50 +++++++++++++++++++++++++++++++++++++++++++---
hw/kdrive/linux/mouse.c | 1 +
hw/kdrive/linux/ms.c | 1 +
hw/kdrive/linux/ps2.c | 1 +
hw/kdrive/linux/tslib.c | 1 +
hw/kdrive/src/kdrive.h | 2 +
hw/kdrive/src/kinput.c | 21 +++++++++++++++++++
10 files changed, 78 insertions(+), 4 deletions(-)
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 8096a24..f381b1b 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -1090,6 +1090,7 @@ KdPointerDriver EphyrMouseDriver = {
MouseDisable,
MouseFini,
NULL,
+ NULL,
};
/* Keyboard */
@@ -1153,4 +1154,5 @@ KdKeyboardDriver EphyrKeyboardDriver = {
EphyrKeyboardDisable,
EphyrKeyboardFini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/fake/kbd.c b/hw/kdrive/fake/kbd.c
index 51fba04..3f43595 100644
--- a/hw/kdrive/fake/kbd.c
+++ b/hw/kdrive/fake/kbd.c
@@ -72,4 +72,5 @@ KdKeyboardDriver FakeKeyboardDriver = {
FakeKeyboardDisable,
FakeKeyboardFini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/fake/mouse.c b/hw/kdrive/fake/mouse.c
index 758f6cd..4f50bb8 100644
--- a/hw/kdrive/fake/mouse.c
+++ b/hw/kdrive/fake/mouse.c
@@ -63,4 +63,6 @@ KdPointerDriver FakePointerDriver = {
MouseEnable,
MouseDisable,
MouseFini,
+ NULL,
+ NULL,
};
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 3797f09..cb95b4c 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -164,8 +164,11 @@ EvdevPtrRead (int evdevPort, void *closure)
n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
if (n <= 0) {
- if (errno == ENODEV)
- DeleteInputDeviceRequest(pi->dixdev);
+ if (errno == ENODEV) {
+ Kevdev *ke = pi->driverPrivate;
+ KdUnregisterFd (pi, ke->fd, TRUE);
+ ke->fd = -1;
+ }
return;
}
@@ -374,8 +377,11 @@ EvdevKbdRead (int evdevPort, void *closure)
n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
if (n <= 0) {
- if (errno == ENODEV)
- DeleteInputDeviceRequest(ki->dixdev);
+ if (errno == ENODEV) {
+ Kevdev *ke = ki->driverPrivate;
+ KdUnregisterFd (ki, ke->fd, TRUE);
+ ke->fd = -1;
+ }
return;
}
@@ -518,12 +524,47 @@ EvdevKbdFini (KdKeyboardInfo *ki)
{
}
+static void
+EvdevPtrCheck (KdPointerInfo *pi)
+{
+ Kevdev *ke = pi->driverPrivate;
+ if (ke->fd >= 0)
+ return;
+
+ ke->fd = open(pi->path, 2);
+ if (ke->fd < 0)
+ return;
+
+ if (!KdRegisterFd (ke->fd, EvdevPtrRead, pi)) {
+ close(ke->fd);
+ ke->fd = -1;
+ }
+}
+
+static void
+EvdevKbdCheck (KdKeyboardInfo *ki)
+{
+ Kevdev *ke = ki->driverPrivate;
+ if (ke->fd >= 0)
+ return;
+
+ ke->fd = open(ki->path, O_RDWR);
+ if (ke->fd < 0)
+ return;
+
+ if (!KdRegisterFd (ke->fd, EvdevKbdRead, ki)) {
+ close(ke->fd);
+ ke->fd = -1;
+ }
+}
+
KdPointerDriver LinuxEvdevMouseDriver = {
"evdev",
EvdevPtrInit,
EvdevPtrEnable,
EvdevPtrDisable,
EvdevPtrFini,
+ EvdevPtrCheck,
NULL,
};
@@ -535,5 +576,6 @@ KdKeyboardDriver LinuxEvdevKeyboardDriver = {
EvdevKbdBell,
EvdevKbdDisable,
EvdevKbdFini,
+ EvdevKbdCheck,
NULL,
};
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index 1db5348..c3c7b8d 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -1027,4 +1027,5 @@ KdPointerDriver LinuxMouseDriver = {
MouseDisable,
MouseFini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c
index b6151cd..bde8849 100644
--- a/hw/kdrive/linux/ms.c
+++ b/hw/kdrive/linux/ms.c
@@ -179,4 +179,5 @@ KdPointerDriver MsMouseDriver = {
MsDisable,
MsFini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index 552a3c7..9761593 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -183,4 +183,5 @@ KdPointerDriver Ps2MouseDriver = {
Ps2Disable,
Ps2Fini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 570cbf9..249756b 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -194,4 +194,5 @@ KdPointerDriver TsDriver = {
TslibDisable,
TslibFini,
NULL,
+ NULL,
};
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 3ca9814..2fadf7d 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -180,6 +180,7 @@ typedef struct _KdPointerDriver {
Status (*Enable) (KdPointerInfo *);
void (*Disable) (KdPointerInfo *);
void (*Fini) (KdPointerInfo *);
+ void (*Recheck) (KdPointerInfo *);
struct _KdPointerDriver *next;
} KdPointerDriver;
@@ -252,6 +253,7 @@ typedef struct _KdKeyboardDriver {
void (*Bell) (KdKeyboardInfo *, int, int, int);
void (*Disable) (KdKeyboardInfo *);
void (*Fini) (KdKeyboardInfo *);
+ void (*Recheck) (KdKeyboardInfo *);
struct _KdKeyboardDriver *next;
} KdKeyboardDriver;
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 80a1458..a886c1c 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -78,6 +78,7 @@ static KdPointerMatrix kdPointerMatrix = {
void KdResetInputMachine (void);
#define KD_MAX_INPUT_FDS 8
+#define KD_INPUT_CHECK_TIME_MILLIS 1000
typedef struct _kdInputFd {
int fd;
@@ -1287,6 +1288,24 @@ KdParsePointer (char *arg)
return pi;
}
+static CARD32 KdCheckInput(OsTimerPtr ign1, CARD32 ign2, pointer ign3)
+{
+ KdKeyboardInfo *kdev;
+ KdPointerInfo *pdev;
+
+
+ for (pdev = kdPointers; pdev; pdev = pdev->next) {
+ if (pdev->driver->Recheck)
+ pdev->driver->Recheck(pdev);
+ }
+
+ for (kdev = kdKeyboards; kdev; kdev = kdev->next) {
+ if (kdev->driver->Recheck)
+ kdev->driver->Recheck(kdev);
+ }
+
+ return KD_INPUT_CHECK_TIME_MILLIS;
+}
void
KdInitInput (void)
@@ -1297,6 +1316,8 @@ KdInitInput (void)
kdInputEnabled = TRUE;
+ TimerSet(NULL, 0, KD_INPUT_CHECK_TIME_MILLIS, KdCheckInput, NULL);
+
for (dev = kdConfigPointers; dev; dev = dev->next) {
pi = KdParsePointer(dev->line);
if (!pi)
--
1.7.1
More information about the xorg-devel
mailing list