[Urwid] How to detect that urwid lost focus ?

Ian Ward ian at excess.org
Sun Jun 19 18:12:57 EDT 2011


On 06/19/2011 04:55 PM, goffi wrote:
> G'day everybody,
>
> is there a way to detect that Urwid lost focus ? I mean when the user
> leave the term, not just changing the widget with focus.
>
> For my XMPP client, I'd like to know when the user is not on the term to
> show notifications when somebody is writing to him.
>
> My idea is to detect if we are on X, use Xlib to detect the focus
> windows, and look for the term name or my app name in the window title,
> but it seems a big hacky. Is there a more elegant way to do that ?

sure, if you're willing to rely on having a connection to an X server 
you can get all sorts of focus events.  Try running xev, you can see 
things like

  VisibilityNotify event, serial 34, synthetic NO, window 0x5600001,
      state VisibilityFullyObscured

Ian



More information about the Urwid mailing list