From 37010812a273c98272ae5d960c46b3e909c3a36a Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 22 Mar 2012 17:39:30 +0100 Subject: Cocoa: send key events for modifier keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/platforms/cocoa/qnsview.mm | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/plugins/platforms') 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]; -- cgit v1.2.3