it’s working
authorGuillaume Castagnino <casta@xwing.info>
Thu, 12 Mar 2020 22:01:24 +0000 (23:01 +0100)
committerGuillaume Castagnino <casta@xwing.info>
Thu, 12 Mar 2020 22:01:24 +0000 (23:01 +0100)
fookb.cpp
fookb.qml
xcbEventFilter.cpp
xcbEventFilter.h

index 3ba015c62eac143abfa495732181a30c9a56eeca..63ce9f0e499e7d5748b7ed68b506860d6ebdb984 100644 (file)
--- a/fookb.cpp
+++ b/fookb.cpp
@@ -12,9 +12,12 @@ int main(int argc, char *argv[])
     QQmlApplicationEngine engine;
     engine.load(QUrl(QStringLiteral("qrc:/fookb.qml")));
 
     QQmlApplicationEngine engine;
     engine.load(QUrl(QStringLiteral("qrc:/fookb.qml")));
 
+    /* Get the flag object */
+    QObject *rootObject = engine.rootObjects().first();
+
     /* Install event filter to handle mapping change */
     /* Install event filter to handle mapping change */
-    XcbEventFilter eventFilter;
-    app.installNativeEventFilter(&eventFilter);
+    XcbEventFilter *eventFilter = new XcbEventFilter(rootObject);
+    app.installNativeEventFilter(eventFilter);
 
     /* run application */
     return app.exec();
 
     /* run application */
     return app.exec();
index f6d7cb49022d9c8cf2d2bc00b3c910b4f0d689b2..4a0c0d73c1dedad08f6e8e696b4359321bd8407e 100644 (file)
--- a/fookb.qml
+++ b/fookb.qml
@@ -1,10 +1,17 @@
 import Qt.labs.platform 1.1
 
 SystemTrayIcon {
 import Qt.labs.platform 1.1
 
 SystemTrayIcon {
+    id: systray
+    objectName: "systray"
     visible: true
     visible: true
-    icon.source: "qrc:/images/fr.png"
+    /* initial mapping is ru */
+    property string lang: "ru"
+    icon.source: {
+        return "qrc:/images/" + lang + ".png"
+    }
 
     menu: Menu {
 
     menu: Menu {
+        visible: false
         MenuItem {
             text: qsTr("Quit")
             onTriggered: Qt.quit()
         MenuItem {
             text: qsTr("Quit")
             onTriggered: Qt.quit()
index f7289c16e11e67553b9efbe0d546fb4073d69ab4..3e3d8690fc66ac6912a3240c3340662bcbb53524 100644 (file)
@@ -7,8 +7,9 @@
 #include <xcb/xkb.h>
 #undef explicit
 
 #include <xcb/xkb.h>
 #undef explicit
 
-XcbEventFilter::XcbEventFilter()
+XcbEventFilter::XcbEventFilter(QObject *favicon)
 {
 {
+    m_favicon = favicon;
 }
 
 XcbEventFilter::~XcbEventFilter()
 }
 
 XcbEventFilter::~XcbEventFilter()
@@ -23,8 +24,19 @@ bool XcbEventFilter::nativeEventFilter(const QByteArray &eventType, void *messag
         //qDebug() << "XCB Event: " << xkb_event->any.response_type;
         if (xkb_event->xkbType == XCB_XKB_STATE_NOTIFY) {
             /* We get the event twice here. Not critical, but to investigate */
         //qDebug() << "XCB Event: " << xkb_event->any.response_type;
         if (xkb_event->xkbType == XCB_XKB_STATE_NOTIFY) {
             /* We get the event twice here. Not critical, but to investigate */
-            qDebug() << "XCB Mapping Event - group: " << xkb_event->group << " - eventType: " << xkb_event->eventType;
+            //qDebug() << "XCB Mapping Event - group: " << xkb_event->group << " - eventType: " << xkb_event->eventType;
             // TODO: update QML flag
             // TODO: update QML flag
+            //qDebug() << "current icon: " << m_favicon->property("lang");
+            switch (xkb_event->group)
+            {
+            case 1:
+                m_favicon->setProperty("lang", "fr");
+                break;
+            case 0:
+            default:
+                m_favicon->setProperty("lang", "ru");
+                break;
+            }
         }
     }
     return false;
         }
     }
     return false;
index 54b679f967081b75c3ab32ac2348401e3b6789e0..e755e313f5b30053bdea1bc84a3ee6c2b36d3eeb 100644 (file)
@@ -1,14 +1,17 @@
 #ifndef XCB_EVENT_FILTER_H
 #define XCB_EVENT_FILTER_H
 
 #ifndef XCB_EVENT_FILTER_H
 #define XCB_EVENT_FILTER_H
 
+#include <QObject>
 #include <QAbstractNativeEventFilter>
 
 class XcbEventFilter : public QAbstractNativeEventFilter
 {
 public:
 #include <QAbstractNativeEventFilter>
 
 class XcbEventFilter : public QAbstractNativeEventFilter
 {
 public:
-    XcbEventFilter();
+    XcbEventFilter(QObject *favicon);
     ~XcbEventFilter() override;
     bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override;
     ~XcbEventFilter() override;
     bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override;
+private:
+    QObject *m_favicon;
 };
 
 #endif // XCB_EVENT_FILTER_H
 };
 
 #endif // XCB_EVENT_FILTER_H