小编Eth*_*anS的帖子

在 Xlib 中捕获按钮事件,然后将事件传递给客户端

我正在开发一个窗口管理器,主要是作为练习,我遇到了一个问题。我希望能够将单击的窗口提升到堆栈的顶部。目前,我在 Button1 和 ControlMask 上使用 XGrabButton 来允许移动窗口,当我 Ctrl+单击窗口时,达到了预期的效果。但是,如果我在Button1 上使用XGrabButton 和AnyModifier,虽然达到了我想要的效果,但我无法再通过鼠标按钮与客户端窗口进行交互(突出显示文本等)。我曾尝试在 EnterNotify 上抓取按钮,然后在窗口升起时立即取消抓取按钮,但这似乎没有任何效果,窗口管理器的行为就好像我从未抓取过按钮一样。

我的程序还比较小,所以代码如下:

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "window_manager.h"


ewm_instance wm;

void 
ewm_init()
{
    wm._display = XOpenDisplay(NULL);

    if (!wm._display) {
        printf("Could not open display %s\n", XDisplayName(NULL));
    } 
    wm._root = DefaultRootWindow(wm._display);
}

void
ewm_run()
{
    XSelectInput(wm._display, 
                 wm._root, 
                 SubstructureRedirectMask | SubstructureNotifyMask | 
                 KeyPressMask | KeyReleaseMask | 
                 ButtonPressMask | ButtonReleaseMask);

    XSync(wm._display, 0);
    XGrabServer(wm._display);
    Window returned_root, returned_parent;
    Window *top_level_windows;
    unsigned int num_top_level_windows;
    XQueryTree(wm._display,
               wm._root,
               &returned_root,
               &returned_parent,
               &top_level_windows,
               &num_top_level_windows); …
Run Code Online (Sandbox Code Playgroud)

c x11 xlib xorg

7
推荐指数
1
解决办法
1261
查看次数

标签 统计

c ×1

x11 ×1

xlib ×1

xorg ×1