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

Ingo Bürk admin at airblader.de
Sat Oct 15 18:20:04 UTC 2016


You just select PropertyNotify. It tells you which property has updated in the event (for example xprop -root -spy _NET_ACTIVE_WINDOW). 

One small note: check the actual value of the property since a window manager may set it to None if no window has focus. 


Regards 
Ingo 

⁣​

On Oct 15, 2016, 20:16, at 20:16, Jack Bates <m7iwhf at nottheoilrig.com> wrote:
>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()
>_______________________________________________
>Xcb mailing list
>Xcb at lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/xcb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20161015/417d20e7/attachment.html>


More information about the Xcb mailing list