diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-26 15:24:42 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-27 19:49:55 +0200 |
commit | f563203f60f2cb4d03650af3a357e988aa6bce32 (patch) | |
tree | c8f9711a3543287bf26a2155c1ad83df8f3d5fba /src/plugins/platforms/cocoa/qcocoahelpers.h | |
parent | 2945c6223bf067f240a020b2454d6bcac8fa961a (diff) |
macOS: Factor out key event handling into helper struct
This allows us to share code between handleKeyEvent: and flagsChanged:
for parsing the incoming NSEvent, and allows for sending key events
from other call sites in the future without duplicating the parsing
and sending logic.
Pick-to: 6.2
Change-Id: Ic63f740523496a9432e439663a20f78b5bc234c5
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.h')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index b6e3960121..0fa868c73f 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -371,6 +371,31 @@ InputMethodQueryResult queryInputMethod(QObject *object, Qt::InputMethodQueries // ------------------------------------------------------------------------- +struct KeyEvent +{ + ulong timestamp = 0; + QEvent::Type type = QEvent::None; + + Qt::Key key = Qt::Key_unknown; + Qt::KeyboardModifiers modifiers = Qt::NoModifier; + QString text; + bool isRepeat = false; + + // Scan codes are hardware dependent codes for each key. There is no way to get these + // from Carbon or Cocoa, so leave it 0, as documented in QKeyEvent::nativeScanCode(). + static const quint32 nativeScanCode = 0; + + quint32 nativeVirtualKey = 0; + NSEventModifierFlags nativeModifiers = 0; + + KeyEvent(NSEvent *nsevent); + bool sendWindowSystemEvent(QWindow *window) const; +}; + +QDebug operator<<(QDebug debug, const KeyEvent &e); + +// ------------------------------------------------------------------------- + QDebug operator<<(QDebug, const NSRange &); QDebug operator<<(QDebug, SEL); |