Xlib - 忽略 XGrab* 中的修饰键
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有修饰符,掩码将为
0
。The mask would be
0
for no modifiers.