Browse Source

it’s working

master
Guillaume Castagnino 2 years ago
parent
commit
8d5dba1665
  1. 7
      fookb.cpp
  2. 9
      fookb.qml
  3. 16
      xcbEventFilter.cpp
  4. 5
      xcbEventFilter.h

7
fookb.cpp

@ -12,9 +12,12 @@ int main(int argc, char *argv[])
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 */
XcbEventFilter eventFilter;
app.installNativeEventFilter(&eventFilter);
XcbEventFilter *eventFilter = new XcbEventFilter(rootObject);
app.installNativeEventFilter(eventFilter);
/* run application */
return app.exec();

9
fookb.qml

@ -1,10 +1,17 @@
import Qt.labs.platform 1.1
SystemTrayIcon {
id: systray
objectName: "systray"
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 {
visible: false
MenuItem {
text: qsTr("Quit")
onTriggered: Qt.quit()

16
xcbEventFilter.cpp

@ -7,8 +7,9 @@
#include <xcb/xkb.h>
#undef explicit
XcbEventFilter::XcbEventFilter()
XcbEventFilter::XcbEventFilter(QObject *favicon)
{
m_favicon = favicon;
}
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 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
//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;

5
xcbEventFilter.h

@ -1,14 +1,17 @@
#ifndef XCB_EVENT_FILTER_H
#define XCB_EVENT_FILTER_H
#include <QObject>
#include <QAbstractNativeEventFilter>
class XcbEventFilter : public QAbstractNativeEventFilter
{
public:
XcbEventFilter();
XcbEventFilter(QObject *favicon);
~XcbEventFilter() override;
bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override;
private:
QObject *m_favicon;
};
#endif // XCB_EVENT_FILTER_H

Loading…
Cancel
Save