summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2012-03-22 17:39:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-26 08:41:37 +0200
commit37010812a273c98272ae5d960c46b3e909c3a36a (patch)
tree179b6dcfab4986d6525eb0efd76358137e3d00fd /src
parent595021e0f7a2bfed37750cc41d6c4564e69297c8 (diff)
Cocoa: send key events for modifier keys
Implement -flagsChanged: in QNSView so that we can calculate the necessary modifier key events to send. Change-Id: I3de89537d6e22b4a6d69ae646a71d9722dd9f82a Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index d249158db3..2b384a28ec 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -638,6 +638,43 @@ static QTouchDevice *touchDevice = 0;
[self handleKeyEvent:nsevent eventType:int(QEvent::KeyRelease)];
}
+- (void)flagsChanged:(NSEvent *)nsevent
+{
+ ulong timestamp = [nsevent timestamp] * 1000;
+ ulong modifiers = [nsevent modifierFlags];
+ Qt::KeyboardModifiers qmodifiers = [self convertKeyModifiers:modifiers];
+
+ // calculate the delta and remember the current modifiers for next time
+ static ulong m_lastKnownModifiers;
+ ulong lastKnownModifiers = m_lastKnownModifiers;
+ ulong delta = lastKnownModifiers ^ modifiers;
+ m_lastKnownModifiers = modifiers;
+
+ struct qt_mac_enum_mapper
+ {
+ ulong mac_mask;
+ Qt::Key qt_code;
+ };
+ static qt_mac_enum_mapper modifier_key_symbols[] = {
+ { NSShiftKeyMask, Qt::Key_Shift },
+ { NSControlKeyMask, Qt::Key_Meta },
+ { NSCommandKeyMask, Qt::Key_Control },
+ { NSAlternateKeyMask, Qt::Key_Alt },
+ { NSAlphaShiftKeyMask, Qt::Key_CapsLock },
+ { 0ul, Qt::Key_unknown } };
+ for (int i = 0; modifier_key_symbols[i].mac_mask != 0u; ++i) {
+ uint mac_mask = modifier_key_symbols[i].mac_mask;
+ if ((delta & mac_mask) == 0u)
+ continue;
+
+ QWindowSystemInterface::handleKeyEvent(m_window,
+ timestamp,
+ (lastKnownModifiers & mac_mask) ? QEvent::KeyRelease : QEvent::KeyPress,
+ modifier_key_symbols[i].qt_code,
+ qmodifiers);
+ }
+}
+
- (void) doCommandBySelector:(SEL)aSelector
{
[self tryToPerform:aSelector with:self];