Преглед на файлове

Detection autorepeated keys manually on X11

On X11, isAutoRepeat() always returns false. This is a Qt bug, see:
https://bugreports.qt.io/browse/QTBUG-57335

There is a suggestion how to hack around this on SO:
http://stackoverflow.com/questions/38102221/qkeyevent-isautorepeat-not-working
but it requires linking to/having headers of yet another library, and
apparently doesn't fix the issue fully.

So add some lame manual detection to work this around. We simply ignore
KeyDown events until the next KeyUp event.
Vincent Lang преди 7 години
родител
ревизия
1db16c69d7
променени са 2 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 10 0
      src/ui/EventFilter.cpp
  2. 4 1
      src/ui/EventFilter.h

+ 10 - 0
src/ui/EventFilter.cpp

@@ -80,6 +80,16 @@ bool EventFilter::eventFilter(QObject* watched, QEvent* event)
     else
       keystatus = InputBase::KeyUp;
 
+    if (keystatus == InputBase::KeyDown)
+    {
+      // Swallow auto-repeated keys (isAutoRepeat doesn't always work - QTBUG-57335)
+      if (m_currentKeyDown)
+        return true;
+      m_currentKeyDown = true;
+    }
+    else
+      m_currentKeyDown = false;
+
     QKeyEvent* kevent = dynamic_cast<QKeyEvent*>(event);
     if (kevent)
     {

+ 4 - 1
src/ui/EventFilter.h

@@ -12,10 +12,13 @@ class EventFilter : public QObject
 {
   Q_OBJECT
 public:
-  explicit EventFilter(QObject* parent = nullptr) : QObject(parent) {}
+  explicit EventFilter(QObject* parent = nullptr) : QObject(parent), m_currentKeyDown(false) {}
 
 protected:
   bool eventFilter(QObject* watched, QEvent* event) override;
+
+private:
+  bool m_currentKeyDown;
 };
 
 #endif //PLEXMEDIAPLAYER_EVENTFILTER_H