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

Jack Bates m7iwhf at nottheoilrig.com
Sat Oct 15 18:16:37 UTC 2016


Thanks! Is there an event for _NET_ACTIVE_WINDOW, or should I continue 
to wait for FocusIn but then read _NET_ACTIVE_WINDOW?

On 15/10/16 09:46 AM, Ingo Bürk wrote:
> You're selecting FocusIn on the root window, but you won't really ever
> see it being triggered there. You'd need to select it on each top-level
> window and also keep track of new windows being mapped etc.
>
> If you have an at least somewhat EWMH compliant window manager I'd
> suggest you just watch _NET_ACTIVE_WINDOW on the root window instead.
>
> On 10/15/2016 05:25 PM, Jack Bates wrote:
>> 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