Warning, /graphics/krita/3rdparty/ext_qt/0001-win-Fix-unbalanced-KeyPress-Release-events-when-usin.patch is written in an unsupported language. File is not indexed.

0001 From 5034b2c0ca273a75d8dc819c2fb43aecd08fbc56 Mon Sep 17 00:00:00 2001
0002 From: Dmitry Kazakov <dimula73@gmail.com>
0003 Date: Wed, 25 May 2022 16:46:08 +0300
0004 Subject: [PATCH] [win] Fix unbalanced KeyPress/Release events when using
0005  non-latin layout
0006 
0007 When the key is released with a different set of modifiers, we should
0008 notify application about the release of the old key, not the new one.
0009 E.g. for '2' vs '@' keys.
0010 
0011 https://bugs.kde.org/show_bug.cgi?id=454256
0012 ---
0013  .../platforms/windows/qwindowskeymapper.cpp   | 25 ++++++++++++++-----
0014  1 file changed, 19 insertions(+), 6 deletions(-)
0015 
0016 diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp
0017 index 68074ad6..fc14dd7e 100644
0018 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp
0019 +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp
0020 @@ -130,13 +130,14 @@ enum { scancodeBitmask = 0x1ff };
0021  
0022  // Key recorder ------------------------------------------------------------------------[ start ] --
0023  struct KeyRecord {
0024 -    KeyRecord(int c, int a, int s, const QString &t) : code(c), ascii(a), state(s), text(t) {}
0025 +    KeyRecord(int c, int a, int s, const QString &t, int sc) : code(c), ascii(a), state(s), text(t), sentCode(sc) {}
0026      KeyRecord() {}
0027  
0028      int code;
0029      int ascii;
0030      int state;
0031      QString text;
0032 +    int sentCode;
0033  };
0034  
0035  // We need to record the pressed keys in order to decide, whether the key event is an autorepeat
0036 @@ -145,7 +146,7 @@ static const int QT_MAX_KEY_RECORDINGS = 64; // User has LOTS of fingers...
0037  struct KeyRecorder
0038  {
0039      inline KeyRecord *findKey(int code, bool remove);
0040 -    inline void storeKey(int code, int ascii, int state, const QString& text);
0041 +    inline void storeKey(int code, int ascii, int state, const QString& text, int sentCode);
0042      inline void clearKeys();
0043  
0044      int nrecs = 0;
0045 @@ -183,7 +184,7 @@ KeyRecord *KeyRecorder::findKey(int code, bool remove)
0046      return result;
0047  }
0048  
0049 -void KeyRecorder::storeKey(int code, int ascii, int state, const QString& text)
0050 +void KeyRecorder::storeKey(int code, int ascii, int state, const QString& text, int sentCode)
0051  {
0052      Q_ASSERT_X(nrecs != QT_MAX_KEY_RECORDINGS,
0053                 "Internal KeyRecorder",
0054 @@ -193,7 +194,7 @@ void KeyRecorder::storeKey(int code, int ascii, int state, const QString& text)
0055          qWarning("Qt: Internal keyboard buffer overflow");
0056          return;
0057      }
0058 -    records[nrecs++] = KeyRecord(code,ascii,state,text);
0059 +    records[nrecs++] = KeyRecord(code,ascii,state,text,sentCode);
0060  }
0061  
0062  void KeyRecorder::clearKeys()
0063 @@ -1162,6 +1163,13 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
0064          // (Consumed by modal widget is one possibility) So, remove the record from the list
0065          // This will stop the auto-repeat of the key, should a modifier change, for example
0066          if (rec && rec->state != state) {
0067 +
0068 +            const QString text = rec->text;
0069 +            const Qt::KeyboardModifiers modifiers(state);
0070 +
0071 +            QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyRelease, rec->sentCode,
0072 +                                                           modifiers, scancode, quint32(msg.wParam), nModifiers, text, false);
0073 +
0074              key_recorder.findKey(int(msg.wParam), true);
0075              rec = nullptr;
0076          }
0077 @@ -1285,7 +1293,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
0078                  return false;
0079              }
0080  #endif // !QT_NO_SHORTCUT
0081 -            key_recorder.storeKey(int(msg.wParam), a, state, text);
0082 +            key_recorder.storeKey(int(msg.wParam), a, state, text, code);
0083  
0084              // QTBUG-71210
0085              // VK_PACKET specifies multiple characters. The system only sends the first
0086 @@ -1328,8 +1336,13 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
0087                        || code == Qt::Key_Alt)) {
0088              // Someone ate the key down event
0089          } else {
0090 -            if (!code)
0091 +            if (rec && rec->state != state) {
0092 +                // if the state of modifiers has changed, make sure that
0093 +                // the original key code is delivered
0094 +                code = rec->sentCode;
0095 +            } else if (!code) {
0096                  code = asciiToKeycode(rec->ascii ? char(rec->ascii) : char(msg.wParam), state);
0097 +            }
0098  
0099              // Map SHIFT + Tab to SHIFT + BackTab, QShortcutMap knows about this translation
0100              if (code == Qt::Key_Tab && (state & Qt::ShiftModifier) == Qt::ShiftModifier)
0101 -- 
0102 2.23.0.windows.1
0103