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;
}
Try using XWindowEvent() instead of XNextEvent(). This will probably solve your issue, since you have more than one window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With