diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2011-02-27 07:32:50 +0300 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2011-02-27 07:32:50 +0300 |
commit | 2cd986337d28f5faf86f6d77152adf28ba242974 (patch) | |
tree | 4834166beb85e95468cc9f91c7efbe280a4ffacb /src/mumble | |
parent | 4774dab0bf186539d8a874d913ae5f66d900999c (diff) |
Work around broken XI2 master devices
Diffstat (limited to 'src/mumble')
-rw-r--r-- | src/mumble/GlobalShortcut_unix.cpp | 39 | ||||
-rw-r--r-- | src/mumble/GlobalShortcut_unix.h | 6 |
2 files changed, 37 insertions, 8 deletions
diff --git a/src/mumble/GlobalShortcut_unix.cpp b/src/mumble/GlobalShortcut_unix.cpp index e40f5d9f8..36f5f3ff0 100644 --- a/src/mumble/GlobalShortcut_unix.cpp +++ b/src/mumble/GlobalShortcut_unix.cpp @@ -39,8 +39,6 @@ GlobalShortcutX::GlobalShortcutX() { display = NULL; - iKeyPress = iKeyRelease = iButtonPress = iButtonRelease = -1; - #ifdef Q_OS_LINUX QString dir = QLatin1String("/dev/input"); QFileSystemWatcher *fsw = new QFileSystemWatcher(QStringList(dir), this); @@ -78,6 +76,8 @@ GlobalShortcutX::GlobalShortcutX() { if (rc != BadRequest) { qWarning("GlobalShortcutX: Using XI2 %d.%d", major, minor); + queryXIMasterList(); + XIEventMask evmask; unsigned char mask[(XI_LASTEVENT + 7)/8]; @@ -88,8 +88,9 @@ GlobalShortcutX::GlobalShortcutX() { XISetMask(mask, XI_RawButtonRelease); XISetMask(mask, XI_RawKeyPress); XISetMask(mask, XI_RawKeyRelease); + XISetMask(mask, XI_HierarchyChanged); - evmask.deviceid = XIAllMasterDevices; + evmask.deviceid = XIAllDevices; evmask.mask_len = sizeof(mask); evmask.mask = mask; @@ -160,6 +161,29 @@ void GlobalShortcutX::run() { } } +// Find XI2 master devices so they can be ignored. +void GlobalShortcutX::queryXIMasterList() { + XIDeviceInfo *info, *dev; + int ndevices; + + qsMasterDevices.clear(); + + dev = info = XIQueryDevice(display, XIAllDevices, &ndevices); + for(int i=0;i<ndevices;++i) { + switch (dev->use) { + case XIMasterPointer: + case XIMasterKeyboard: + qsMasterDevices.insert(dev->deviceid); + break; + default: + break; + } + + ++dev; + } + XIFreeDeviceInfo(info); +} + // XInput2 event is ready on socketnotifier. void GlobalShortcutX::displayReadyRead(int) { XEvent evt; @@ -175,15 +199,20 @@ void GlobalShortcutX::displayReadyRead(int) { continue; XIDeviceEvent *xide = reinterpret_cast<XIDeviceEvent *>(cookie->data); + switch(cookie->evtype) { case XI_RawKeyPress: case XI_RawKeyRelease: - handleButton(xide->detail, cookie->evtype == XI_RawKeyPress); + if (! qsMasterDevices.contains(xide->deviceid)) + handleButton(xide->detail, cookie->evtype == XI_RawKeyPress); break; case XI_RawButtonPress: case XI_RawButtonRelease: - handleButton(xide->detail + 0x117, cookie->evtype == XI_RawButtonPress); + if (! qsMasterDevices.contains(xide->deviceid)) + handleButton(xide->detail + 0x117, cookie->evtype == XI_RawButtonPress); break; + case XI_HierarchyChanged: + queryXIMasterList(); } XFreeEventData(display, cookie); diff --git a/src/mumble/GlobalShortcut_unix.h b/src/mumble/GlobalShortcut_unix.h index 014567978..c902ea6a2 100644 --- a/src/mumble/GlobalShortcut_unix.h +++ b/src/mumble/GlobalShortcut_unix.h @@ -52,6 +52,8 @@ class GlobalShortcutX : public GlobalShortcutEngine { Display *display; QSet<Window> qsRootWindows; int iXIopcode; + QSet<int> qsMasterDevices; + volatile bool bRunning; QSet<QString> qsKeyboards; QMap<QString, QFile *> qmInputDevices; @@ -61,9 +63,7 @@ class GlobalShortcutX : public GlobalShortcutEngine { void run(); QString buttonName(const QVariant &); - int iKeyPress, iKeyRelease, iButtonPress, iButtonRelease; - - void initXInput(Display *); + void queryXIMasterList(); public slots: void displayReadyRead(int); void inputReadyRead(int); |