如何使用 Xlib 正确拦截和转发鼠标事件?
我正在开发一个简单的 Xlib 程序,我想在其中拦截所有鼠标事件(运动、按钮按下、按钮释放)。我可能想在某个时候对这些数据做一些事情,但现在,我只想将这些鼠标事件正确地“转发”到正确的窗口(就好像我根本没有拦截它们一样)。
目前,我的一般做法如下:
- 使用 XGrabPointer() 获取根窗口的指针
- 收到事件后,使用 XQueryPointer() 找到指针所在的子窗口
- 使用 XSendEvent() 将事件转发到子窗口
还有一些更多的细节,但这是基本的想法。我一直在 Ubuntu Linux 上测试我的程序,它似乎可以在很多情况下工作(例如,单击最小化、最大化和关闭按钮可以正常工作)。但是,它并不适用于所有场景,例如单击菜单栏项。
总之,我基本上只是希望能够拦截鼠标事件,然后将它们转发到适当的窗口,就像我根本没有拦截它们一样。使用 Xlib 执行此操作的正确方法是什么?
I'm working on a simple Xlib program where I want to intercept all mouse events (motion, button pressing, button releasing). I might want to do something with this data at some point, but right now, I just want to properly "forward" these mouse events to the proper windows (as if I wasn't intercepting them at all).
At the moment, my general approach is as follows:
- Grab the pointer for the root window with XGrabPointer()
- Upon receiving the event, find the child window the pointer is over with XQueryPointer()
- Forward the event to the child window with XSendEvent()
There are some more details, but that is the basic idea. I've been testing my program on Ubuntu Linux, and it seems to work in many scenarios (for instance, clicking on minimize, maximize, and close buttons works properly). However, it doesn't work in all scenarios, such as clicking on menu bar items.
In summary, I basically just want to be able to intercept mouse events and then forward them to the appropriate windows as if I hadn't intercepted them at all. What is the proper way to do this with Xlib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论