← KD100

Fix OSD window dragging not working

a0deb07f1ca6e0b069b7a168d72a39bbb70121dc · Claude · Feb 7, 2026 04:56

The USB read was blocking indefinitely (timeout=0), preventing the
main loop from calling osd_update to process X11 mouse events.

Changes:
- Changed libusb_interrupt_transfer timeout from 0 to 50ms
- Added XFlush after XMapWindow in osd_set_mode
- Timeout now continues loop instead of printing error message

The OSD window can now be dragged while waiting for KD100 button presses.

https://claude.ai/code/session_01H5sr8TkRyt6U1vdkVZRRvy

+7 −3 · 2 files changed

  • src/device.c +6 −3
  • src/osd.c +1 −0
diff --git a/src/device.c b/src/device.c
index a176a17..3f49b8c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -385,10 +385,13 @@ void device_run(libusb_context* ctx, config_t* config, int debug, int accept, in
                         }
                     }
 
-                    err = libusb_interrupt_transfer(handle, 0x81, data, sizeof(data), NULL, 0);
+                    // Use 50ms timeout to allow OSD event processing (dragging, etc.)
+                    err = libusb_interrupt_transfer(handle, 0x81, data, sizeof(data), NULL, 50);
 
-                    if (err == LIBUSB_ERROR_TIMEOUT)
-                        printf("\nTIMEDOUT\n");
+                    if (err == LIBUSB_ERROR_TIMEOUT) {
+                        // Normal timeout - just continue to process OSD events
+                        continue;
+                    }
                     if (err == LIBUSB_ERROR_PIPE)
                         printf("\nPIPE ERROR\n");
                     if (err == LIBUSB_ERROR_NO_DEVICE)
diff --git a/src/osd.c b/src/osd.c
index 298524b..b7afe16 100644
--- a/src/osd.c
+++ b/src/osd.c
@@ -301,6 +301,7 @@ void osd_set_mode(osd_state_t* osd, osd_mode_t mode) {
     XResizeWindow(dpy, win, osd->width, osd->height);
     XMapWindow(dpy, win);
     XRaiseWindow(dpy, win);
+    XFlush(dpy);
 
     osd_redraw(osd);
 }