xlib 有活动窗口事件吗?
我正在尝试编写一个程序,使用 Xlib 跟踪活动窗口何时发生变化。我很难找出最好的方法来做到这一点。到目前为止,这些是我的想法:
- 每秒使用 _NET_ACTIVE_WINDOW 来获取活动窗口,如果它已更改,则运行该事件的相关代码。
- 获取所有窗口的列表并聆听它们在事件中的焦点。不过,我必须弄清楚如何保持打开窗口的最新列表。
他们是更简单/更好的方法吗?我是 Xlib 编程新手。
I am trying to write a program that tracks when the active window changes using Xlib. I am have trouble figuring out the best way to do this. These are my ideas so far:
- Every second use _NET_ACTIVE_WINDOW to get the active window and if it has changed then running the related code for the event.
- Get a list of all windows and listen to their focus in event. I would have to figure out how to keep an up to date list of open windows though.
Is their an easier/better way? I am new to programming with Xlib.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 @alanc 提议的 Python 实现。
我为某人编写的作为示例的更完整注释的版本位于此要点中。
Here's a Python implementation of what @alanc proposed.
The more fully-commented version I wrote as an example for someone is in this gist.
难道您不能只在根窗口上选择
PropertyChange
来在更新任何属性时发送PropertyNotify
事件,然后检查每个事件以查看它是否适用于_NET_ACTIVE_WINDOW ?
Can't you just select
PropertyChange
on the root window to get sentPropertyNotify
events when any property is updated and then check each event to see if it was for_NET_ACTIVE_WINDOW
?我也一直在寻找“活动窗口更改事件捕获器”。我同时使用的(可能对你有帮助)是 xdotool 和 xwininfo。
I've been looking for "active windows change event grabber" as well. What I use in mean time (and might be helpful for you) is combination of xdotool and xwininfo.