Browse Source

EventFilter: improve autorepeat heuristic

I found that a simple Ctrl+Shift+F requires hitting F twice, because the
first time it's supressed, because the code thinks keys are already held
down. That's true, but we really should exclude modifier-only keys.
Vincent Lang 8 years ago
parent
commit
00c744b207
1 changed files with 16 additions and 11 deletions
  1. 16 11
      src/ui/EventFilter.cpp

+ 16 - 11
src/ui/EventFilter.cpp

@@ -111,25 +111,30 @@ bool EventFilter::eventFilter(QObject* watched, QEvent* event)
     else
       keystatus = InputBase::KeyUp;
 
+    QKeyEvent* kevent = dynamic_cast<QKeyEvent*>(event);
+    if (!kevent)
+      return QObject::eventFilter(watched, event);
+
     if (keystatus == InputBase::KeyDown)
     {
       // Swallow auto-repeated keys (isAutoRepeat doesn't always work - QTBUG-57335)
-      if (m_currentKeyDown)
-        return true;
-      m_currentKeyDown = true;
+      // Do this only for non-modifier keys (QKeyEvent::text serves as a heuristic
+      // to distinguish them from normal key presses)
+      if (kevent->text().size())
+      {
+        if (m_currentKeyDown)
+          return true;
+        m_currentKeyDown = true;
+      }
     }
     else
       m_currentKeyDown = false;
 
-    QKeyEvent* kevent = dynamic_cast<QKeyEvent*>(event);
-    if (kevent)
+    system.setCursorVisibility(false);
+    if (kevent->spontaneous() && !kevent->isAutoRepeat())
     {
-      system.setCursorVisibility(false);
-      if (kevent->spontaneous() && !kevent->isAutoRepeat())
-      {
-        InputKeyboard::Get().keyPress(keyEventToKeyString(kevent), keystatus);
-        return true;
-      }
+      InputKeyboard::Get().keyPress(keyEventToKeyString(kevent), keystatus);
+      return true;
     }
   }
   else if (event->type() == QEvent::MouseMove)