X11:如何真正抓住鼠标指针? [英] X11: How do I REALLY grab the mouse pointer?

查看:278
本文介绍了X11:如何真正抓住鼠标指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Xlib中实现了水平拆分器小部件.我正在尝试在用户单击&时抓住鼠标.在分割条上拖动(以便用户可以动态移动分割&从而调整分割条两侧的窗口大小).

I've implemented a horizontal splitter widget in Xlib. I'm trying to grab the mouse when the user clicks & drags on the splitter bar (so that the user can dynamically move the split & thus resize the windows on either side of the splitter bar).

我在收到鼠标左键后使用了XGrabPointer(),希望以后所有的鼠标移动(拖动)都将被转移到拆分器窗口,直到释放左键.

I've used XGrabPointer() after receiving a left click, in hopes that all future mouse motion (dragging) will be diverted to the splitter window until the left button is released.

不幸的是,它似乎无法正常工作.如果用户拖动速度太快,并且鼠标指针进入了拆分两侧的任一窗口,则MotionEvent消息将被转移到该(子)窗口,而不是拆分器窗口.

Unfortuntately, it doesn't seem to work like that. If the user drags too quickly and the mouse pointer enters one of the windows on either side of the split, the MotionEvent messages are diverted to that (child) window rather than the splitter window.

我做错了什么?我的XGrabPointer()调用如下:

What have I done wrong? My XGrabPointer() call is as follows:

::XGrabPointer(mDisplay, window, True,
               ButtonPressMask |
                 ButtonReleaseMask |
                 PointerMotionMask |
                 FocusChangeMask |
                 EnterWindowMask |
                  LeaveWindowMask,
               GrabModeAsync,
               GrabModeAsync,
               RootWindow(mDisplay, DefaultScreen(mDisplay)),
               None,
               CurrentTime);

推荐答案

我几乎很难接受这一点,但是答案却很简单,就像将第三个参数(owner_events)从True更改为False一样.

I'm almost embarrassed to admit this, but the answer turned out to be as simple as changing that third parameter (owner_events) from True to False.

tronche.com上的Xlib教程/参考:

如果owner_events为False,则所有有关生成的指针事件都将报告到handle_window,并且仅在被event_mask选择时才报告.如果owner_events为True,并且如果通常将生成的指针事件报告给此客户端,则照常报告该事件.否则,将针对grab_window报告该事件,并且仅在由event_mask选择时才报告该事件.

If owner_events is False, all generated pointer events are reported with respect to grab_window and are reported only if selected by event_mask. If owner_events is True and if a generated pointer event would normally be reported to this client, it is reported as usual. Otherwise, the event is reported with respect to the grab_window and is reported only if selected by event_mask.

我仍然不确定我是否完全理解True案例的行为,但是我的解释是,如果True,则将禁止其他X程序(即,由其他进程创建的窗口)接收XEvent,但是那些会击中您的过程创建的任何窗口都照常交付.在错误的情况下,将针对您选择的特定窗口报告所有事件.这就是我的行为.

I'm still not sure I completely understand the behavior of the True case, but my interpretation is that if True, other X programs (that is, windows created by other processes) are barred from receiving XEvents, but those that would hit any window created by your process are delivered as normal. In the false case, all events are reported with respect to the specific window you have selected. This was the behavior I was after.

这篇关于X11:如何真正抓住鼠标指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆