diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-09-14 18:44:09 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-10-06 11:20:49 +0200 |
commit | 57d6f842eadcfe59337e223237ef024de3b0e433 (patch) | |
tree | 8dbdd5aea838064dda67974e5ab5713e37857951 /src/gui | |
parent | 7aac974c78d488c1af39bb40feb5779c878dc4bf (diff) |
Un-special-case macOS in handling of QKeyEvent::nativeScanCode()
In the porting from Qt 4 to Qt 5 an assumption was made in QKeyMapper
that the underlying platform implementation needed the native scan
code to be able to resolve the possible keymaps for an event.
As a result, the macOS platform plugin started sending key events
with a fake native scan code of 1, so that it would still be allowed
to map key events.
Which in turn led to the documentation of QKeyEvent::nativeScanCode()
getting an exception for macOS.
Let's clean up this by removing the original assumption, and leave it
up to the platforms to decide what information from the key event
is needed.
QKeyMapperPrivate::possibleKeys() will still call extractKeyFromEvent
as a fallback if the platform layer doesn't return any possible keys.
Change-Id: I122a45bcec658c45ccc0b2c0671eb264d85d7be6
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper.cpp | 3 | ||||
-rw-r--r-- | src/gui/platform/unix/qxkbcommon.cpp | 3 |
3 files changed, 3 insertions, 7 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 087873d67e..38906df6cb 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1663,10 +1663,6 @@ QKeyEvent::~QKeyEvent() Note: The native scan code may be 0, even if the key event contains extended information. - - Note: On \macos, this function is not useful, because there is no - way to get the scan code from the system APIs. The function always - returns 1 (or 0 in the case explained above). */ /*! diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp index 89eacc944a..19b0e15279 100644 --- a/src/gui/kernel/qkeymapper.cpp +++ b/src/gui/kernel/qkeymapper.cpp @@ -83,9 +83,6 @@ static QList<int> extractKeyFromEvent(QKeyEvent *e) QList<int> QKeyMapper::possibleKeys(QKeyEvent *e) { - if (!e->nativeScanCode()) - return extractKeyFromEvent(e); - return instance()->d_func()->possibleKeys(e); } diff --git a/src/gui/platform/unix/qxkbcommon.cpp b/src/gui/platform/unix/qxkbcommon.cpp index 71f1cfd24a..02b5ab5164 100644 --- a/src/gui/platform/unix/qxkbcommon.cpp +++ b/src/gui/platform/unix/qxkbcommon.cpp @@ -621,6 +621,9 @@ QList<int> QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event, { QList<int> result; quint32 keycode = event->nativeScanCode(); + if (!keycode) + return result; + Qt::KeyboardModifiers modifiers = event->modifiers(); xkb_keymap *keymap = xkb_state_get_keymap(state); // turn off the modifier bits which doesn't participate in shortcuts |