Index: xf86-input-evdev/src/evdev_brain.c =================================================================== RCS file: /cvs/xorg/driver/xf86-input-evdev/src/evdev_brain.c,v retrieving revision 1.4 diff -u -r1.4 evdev_brain.c --- xf86-input-evdev/src/evdev_brain.c 16 Mar 2006 13:09:19 -0000 1.4 +++ xf86-input-evdev/src/evdev_brain.c 31 Mar 2006 02:42:36 -0000 @@ -37,6 +37,8 @@ #include "xf86_OSlib.h" #include "evdev.h" +#include "inotify.h" +#include "inotify-syscalls.h" #include #include @@ -292,8 +294,7 @@ } } - if (!found) - close (info.fd); + close (info.fd); } for (driver = evdev_drivers; driver; driver = driver->next) @@ -315,16 +316,18 @@ evdevReadInput (InputInfoPtr pInfo) { /* - * XXX: Freezing the server for a moment is not really friendly. - * But we need to wait until udev has actually created the device. + * Clear the inotify descriptor */ - usleep (500000); + char buf[512]; + read (pInfo->fd, buf, 512); evdevRescanDevices (pInfo); } static int evdevControl(DeviceIntPtr pPointer, int what) { + int wd; + InputInfoPtr pInfo; pInfo = pPointer->public.devicePrivate; @@ -335,17 +338,20 @@ break; case DEVICE_ON: - /* - * XXX: We do /proc/bus/usb/devices instead of /proc/bus/input/devices - * because the only hotplug input devices at the moment are USB... - * And because the latter is useless to poll/select against. - * FIXME: Get a patch in the kernel which fixes the latter. - */ - pInfo->fd = open ("/proc/bus/usb/devices", O_RDONLY); - if (pInfo->fd == -1) { - xf86Msg(X_ERROR, "%s: cannot open /proc/bus/usb/devices.\n", pInfo->name); - return BadRequest; - } + /* + * Use the kernel's inotify to detect changes in /dev/input + */ + pInfo->fd = inotify_init (); + if (pInfo->fd == -1) { + xf86Msg(X_ERROR, "%s: cannot initialize inotify.\n", pInfo->name); + return BadRequest; + } + wd = inotify_add_watch (pInfo->fd, "/dev/input/", IN_CREATE | IN_DELETE); + if (wd < 0) { + xf86Msg(X_ERROR, "%s: cannot initialize inotify watcher.\n", pInfo->name); + return BadRequest; + } + xf86FlushInput(pInfo->fd); AddEnabledDevice(pInfo->fd); pPointer->public.on = TRUE;