-
- info = XListInputDevices(display, &num_devices);
-
- for(loop=0; loop<num_devices; loop++) {
- print_info(info+loop, shortformat);
- }
+ XEvent ev;
+
+#if HAVE_XI2
+ if (daemon)
+ {
+ XiSelectEvent(display, DefaultRootWindow(display), NULL,
+ XI_DeviceHierarchyChangedMask |
+ XI_DeviceClassesChangedMask);
+ }
+#endif
+
+ do {
+ info = XListInputDevices(display, &num_devices);
+ for(loop=0; loop<num_devices; loop++) {
+ print_info(info+loop, shortformat);
+ }
+
+#if HAVE_XI2
+ /* just wait for the next generic event to come along */
+ while (daemon && !XNextEvent(display, &ev))
+ {
+ if (ev.type == GenericEvent)
+ {
+ XGenericEvent* gev = (XGenericEvent*)&ev;
+ /* we just assume that extension is IReqCode, pretty save
+ since we don't register for other events. */
+ if (gev->evtype == XI_DeviceHierarchyChangedNotify)
+ {
+ printf("Hierarchy change.\n");
+ } else if (gev->evtype == XI_DeviceClassesChangedNotify)
+ {
+ printf("Device classes changed.\n");
+ free(((XDeviceClassesChangedEvent*)&ev)->inputclassinfo);
+ }
+ break;
+ }
+ }
+#endif
+ } while(daemon);