Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating InputOnly window

Tags:

c++

xlib

I want to create "InputOnly" window which should be invisible and taking input, but when running code bellow, my InputOnly window does get any event. I want to have my focus on other window and still getting input. How can I achieve it?

#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;
}
like image 405
relaxxx Avatar asked Jan 23 '26 10:01

relaxxx


1 Answers

Try using XWindowEvent() instead of XNextEvent(). This will probably solve your issue, since you have more than one window.

like image 110
moongoal Avatar answered Jan 25 '26 13:01

moongoal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!