2012-01-31 95 views
2

我想要创建“InputOnly”窗口,该窗口应该是不可见的并且需要输入,但是当运行代码时,我的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; 
} 

回答

1

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