Ask Xlib for events before blocking on the display in x11graph.scm.
authorTaylor R Campbell <campbell@mumble.net>
Tue, 28 Aug 2012 04:26:04 +0000 (04:26 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Tue, 28 Aug 2012 04:26:04 +0000 (04:26 +0000)
Fixes race whereby Xlib may have queued up events already before we
ask the OS about I/O on the underlying file descriptor.  This can
cause us to fail to notice an event until a second one comes along,
so that, e.g., a newly created window will hang until you move the
mouse over it or similar.

src/runtime/x11graph.scm

index f273c898d0afb4dcce082b2e55c51cb0f52d55be..fd879179cbf71862da205890cd907fdc56d62778 100644 (file)
@@ -314,12 +314,13 @@ USA.
 
 (define (%read-and-process-event display)
   (let ((event
-        (and (eq? 'READ
-                  (test-for-io-on-descriptor
-                   (x-display-descriptor (x-display/xd display))
-                   #t
-                   'READ))
-             (x-display-process-events (x-display/xd display) 1))))
+        (or (x-display-process-events (x-display/xd display) 2)
+            (and (eq? 'READ
+                      (test-for-io-on-descriptor
+                       (x-display-descriptor (x-display/xd display))
+                       #t
+                       'READ))
+                 (x-display-process-events (x-display/xd display) 1)))))
     (if event
        (process-event display event))))