7 #include <X11/extensions/XInput2.h>
10 MultypoWindow::MultypoWindow(QWidget *parent) :
17 MultypoWindow::~MultypoWindow()
21 void MultypoWindow::showEvent ( QShowEvent * )
25 Display *dpy = x11Info().display();
27 /* XInput Extension available? */
29 if (!XQueryExtension(dpy, "XInputExtension", &xiOpcode, &eventID, &errorID)) {
30 qCritical() << "X Input extension not available";
33 /* Which version of XI2? We support 2.0 */
34 int major = 2, minor = 0;
35 if (XIQueryVersion(dpy, &major, &minor) == BadRequest) {
36 qCritical() << "XI2 not available. Server supports" << major << "." <<
40 qDebug() << "System is sane";
43 // Now let's listen to keypress events
44 XIEventMask eventmask;
45 unsigned char mask [1] = { 0 }; // will change
46 eventmask.deviceid = XIAllMasterDevices;
47 eventmask.mask_len = sizeof (mask); // in bytes, for whatever reason...
48 eventmask.mask = mask;
49 XISetMask(mask, XI_KeyPress);
50 XISelectEvents (dpy, winId(), &eventmask, 1);
56 setFocus(Qt::OtherFocusReason);*/
59 void MultypoWindow::handleKeyPress(int device, QString string)
61 qDebug() << "Device" << device << "String" << string;
64 bool MultypoWindow::handleX11Event(XEvent *event)
66 if (!xiInited) return false;
67 Display *dpy = x11Info().display();
69 if (event->xcookie.type == GenericEvent && event->xcookie.extension == xiOpcode
70 && event->xcookie.evtype == XI_KeyPress && XGetEventData(dpy, &event->xcookie)) {
72 XIDeviceEvent *d_ev = (XIDeviceEvent*) event->xcookie.data;
73 KeyCode keycode = d_ev->detail;
74 int kbdid = d_ev->deviceid;
76 if (!(d_ev->flags & XIKeyRepeat)) {
77 int keysyms_per_keycode;
78 KeySym keysym = XGetKeyboardMapping (dpy, keycode, 1, &keysyms_per_keycode)[0];
79 handleKeyPress(kbdid, XKeysymToString(keysym));
82 XFreeEventData(dpy, &event->xcookie);