Discussion:
[Xcb] Get *new* active window after FocusInEvent?
Jack Bates
2016-10-15 15:25:14 UTC
Permalink
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()
conn.core.ChangeWindowAttributes(
screen.root,
CW.EventMask,
[
EventMask.FocusChange,
],
)
conn.flush()
event = conn.wait_for_event()
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()
Ingo Bürk
2016-10-15 16:46:50 UTC
Permalink
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
Post by Jack Bates
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()
conn.core.ChangeWindowAttributes(
screen.root,
CW.EventMask,
[
EventMask.FocusChange,
],
)
conn.flush()
event = conn.wait_for_event()
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
https://lists.freedesktop.org/mailman/listinfo/xcb
Jack Bates
2016-10-15 18:16:37 UTC
Permalink
Thanks! Is there an event for _NET_ACTIVE_WINDOW, or should I continue
to wait for FocusIn but then read _NET_ACTIVE_WINDOW?
Post by Ingo Bürk
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.
Post by Jack Bates
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()
conn.core.ChangeWindowAttributes(
screen.root,
CW.EventMask,
[
EventMask.FocusChange,
],
)
conn.flush()
event = conn.wait_for_event()
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()
Ingo Bürk
2016-10-15 18:20:04 UTC
Permalink
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

⁣​
Post by Jack Bates
Thanks! Is there an event for _NET_ACTIVE_WINDOW, or should I continue
to wait for FocusIn but then read _NET_ACTIVE_WINDOW?
Post by Ingo Bürk
You're selecting FocusIn on the root window, but you won't really
ever
Post by Ingo Bürk
see it being triggered there. You'd need to select it on each
top-level
Post by Ingo Bürk
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.
Post by Jack Bates
How do I get the *new* active window after a FocusInEvent?
The following is my attempt, but I get the *old* active window
instead.
Post by Ingo Bürk
Post by Jack Bates
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()
conn.core.ChangeWindowAttributes(
screen.root,
CW.EventMask,
[
EventMask.FocusChange,
],
)
conn.flush()
event = conn.wait_for_event()
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
https://lists.freedesktop.org/mailman/listinfo/xcb
Loading...