handle xcb/xkb
authorGuillaume Castagnino <guillaume.castagnino@rohde-schwarz.com>
Thu, 12 Mar 2020 14:42:36 +0000 (15:42 +0100)
committerGuillaume Castagnino <guillaume.castagnino@rohde-schwarz.com>
Thu, 12 Mar 2020 14:42:36 +0000 (15:42 +0100)
fookb.cpp
xcbEventFilter.cpp

index de93742b38c2bb3f6783e79f335b97de383b0f72..3ba015c62eac143abfa495732181a30c9a56eeca 100644 (file)
--- a/fookb.cpp
+++ b/fookb.cpp
@@ -6,14 +6,16 @@
 
 int main(int argc, char *argv[])
 {
+    /* create qapp and QML engine */
     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
     QApplication app(argc, argv);
     QQmlApplicationEngine engine;
     engine.load(QUrl(QStringLiteral("qrc:/fookb.qml")));
 
-    // Install event filter to handle mapping change
+    /* Install event filter to handle mapping change */
     XcbEventFilter eventFilter;
     app.installNativeEventFilter(&eventFilter);
 
+    /* run application */
     return app.exec();
 }
index b7e300b088194e5387174a67061ddee8da79a718..0141f77469f6b69ef77d32d59c9f43612778d722 100644 (file)
@@ -3,6 +3,9 @@
 #include <QDebug>
 
 #include <xcb/xcb.h>
+#define explicit dont_use_cxx_explicit
+#include <xcb/xkb.h>
+#undef explicit
 
 XcbEventFilter::XcbEventFilter()
 {
@@ -15,9 +18,17 @@ XcbEventFilter::~XcbEventFilter()
 bool XcbEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
 {
     if (eventType == "xcb_generic_event_t") {
-        xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message);
+        xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message);
+        uint response_type = event->response_type & ~0x80;
+
         qDebug() << "XCB Event";
-        // ...
+        /* We are only interested in XCB_XKB_STATE_NOTIFY */
+        if (response_type ==  XCB_XKB_STATE_NOTIFY)
+        {
+            xcb_xkb_state_notify_event_t *kbd_event = reinterpret_cast<xcb_xkb_state_notify_event_t *>(event);
+
+            qDebug() << "XCB Mapping Event - group: " << kbd_event->group;
+        }
     }
     return false;
 }