wild-bind-x11-0.2.0.6: X11-specific implementation for WildBind

MaintainerToshio Ito <debug.ito@gmail.com>
Safe HaskellNone
LanguageHaskell2010

WildBind.X11.Internal.NotificationDebouncer

Description

This is an internal module. End-users should not rely on it.

WildBind.X11 module receives some notification events to update the current state of the desktop (usually it is the active window). However, there are some problems in updating the state every time it receives a notification event.

  • Notification events can come too fast. It can make siginificant overhead to the system.
  • The active window obtained at the very moment a notification arrives is often unstable. It can become invalid soon. In addition, Xlib is notorious for being bad at handling that kind of exceptions (it just crashes the entire process and it's practically impossible to catch the exceptions).

Personally, I have experienced even weirder behaviors when I did some X11 operations at arrivals of notification events.

  • Sometimes I could not obtain the current active window. Instead, I ended up with getting the previous active window.
  • Sometimes GetWindowProperty blocked forever.

So, as a workaround, we debounce the raw notification events and generate a ClientMessage X11 event. When we get the ClientMessage, we update the state.

Synopsis

Documentation

withDebouncer :: Display -> (Debouncer -> IO a) -> IO a Source #

Create a Debouncer and run the specified action.

notify :: Debouncer -> IO () Source #

Notify the Debouncer that a notification event arrives. After a while, the Debouncer emits a ClientMessage X11 event.

xEventMask :: EventMask Source #

The Xlib EventMask for sending the ClientMessage. You have to select this mask by selectInput function to receive the ClientMessage.

isDebouncedEvent :: Debouncer -> XEventPtr -> IO Bool Source #

Check if the given event is the debounced ClientMessage X11 event.