https://bugs.kde.org/show_bug.cgi?id=484525

Jed GIblin <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #14 from Jed GIblin <[email protected]> ---
I was able to create a small workaround to track the key that triggered the
last shortcut and to only send the shortcut release message if the released key
matches the shortcut key, not just send on any key release.

Obviously this has some flaws logically with tracking multi key shortcuts /
multiple shortcuts, but it does at least fix it in the context of discord PTT.

diff --git a/src/globalshortcutsregistry.cpp b/src/globalshortcutsregistry.cpp
index 4a02ede..1683d7c 100644
--- a/src/globalshortcutsregistry.cpp
+++ b/src/globalshortcutsregistry.cpp
@@ -521,9 +521,10 @@ bool GlobalShortcutsRegistry::keyEvent(int keyQt,
ShortcutKeyState state)
     }

     if (state == ShortcutKeyState::Released) {
-        if (m_lastShortcut) {
+        if (m_lastShortcut && (m_lastShortcutKey == 0 || key ==
m_lastShortcutKey)) {
            
m_lastShortcut->context()->component()->emitGlobalShortcutEvent(*m_lastShortcut,
state);
             m_lastShortcut = nullptr;
+           m_lastShortcutKey = 0;
         }
     }

@@ -617,6 +618,7 @@ bool GlobalShortcutsRegistry::processKey(int keyQt,
ShortcutKeyState state)
     // Invoke the action
     shortcut->context()->component()->emitGlobalShortcutEvent(*shortcut,
state);
     m_lastShortcut = shortcut;
+    m_lastShortcutKey = keyQt & ~Qt::KeyboardModifierMask;

     return true;
 }
@@ -967,6 +969,7 @@ bool GlobalShortcutsRegistry::unregisterKey(const
QKeySequence &key, GlobalShort
     if (shortcut && shortcut == m_lastShortcut) {
        
m_lastShortcut->context()->component()->emitGlobalShortcutEvent(*m_lastShortcut,
ShortcutKeyState::Released);
         m_lastShortcut = nullptr;
+       m_lastShortcutKey = 0;
     }

     _active_keys.remove(key, shortcut);
diff --git a/src/globalshortcutsregistry.h b/src/globalshortcutsregistry.h
index 71c1c53..ea627ef 100644
--- a/src/globalshortcutsregistry.h
+++ b/src/globalshortcutsregistry.h
@@ -257,6 +257,7 @@ private:

     QDBusObjectPath _dbusPath;
     GlobalShortcut *m_lastShortcut = nullptr;
+    int m_lastShortcutKey = 0;
     QTimer m_refreshServicesTimer;
     uint64_t m_serial = 0;
 };

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to