[xmonad] Patch: Use threadWaitRead to avoid blocking in nextEvent in the main loop

Adam Sampson ats at offog.org
Sat Jun 21 20:47:03 EDT 2008


I've been playing around with Control.Concurrent lately, and ran into a
problem with xmonad as it stands: it usually blocks inside XNextEvent()
in the main loop, so the Haskell runtime system never gets a chance to
run any other lightweight threads.

The attached patch uses threadWaitRead to tell the runtime system to
wait for the X file descriptor to become ready before calling
XNextEvent. This works for me: I've now got a couple of forkIO threads
happily updating my status bar periodically.

I'm not entirely convinced it's correct, though. Is it possible for the
X server to send more than one event in a single communication? If so,
it would be necessary to call nextEvent to handle the subsequent events
before the file descriptor becomes ready again (which'd be easy if
there's a way to find out whether there are any events pending without


Adam Sampson <ats at offog.org>                         <http://offog.org/>
-------------- next part --------------

New patches:

[Use threadWaitRead to avoid blocking in nextEvent in the main loop
Adam Sampson <ats at offog.org>**20080622002858
 This makes it possible to use lightweight threads (spawned using forkIO)
 in xmonad extensions; previously they wouldn't get a chance to run
 except when xmonad received an event.
] {
hunk ./XMonad/Main.hsc 25
+import Control.Concurrent
hunk ./XMonad/Main.hsc 140
-            forever_ $ handle =<< io (nextEvent dpy e >> getEvent e)
+            forever_ $ handle =<< io (do threadWaitRead (fromIntegral $ connectionNumber dpy)
+                                         nextEvent dpy e >> getEvent e)


[Raise windows in the floating layer when moving or resizing
Trevor Elliott <trevor at galois.com>**20080521215057] 
[add currentTag convenience function
Devin Mullins <me at twifkak.com>**20080511224258] 
[Make Mirror a newtype
Spencer Janssen <sjanssen at cse.unl.edu>**20080508104640] 
Spencer Janssen <sjanssen at cse.unl.edu>**20080507013122] 
[Break long line
Spencer Janssen <sjanssen at cse.unl.edu>**20080507012608] 
Spencer Janssen <sjanssen at cse.unl.edu>**20080507012519] 
Spencer Janssen <sjanssen at cse.unl.edu>**20080507011309] 
[Overhaul Choose, fixes issue 183
Spencer Janssen <sjanssen at cse.unl.edu>**20080506220809] 
[Remember if focus changes were caused by mouse actions or by key commands
Klaus Weidner <kweidner at pobox.com>**20080502175603
 If the user used the mouse to change window focus (moving into or clicking on a
 window), this should be handled differently than focus changes due to keyboard
 commands. Specifically, it's inappropriate to discard window enter/leave events
 while the mouse is moving. This fixes the bug where a fast mouse motion across
 multiple windows resulted in the wrong window keeping focus.
 It's also helpful information for contrib modules such as UpdatePointer - it's
 supposed to move the mouse pointer only in response to keyboard actions, not if
 the user was moving the mouse.
Spencer Janssen <sjanssen at cse.unl.edu>**20080506203840] 
[Added doShift function for more user-friendly hooks
Ivan N. Veselov <veselov at gmail.com>**20080506185757] 
[use named colours. fixes startup failure on the XO
Don Stewart <dons at galois.com>**20080502210149] 
[Set focus *after* revealing windows
Spencer Janssen <sjanssen at cse.unl.edu>**20080407222559] 
[Reveal windows after moving/resizing them.
Spencer Janssen <sjanssen at cse.unl.edu>**20080407220756
 This should reduce the number of repaints for newly visible windows.
[Hide newly created but non-visible windows (fixes bug #172)
Spencer Janssen <sjanssen at cse.unl.edu>**20080430014012] 
[formatting, eta expansion
Don Stewart <dons at galois.com>**20080418184337] 
[XMonad.ManageHook: add 'appName', another name for 'resource'
Lukas Mai <l.mai at web.de>**20080406012006] 
[XMonad.ManageHook: make 'title' locale-aware; haddock cleanup
Lukas Mai <l.mai at web.de>**20080406011338
 The code for 'title' was stolen from getname.patch (bug #44).
[XMonad.Main: call setlocale on startup
Lukas Mai <l.mai at web.de>**20080406011234] 
[floats always use current screen (with less bugs)
robreim at bobturf.org**20080405135009] 
[XMonad.Operations: applySizeHint reshuffle
Lukas Mai <l.mai at web.de>**20080404215615
 Make applySizeHints take window borders into account. Move old functionality
 to applySizeHintsContents. Add new mkAdjust function that generates a custom
 autohinter for a window.
[XMonad.Layout: documentation cleanup
Lukas Mai <l.mai at web.de>**20080404215444] 
[Remove gaps from the example config
Spencer Janssen <sjanssen at cse.unl.edu>**20080329232959] 
[Remove gaps
Spencer Janssen <sjanssen at cse.unl.edu>**20080325091526] 
[TAG 0.7
Spencer Janssen <sjanssen at cse.unl.edu>**20080329210249] 
Patch bundle hash:

More information about the xmonad mailing list