Xlib - 忽略 XGrab* 中的修饰键

发布于 2024-10-22 02:51:31 字数 1249 浏览 3 评论 0原文

Holla,

我目前正在对 TinyWM 进行一些更改 - 我想实施的一个更改是点击聚焦策略。

我发现我需要在孩子上运行 XGrabButton ,因为它是在 MapNotify 事件中创建的,但我无法弄清楚要使用哪个修饰符掩码来忽略所有修饰符掩码(意思是,我希望无论如何修饰键被激活时都会发生焦点单击)。

我遇到了困难,因为当我没有按下修饰键时,即使 AnyModifier 似乎也不起作用(即使这样,它也相当挑剔)。

这是相关的代码块:

void eMapNotify(Display *dpy, XEvent *ev){
     // Ignore windows we don't care about
     if (!ev.xmap.override_redirect) XSetWindowBorderWidth(dpy, ev.xmap.window, 3);

     // Allows us to hook into this window's clicks to let us focus it
     XGrabButton(dpy, 1, WHAT_MASK_DO_I_PUT_HERE, ev.xmap.window,
                 True, ButtonPressMask, GrabModeAsync, GrabModeAsync, 
                 None, None);
}

有什么想法吗?


编辑:

我发现事实上事件处理程序确实记录了点击,但是点击没有转发到子窗口,这正是我想要的行为。

更新

我目前已经使用以下代码实现了聚焦功能,该代码跟踪指针并将其聚焦在任何位置。在我的机器上,它并不像看起来那么贵:

Window dump, child;
int rx, ry, cx, cy;
unsigned int mask;
// Get the pointer's location
XQueryPointer(dpy, root, &dump, &child, &rx, &ry, &cx, &cy, &mask);
// Focuses the pointer's current window
XSetInputFocus(dpy, dump, RevertToNone, CurrentTime); 

Holla,

I'm currently hacking out some changes to TinyWM - one I'd like to implement is a click-to-focus policy.

I've figured out that I need to run an XGrabButton on the child as it is created in an MapNotify event, but I cannot figure out what modifier mask to use which ignores all modifier masks (meaning, I would like the focus click to happen no matter what modifier keys are activated).

I've hit a brick wall, as even AnyModifier seems not to work when I have no modifier keys pressed (and even then, it is rather picky).

Here's the relevant chunk of code:

void eMapNotify(Display *dpy, XEvent *ev){
     // Ignore windows we don't care about
     if (!ev.xmap.override_redirect) XSetWindowBorderWidth(dpy, ev.xmap.window, 3);

     // Allows us to hook into this window's clicks to let us focus it
     XGrabButton(dpy, 1, WHAT_MASK_DO_I_PUT_HERE, ev.xmap.window,
                 True, ButtonPressMask, GrabModeAsync, GrabModeAsync, 
                 None, None);
}

Any ideas?


EDIT:

I've found out that in fact the event handler does record the click, but the click is not forwarded to the child window, which is precisely the behavior I want.

UPDATE

I've currently implemented focusing functionality with the following code, which tracks the pointer and focuses it wherever it is. On my machine, it's not nearly as expensive as it may look:

Window dump, child;
int rx, ry, cx, cy;
unsigned int mask;
// Get the pointer's location
XQueryPointer(dpy, root, &dump, &child, &rx, &ry, &cx, &cy, &mask);
// Focuses the pointer's current window
XSetInputFocus(dpy, dump, RevertToNone, CurrentTime); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2024-10-29 02:51:31

如果没有修饰符,掩码将为 0

The mask would be 0 for no modifiers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文