summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@theqtcompany.com>2016-03-23 10:25:17 +0100
committerOliver Wolff <oliver.wolff@theqtcompany.com>2016-04-08 05:57:22 +0000
commita064bcf883f4552af3c81756dceda7c53cb8b061 (patch)
tree16f3c1b4668cea36dcc2654a3cff33eac046288e /src/plugins
parentfe4fad790ed187bf1d8c5bf61066fe00823fbe7e (diff)
winrt: mimic desktop Window's "QKeyEvent::isAutoRepeat" behavior
We should mimic desktop Qt's behavior as close as possible. That means, that a key release event is triggered between auto generated press events for most keys. For some keys like modifiers, caps lock, scroll lock etc. there are no auto repeated events if the key is held down. The "last" release event after having held the key and several events are triggered does not have the isAutoRepeat flag set so we should not have that flag in this case either. Task-number: QTBUG-52055 Change-Id: I001a73416c4b2072d307ee5d87c7cb8406c9575f Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp
index e4f7709146..fbf6393d90 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.cpp
+++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp
@@ -416,6 +416,23 @@ static inline Qt::Key qKeyFromVirtual(VirtualKey key)
}
}
+// Some keys like modifiers, caps lock etc. should not be automatically repeated if the key is held down
+static inline bool shouldAutoRepeat(Qt::Key key)
+{
+ switch (key) {
+ case Qt::Key_Shift:
+ case Qt::Key_Control:
+ case Qt::Key_Alt:
+ case Qt::Key_Meta:
+ case Qt::Key_CapsLock:
+ case Qt::Key_NumLock:
+ case Qt::Key_ScrollLock:
+ return false;
+ default:
+ return true;
+ }
+}
+
static inline Qt::Key qKeyFromCode(quint32 code, int mods)
{
if (code >= 'a' && code <= 'z')
@@ -870,12 +887,33 @@ HRESULT QWinRTScreen::onKeyDown(ABI::Windows::UI::Core::ICoreWindow *, ABI::Wind
Q_ASSERT_SUCCEEDED(hr);
Qt::Key key = qKeyFromVirtual(virtualKey);
- // Defer character key presses to onCharacterReceived
- if (key == Qt::Key_unknown || (key >= Qt::Key_Space && key <= Qt::Key_ydiaeresis)) {
+
+ const bool wasPressed = d->activeKeys.contains(key);
+ if (wasPressed) {
+ if (!shouldAutoRepeat(key))
+ return S_OK;
+
+ // If the key was pressed before trigger a key release before the next key press
+ QWindowSystemInterface::handleExtendedKeyEvent(
+ topWindow(),
+ QEvent::KeyRelease,
+ key,
+ keyboardModifiers(),
+ !status.ScanCode ? -1 : status.ScanCode,
+ virtualKey,
+ 0,
+ QString(),
+ status.WasKeyDown,
+ !status.RepeatCount ? 1 : status.RepeatCount,
+ false);
+ } else {
d->activeKeys.insert(key, KeyInfo(virtualKey));
- return S_OK;
}
+ // Defer character key presses to onCharacterReceived
+ if (key == Qt::Key_unknown || (key >= Qt::Key_Space && key <= Qt::Key_ydiaeresis))
+ return S_OK;
+
QWindowSystemInterface::handleExtendedKeyEvent(
topWindow(),
QEvent::KeyPress,
@@ -912,7 +950,7 @@ HRESULT QWinRTScreen::onKeyUp(ABI::Windows::UI::Core::ICoreWindow *, ABI::Window
virtualKey,
0,
info.text,
- status.WasKeyDown,
+ false, // The final key release does not have autoRepeat set on Windows
!status.RepeatCount ? 1 : status.RepeatCount,
false);
return S_OK;