[Xcb] Get *new* active window after FocusInEvent?

Jack Bates m7iwhf at nottheoilrig.com
Sat Oct 15 15:25:14 UTC 2016


How do I get the *new* active window after a FocusInEvent?
The following is my attempt, but I get the *old* active window instead.
My goal is to automatically move the mouse to the new active window when 
I change active windows, say by pressing Alt-Tab or closing the old 
active window.

> #!/usr/bin/env python3
>
> import xcffib
> from xcffib.xproto import CW
> from xcffib.xproto import EventMask
> from xcffib.xproto import FocusInEvent
>
> conn = xcffib.connect()
>
> setup = conn.get_setup()
> for screen in setup.roots:
>   conn.core.ChangeWindowAttributes(
>     screen.root,
>     CW.EventMask,
>     [
>       EventMask.FocusChange,
>     ],
>   )
>
> conn.flush()
>
> while True:
>   event = conn.wait_for_event()
>   if isinstance(event, FocusInEvent):
>     reply = conn.core.GetInputFocus().reply()
>     conn.core.WarpPointer(
>       xcffib.XCB_NONE,
>       reply.focus,
>       xcffib.XCB_NONE,
>       xcffib.XCB_NONE,
>       xcffib.XCB_NONE,
>       xcffib.XCB_NONE,
>       0,
>       0,
>     )
>
>     conn.flush()


More information about the Xcb mailing list