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

Ingo Bürk admin at airblader.de
Sat Oct 15 16:46:50 UTC 2016


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.


Regards

Ingo


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()
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/xcb



More information about the Xcb mailing list