소스 검색

ui: workaround double key events with multimedia keys on Windows

Without doubt an awful hack. If I interpret the situation right, this
must have existed since Qt 5.4, and I have no idea how nobody using Qt
did not notice this.

Refs https://github.com/plexinc/plex-media-player-private/issues/666
Vincent Lang 7 년 전
부모
커밋
bfc6fdc729
1개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 1
      src/ui/EventFilter.cpp

+ 14 - 1
src/ui/EventFilter.cpp

@@ -18,6 +18,8 @@ static QStringList desktopWhiteListedKeys = { "Media Play",
                                               "Media Previous",
                                               "Media Rewind",
                                               "Media FastForward" };
+// These just happen to be mostly the same.
+static QStringList win32AppcommandBlackListedKeys = desktopWhiteListedKeys;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 static QString keyEventToKeyString(QKeyEvent *kevent)
@@ -115,6 +117,17 @@ bool EventFilter::eventFilter(QObject* watched, QEvent* event)
     if (!kevent)
       return QObject::eventFilter(watched, event);
 
+    QString keyName = keyEventToKeyString(kevent);
+
+#ifdef Q_OS_WIN32
+    // On Windows, we get some media keys twice. This is because Windows supports both
+    // normal key events and APPCOMMAND_ messages for media keys. To avoid getting two
+    // key events per key press, filter out non-APPCOMMAND media keys by using the fact
+    // that APPCOMMAND media keys won't have a key code.
+    if (win32AppcommandBlackListedKeys.contains(keyName) && kevent->nativeVirtualKey())
+      return QObject::eventFilter(watched, event);
+#endif
+
     if (keystatus == InputBase::KeyDown)
     {
       // Swallow auto-repeated keys (isAutoRepeat doesn't always work - QTBUG-57335)
@@ -133,7 +146,7 @@ bool EventFilter::eventFilter(QObject* watched, QEvent* event)
     system.setCursorVisibility(false);
     if (kevent->spontaneous() && !kevent->isAutoRepeat())
     {
-      InputKeyboard::Get().keyPress(keyEventToKeyString(kevent), keystatus);
+      InputKeyboard::Get().keyPress(keyName, keystatus);
       return true;
     }
   }