Bug 506141 - Shortcut Key repeatedly triggers even when the key is pressed and released immediately (qt6, wayland)
Summary: Shortcut Key repeatedly triggers even when the key is pressed and released im...
Status: ASSIGNED
Alias: None
Product: krita
Classification: Applications
Component: Shortcuts and Canvas Input Settings (other bugs)
Version First Reported In: git master (please specify the git hash!)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Tiar
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-25 08:07 UTC by Ming Chuan
Modified: 2025-08-14 18:02 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ming Chuan 2025-06-25 08:07:16 UTC
SUMMARY

Sometimes when pressing certain shortcut keys (in my case, ctrl+v and ctrl+g), it's triggered twice (i.e. pasting twice, or create 2 layer of nested group).

According to the log (`QT_LOGGING_RULES="qt.gui* = true"`), it's caused by wayland auto repeat being triggered (`autorepeat, count=1`). Please refer to the log in ADDITIONAL INFORMATION below.

There are 2 potential issue here:
1. Does auto repeat ever make sense for action like "quick group" (ctrl+g) or "pasting a new layer" (ctrl+v)
2. For many shortcut keys like canvas mirroring, the auto repeat delay always work correctly for me (unsure how long is the delay, but it feels like at least 200ms). Maybe the bug only happens when the shortcut action is a relatively costly action which cause lag? Because of that, I think adjusting delay might not solve the problem https://doc.qt.io/qt-6/qwaylandkeyboard.html#setRepeatDelay 

Can't be 100% sure, but according to my personal experience I think this only happens when running krita in wayland natively.

STEPS TO REPRODUCE
1. Build krita with qt6 and run in wayland natively
2. Press ctrl+g on a paint layer to put it under a group. ("G" key is pressed and released immediately, less than about 100ms)
3. The paint layer sometimes will be grouped twice. (happens very frequently on my machine)

SOFTWARE/OS VERSIONS
Qt Version: 6.9
Krita master branch as of 2025-06-22

ADDITIONAL INFORMATION

With `QT_LOGGING_RULES="qt.gui* = true"` The following logs shows up when the bug happens

```
qt.gui.shortcutmap: Creating new sequences for QKeyEvent(ShortcutOverride, Key_G, ControlModifier, text="\u0007") with ignoredModifiers= QFlags<Qt::KeyboardModifier>(NoModifier)
qt.gui.shortcutmap: Possible input sequences: QList(QKeySequence("Ctrl+G"))
qt.gui.shortcutmap: Looking for shortcuts matching QKeySequence("Ctrl+G")
qt.gui.shortcutmap:  - QKeySequence::ExactMatch for shortcut QKeySequence("Ctrl+G")
qt.gui.shortcutmap:  - QKeySequence::NoMatch for shortcut QKeySequence("Ctrl+H")
qt.gui.shortcutmap: Found better match ( QList(QKeySequence("Ctrl+G")) ), clearing key sequence list
qt.gui.shortcutmap: Added ok key sequence QList(QKeySequence("Ctrl+G"))
qt.gui.shortcutmap: Returning shortcut match ==  QKeySequence::ExactMatch
qt.gui.shortcutmap: QShortcutMap::nextState(QKeyEvent(ShortcutOverride, Key_G, ControlModifier, text="\u0007")) = QKeySequence::ExactMatch
qt.gui.shortcutmap: QShortcutMap::dispatchEvent(): Sending QShortcutEvent(""Ctrl+G"", -67, false) to object(KisAction(0x1956e10, name = "create_quick_group"))
qt.gui.shortcutmap: Creating new sequences for QKeyEvent(ShortcutOverride, Key_G, ControlModifier, text="\u0007", autorepeat, count=1) with ignoredModifiers= QFlags<Qt::KeyboardModifier>(NoModifier)
qt.gui.shortcutmap: Possible input sequences: QList(QKeySequence("Ctrl+G"))
qt.gui.shortcutmap: Looking for shortcuts matching QKeySequence("Ctrl+G")
qt.gui.shortcutmap:  - QKeySequence::ExactMatch for shortcut QKeySequence("Ctrl+G")
qt.gui.shortcutmap:  - QKeySequence::NoMatch for shortcut QKeySequence("Ctrl+H")
qt.gui.shortcutmap: Found better match ( QList(QKeySequence("Ctrl+G")) ), clearing key sequence list
qt.gui.shortcutmap: Added ok key sequence QList(QKeySequence("Ctrl+G"))
qt.gui.shortcutmap: Returning shortcut match ==  QKeySequence::ExactMatch
qt.gui.shortcutmap: QShortcutMap::nextState(QKeyEvent(ShortcutOverride, Key_G, ControlModifier, text="\u0007", autorepeat,count=1)) = QKeySequence::ExactMatch
qt.gui.shortcutmap: QShortcutMap::dispatchEvent(): Sending QShortcutEvent(""Ctrl+G"", -67, false) to object(KisAction(0x1956e10, name = "create_quick_group"))
```
Comment 1 Ming Chuan 2025-06-27 19:11:16 UTC
I added logging to https://github.com/qt/qtwayland/blob/6.9.0/src/client/qwaylandinputdevice.cpp , together with `WAYLAND_DEBUG=1` to observe the timestamp of wayland event processing, here is what's happening

1. User press ctrl+g on their keyboard
2. Wayland compositor send `wl_keyboard` key press event to krita
3. krita enters a busy state (probably busy calculating new group layer thumbnail?), stops reading any new wayland event
4. User releases ctrl+g key on their keyboard
5. The key repeat timer in `QWaylandInputDevice::Keyboard::Keyboard` got fired while krita is busy, a key repeat event is generated
6. krita leaves busy state, starts reading wayland events again, receives key release event and cancel the key repeat timer, but it's too late as the repeat event has been passed to application code for handling
7. qt.gui.shortcutmap groups the layer twice

When I repro this, krita stayed in "busy state" for about 950ms
Comment 2 Tiar 2025-06-28 00:25:40 UTC
Askmeaboutloom suggested turning off autorepeat on the actions we don't want to repeat, so I'm going to try that.
Comment 3 Ming Chuan 2025-08-14 18:02:27 UTC
Filed a ticket to QT [[QTBUG-139201] Key repeat handling in Qt Wayland vulnerable to race conditions when Wayland event loop stalls - Qt Bug Tracker](https://bugreports.qt.io/browse/QTBUG-139201)