本文介绍了X11:XGrabPointer 会阻止其他应用程序发生任何鼠标事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码:

XGrabPointer(d, root, False, ButtonPressMask
      , GrabModeAsync, GrabModeAsync, None,
      None, CurrentTime);

我只是用按钮按下事件指定,但在运行其他应用程序时无法获得任何其他鼠标事件,例如鼠标移动.这是这个功能设计的吗?或者我理解错误的东西.像参数owner_events,看不懂.

I just specify with button press event, but when running other applications can't get any other mouse event such as mouse move.Is it what this function designed to be? or with something I made wrong understanding. like parameter owner_events, I can't understand well.

如果 owner_events 为 False,则所有生成的指针事件都将报告与grab_window 相关,并且仅当被 event_mask 选中时才报告.如果 owner_events 为 True 并且如果生成的指针事件通常会报告给此客户端,则照常报告.否则,事件是关于grab_window 报告的,并且只有在被event_mask 选择时才报告.对于 owner_events 的任一值,未报告的事件将被丢弃.

通过对owner_event的解释,看起来我需要注册两种事件类型:ButtonPressMask|PointerMotionMask 和 owner_events 是吗?但这也不起作用.

with explaination of owner_event, it looks like I need to register two event type: ButtonPressMask|PointerMotionMask and owner_events True? but that doesn't work either.

推荐答案

关键在你发布的描述的最后一句:

The key is in the last sentence of the description you posted:

对于 owner_events 的任一值,未报告的事件将被丢弃.

即owner_events 是 True 还是 False 无关紧要,未处理的事件将被丢弃.owner_events 的微妙之处在于将事件传递到哪个窗口: if owner_events == False all 与掩码匹配的指针事件被发送到抓取窗口,即使该事件在属于您的其他窗口中应用程序(X 语言中的客户端);坐标也是相对于抓取窗口的.如果 owner_events == True 事件会报告给您应用程序的任何窗口,但不会报告给其他应用程序.

I.e. it doesn't matter if owner_events is True or False, events that are not handled are discarded. The subtelty of owner_events is to which window the events are delivered: if owner_events == False all pointer events matching the mask are sent to the grabbing window, even if the event is in other windows that belong to you application (Client in X parlance); coordinates are relative to the grabbing window too. If owner_events == True events are reported to any window of your application, but not to other applications.

XGrabPointer 真的能抓取所有的指针事件,而且这个非常强大.它通常仅用于临时(临时)窗口,如弹出窗口、扩展下拉窗口等.原因是跟踪窗口外的点击,以便您可以关闭瞬态.我在颜色选择器弹出窗口中使用过:当用户单击选择颜色"按钮时会出现一个弹出窗口,我执行一个 XGrabPointer (..False..),所以我得到了所有的点击事件.如果用户在我的弹出窗口外单击,我会关闭窗口,就好像用户没有进行选择一样.如果没有 XGrabPointer,我不会知道发生了这种情况,并且弹出窗口将保持打开状态,直到用户单击它.当弹出窗口关闭时,XGrabPointer 会立即被移除.

XGrabPointer really grabs all pointer events, and this is very strong. It is normally only used for transient (temporary) windows like popups, expanding dropdown windows, etc. The reason is to keep track of clicks outside of the window so you can close the transient. I've used in a color selector popup: when the users clicks on the "choose color" button a popup appears, I do a XGrabPointer (..False..), so I get all click events. If a user clicks outside of my popup window I close the window as if the user did not make a selection. Without XGrabPointer I would not know this happened and the popup would remain open until the user clicked in it. The XGrabPointer is immediately removed when the popup closes.

这篇关于X11:XGrabPointer 会阻止其他应用程序发生任何鼠标事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:06