forked from bartvdbraak/blender
Cocoa: proper implementation of the modifiers key wrong value when application becomes active again
Note: this works fine when running under 10.6, even if compiled with an older sdk Under 10.4/10.5, workaround remains to assume no modifier key is pressed when the user restores the focus to the application
This commit is contained in:
parent
6372c63ae9
commit
d7877d360a
@ -200,6 +200,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
|
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the Cocoa event telling the application has become active (again)
|
||||||
|
* @return Indication whether the event was handled.
|
||||||
|
*/
|
||||||
|
GHOST_TSuccess handleApplicationBecomeActiveEvent();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
|
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
|
||||||
|
@ -392,8 +392,6 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) {
|
|||||||
|
|
||||||
#pragma mark Cocoa objects
|
#pragma mark Cocoa objects
|
||||||
|
|
||||||
static bool justGotFocus = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CocoaAppDelegate
|
* CocoaAppDelegate
|
||||||
* ObjC object to capture applicationShouldTerminate, and send quit event
|
* ObjC object to capture applicationShouldTerminate, and send quit event
|
||||||
@ -442,7 +440,7 @@ static bool justGotFocus = false;
|
|||||||
|
|
||||||
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
||||||
{
|
{
|
||||||
justGotFocus = true;
|
systemCocoa->handleApplicationBecomeActiveEvent();
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -717,33 +715,11 @@ GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32
|
|||||||
|
|
||||||
GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
|
GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
|
||||||
{
|
{
|
||||||
#ifdef MAC_OS_X_VERSION_10_6
|
keys.set(GHOST_kModifierKeyCommand, (m_modifierMask & NSCommandKeyMask) ? true : false);
|
||||||
unsigned int modifiers = [NSEvent modifierFlags];
|
keys.set(GHOST_kModifierKeyLeftAlt, (m_modifierMask & NSAlternateKeyMask) ? true : false);
|
||||||
|
keys.set(GHOST_kModifierKeyLeftShift, (m_modifierMask & NSShiftKeyMask) ? true : false);
|
||||||
keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
|
keys.set(GHOST_kModifierKeyLeftControl, (m_modifierMask & NSControlKeyMask) ? true : false);
|
||||||
keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
|
|
||||||
|
|
||||||
#else
|
|
||||||
if (justGotFocus) {
|
|
||||||
//TODO: need to find a better workaround for the missing cocoa "getModifierFlag" function in 10.4/10.5
|
|
||||||
justGotFocus = false;
|
|
||||||
keys.set(GHOST_kModifierKeyCommand, false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftAlt, false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftShift, false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftControl, false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
|
|
||||||
|
|
||||||
keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
|
|
||||||
keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return GHOST_kSuccess;
|
return GHOST_kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,6 +849,45 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
|
|||||||
return anyProcessed || m_outsideLoopEventProcessed;
|
return anyProcessed || m_outsideLoopEventProcessed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Note: called from NSApplication delegate
|
||||||
|
GHOST_TSuccess GHOST_SystemCocoa::handleApplicationBecomeActiveEvent()
|
||||||
|
{
|
||||||
|
//Update the modifiers key mask, as its status may have changed when the application was not active
|
||||||
|
//(that is when update events are sent to another application)
|
||||||
|
unsigned int modifiers;
|
||||||
|
GHOST_IWindow* window = m_windowManager->getActiveWindow();
|
||||||
|
|
||||||
|
#ifdef MAC_OS_X_VERSION_10_6
|
||||||
|
modifiers = [NSEvent modifierFlags];
|
||||||
|
#else
|
||||||
|
//If build against an older SDK, check if running on 10.6 to use the correct function
|
||||||
|
if ([NSEvent respondsToSelector:@selector(modifierFlags)]) {
|
||||||
|
modifiers = (unsigned int)[NSEvent modifierFlags];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//TODO: need to find a better workaround for the missing cocoa "getModifierFlag" function in 10.4/10.5
|
||||||
|
modifiers = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {
|
||||||
|
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );
|
||||||
|
}
|
||||||
|
if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {
|
||||||
|
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );
|
||||||
|
}
|
||||||
|
if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {
|
||||||
|
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );
|
||||||
|
}
|
||||||
|
if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {
|
||||||
|
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_modifierMask = modifiers;
|
||||||
|
|
||||||
|
return GHOST_kSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
//Note: called from NSWindow delegate
|
//Note: called from NSWindow delegate
|
||||||
GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)
|
GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user