Hi,
a little bit late. But maybe it helps somebody else:
Have a look at project dwm at suckless dot org. See method void setup(int argc, char **argv) in dwm.c how to initialize a XLib Display and set the XEvent mask. Be sure to use the same Display for your QApplication. Use the constructor with the Display parameter, if you want to attach to a running X client:
public:
MyApplication
(Display
* dpy, int
& argc,
char** argv
): QApplication(dpy, argc, argv
) {} bool x11EventFilter(XEvent *e);
};
class MyApplication: public QApplication {
public:
MyApplication(Display* dpy, int& argc, char** argv): QApplication(dpy, argc, argv) {}
bool x11EventFilter(XEvent *e);
};
To copy to clipboard, switch view to plain text mode
What I tried is to attach a QApplication to dwm and replaced the main event loop of dwm by the qt event loop. My implementation of x11EventFilter delivers XEvents back to dwms event handlers.
Or you try this which I also tested successfully:
Use method
Display * QX11Info::display () [static]
after intantiation of your ruApplication and then set/modify the event mask.
Example:
main.cpp:
#include <QApplication>
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
public:
MyApplication
(int
& argc,
char** argv
): QApplication(argc, argv
) {} bool x11EventFilter(XEvent *e);
};
bool MyApplication::x11EventFilter(XEvent *e) {
qDebug("x11Event Filter called");
return false;
}
int main(int argc, char *argv[])
{
MyApplication a(argc, argv);
XSetWindowAttributes wa;
wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
wa.event_mask = ButtonPressMask;
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask);
return a.exec();
}
#include <QApplication>
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
class MyApplication: public QApplication {
public:
MyApplication(int& argc, char** argv): QApplication(argc, argv) {}
bool x11EventFilter(XEvent *e);
};
bool MyApplication::x11EventFilter(XEvent *e) {
qDebug("x11Event Filter called");
return false;
}
int main(int argc, char *argv[])
{
MyApplication a(argc, argv);
Display* dpy = QX11Info::display();
XSetWindowAttributes wa;
wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
wa.event_mask = ButtonPressMask;
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
qttest.pro:
QT += core gui
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/X11R6/lib -lX11
QT += core gui
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/X11R6/lib -lX11
To copy to clipboard, switch view to plain text mode
Start in a separate X Server:
xinit ./qttest -- :1
Bookmarks