1From c0e035236696cd274f03ff15a7ca09d358aac9f1 Mon Sep 17 00:00:00 2001
2From: Dmitry Kazakov <dimula73@gmail.com>
3Date: Mon, 29 Jun 2020 23:41:13 +0300
4Subject: [PATCH] Don't eat ShortcutOverride events when there is a
5 partial-match
6
7Some applications (e.g. Krita) may have its own shortcuts system. That
8is, it should always get ShortcutOverride events, even when they are
9matched to something inside Qt.
10
11If the application (Krita) accepts the event, then all the partially
12matched shortcuts should reset.
13
14See this bug for more details:
15https://bugs.kde.org/show_bug.cgi?id=409613
16---
17 src/gui/kernel/qshortcutmap_p.h           |  4 +++-
18 src/gui/kernel/qwindowsysteminterface.cpp | 10 ++++++++--
19 2 files changed, 11 insertions(+), 3 deletions(-)
20
21diff --git a/src/gui/kernel/qshortcutmap_p.h b/src/gui/kernel/qshortcutmap_p.h
22index 8fc68229..91191288 100644
23--- a/src/gui/kernel/qshortcutmap_p.h
24+++ b/src/gui/kernel/qshortcutmap_p.h
25@@ -91,8 +91,10 @@ public:
26     void dumpMap() const;
27 #endif
28
29-private:
30     void resetState();
31+
32+private:
33+
34     QKeySequence::SequenceMatch nextState(QKeyEvent *e);
35     void dispatchEvent(QKeyEvent *e);
36
37diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
38index b3b6167c..9bb43f2a 100644
39--- a/src/gui/kernel/qwindowsysteminterface.cpp
40+++ b/src/gui/kernel/qwindowsysteminterface.cpp
41@@ -441,7 +441,8 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam
42         window = QGuiApplication::focusWindow();
43
44     QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
45-    if (shortcutMap.state() == QKeySequence::NoMatch) {
46+    if (shortcutMap.state() != QKeySequence::ExactMatch) {
47+
48         // Check if the shortcut is overridden by some object in the event delivery path (typically the focus object).
49         // If so, we should not look up the shortcut in the shortcut map, but instead deliver the event as a regular
50         // key event, so that the target that accepted the shortcut override event can handle it. Note that we only
51@@ -451,8 +452,13 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam
52             QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorepeat, count);
53
54         {
55-            if (QWindowSystemInterfacePrivate::handleWindowSystemEvent<SynchronousDelivery>(shortcutOverrideEvent))
56+            if (QWindowSystemInterfacePrivate::handleWindowSystemEvent<SynchronousDelivery>(shortcutOverrideEvent)) {
57+                if (shortcutMap.state() != QKeySequence::NoMatch) {
58+                    shortcutMap.resetState();
59+                }
60+
61                 return false;
62+            }
63         }
64     }
65
66--
672.20.1.windows.1
68
69