2 #include "ui_multikbd.h"
8 #include <X11/extensions/XInput2.h>
11 MultiKBD::MultiKBD(QWidget *parent) :
24 void MultiKBD::showEvent ( QShowEvent * )
28 Display *dpy = x11Info().display();
30 /* XInput Extension available? */
32 if (!XQueryExtension(dpy, "XInputExtension", &xiOpcode, &eventID, &errorID)) {
33 qCritical() << "X Input extension not available";
36 /* Which version of XI2? We support 2.0 */
37 int major = 2, minor = 0;
38 if (XIQueryVersion(dpy, &major, &minor) == BadRequest) {
39 qCritical() << "XI2 not available. Server supports" << major << "." <<
43 qDebug() << "System is sane";
46 // Now let's listen to keypress events
47 XIEventMask eventmask;
48 unsigned char mask [1] = { 0 }; // will change
49 eventmask.deviceid = XIAllMasterDevices;
50 eventmask.mask_len = sizeof (mask); // in bytes, for whatever reason...
51 eventmask.mask = mask;
52 XISetMask(mask, XI_KeyPress);
53 XISelectEvents (dpy, winId(), &eventmask, 1);
59 setFocus(Qt::OtherFocusReason);*/
62 void MultiKBD::handleKeyPress(int device, const char *string)
64 qDebug() << "Device" << device << "String" << string;
67 bool MultiKBD::handleX11Event(XEvent *event)
69 if (!xiInited) return false;
70 Display *dpy = x11Info().display();
72 if (event->xcookie.type == GenericEvent && event->xcookie.extension == xiOpcode
73 && event->xcookie.evtype == XI_KeyPress && XGetEventData(dpy, &event->xcookie)) {
75 XIDeviceEvent *d_ev = (XIDeviceEvent*) event->xcookie.data;
76 KeyCode keycode = d_ev->detail;
77 int kbdid = d_ev->deviceid;
79 if (!(d_ev->flags & XIKeyRepeat)) {
80 int keysyms_per_keycode;
81 KeySym keysym = XGetKeyboardMapping (dpy, keycode, 1, &keysyms_per_keycode)[0];
82 handleKeyPress(kbdid, XKeysymToString(keysym));
85 XFreeEventData(dpy, &event->xcookie);