【问题标题】:Creating InputOnly window创建 InputOnly 窗口
【发布时间】:2012-01-31 10:14:16
【问题描述】:

我想创建“InputOnly”窗口,它应该是不可见的并接受输入,但是当运行下面的代码时,我的 InputOnly 窗口确实会收到任何事件。 我想让我的注意力集中在其他窗口上并且仍然得到输入。我怎样才能实现它?

#include <X11/Xlib.h>
#include <iostream>

int main(void) {
    Display *dsp;
    Window root;
    Window windows[2];
    XEvent ev; 
    int i = 0;

    dsp = XOpenDisplay(NULL);
    root = RootWindow(dsp, DefaultScreen(dsp));

    windows[i] = XCreateSimpleWindow(
        dsp,
        root,
        0, 0, 200, 200,
        1,
        BlackPixel(dsp, DefaultScreen(dsp)),
        WhitePixel(dsp, DefaultScreen(dsp))
    );
    XSelectInput(dsp, windows[i], 0);
    XMapWindow(dsp, windows[i]);

    ++i;

    XSetWindowAttributes at;
    at.event_mask = KeyPressMask;
    windows[i] = XCreateWindow(
        dsp,
        root,
        10,10,200,200,
        0,
        CopyFromParent,
        InputOnly,
        0,
        0,
        &at
    );
    XSelectInput(dsp, windows[i], KeyPressMask);
    //XMapWindow(dsp, windows[i]);

    while(1) {
        XNextEvent(dsp, &ev);
        std::cout << "foo" << std::endl;
    }   
    return 0;
}

【问题讨论】:

    标签: c++ xlib


    【解决方案1】:

    尝试使用XWindowEvent() 而不是XNextEvent()。这可能会解决您的问题,因为您有多个窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2011-09-03
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多