intercept events, but UI freeze globally
authorGuillaume Castagnino <casta@xwing.info>
Wed, 11 Mar 2020 21:35:04 +0000 (22:35 +0100)
committerGuillaume Castagnino <casta@xwing.info>
Wed, 11 Mar 2020 21:35:04 +0000 (22:35 +0100)
fookb.pro
xlib_wrapper.cpp

index e3554f06fa9a93b861e3378a8a29324442915dd7..61a6c887ee2fa3dc7909070206318f8365632afc 100644 (file)
--- a/fookb.pro
+++ b/fookb.pro
@@ -5,3 +5,4 @@ TARGET = fookb
 
 RESOURCES = fookb.qrc
 QT += widgets qml
+QMAKE_LFLAGS +=-lX11
index d940a158cd252b23e73208ad4277075290ec1a5c..6b29f3bafe4f1c38b065988e128fe4708580bf35 100644 (file)
@@ -1,16 +1,67 @@
 #include "xlib_wrapper.h"
+#include <QApplication>
 #include <QDebug>
 
+/* X Window headers */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+/* XKB fun */
+#include <X11/XKBlib.h>
+
 XlibWrapper::XlibWrapper()
 {
     timer = new QTimer(this);
     timer->setSingleShot(true);
     connect(timer, SIGNAL(timeout()),
-          this, SLOT(XlibWrapperSlot()));
+            this, SLOT(XlibWrapperSlot()));
     timer->start(1000);
 }
 
 void XlibWrapper::XlibWrapperSlot()
 {
+    int event_rtrn;
+    int error_rtrn;
+    int reason_rtrn;
+    Display *dpy;
+    XkbEvent labuda;
+
+    int state = 0;
+
     qDebug() << "Timer...";
+    dpy = XkbOpenDisplay(NULL,
+            &event_rtrn,
+            &error_rtrn, NULL, NULL, &reason_rtrn);
+    if (dpy == NULL) {
+        qDebug() << "Cannot open display";
+        qApp->quit();
+    }
+
+    /* We would like receive the only Xkb event: XkbStateNotify. And only
+     * when XkbLockGroup happens. */
+    if (False == XkbSelectEvents(dpy,
+                XkbUseCoreKbd,
+                XkbAllEventsMask,
+                0)) {
+        qDebug() << "Cannot XkbSelectEvents.";
+        qApp->quit();
+    }
+
+    if (False == XkbSelectEventDetails(dpy,
+                XkbUseCoreKbd,
+                XkbStateNotify,
+                XkbAllEventsMask,
+                XkbGroupLockMask)) {
+        qDebug() << "Cannot XkbSelectEventDetails.";
+        qApp->quit();
+    }
+
+    while (1) {
+        XNextEvent(dpy, &labuda.core);
+        state = labuda.state.group;
+        /* Should not be necessary, here works only with 2 keyboard dispositions */
+        if ((state < 0) || (state > 1))
+            state = 1;
+        qDebug() << "XNextEvent";
+        /* TODO: update flag depending on state */
+    }
 }