Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Plisson <damien.plisson@yahoo.fr>2009-12-01 13:23:27 +0300
committerDamien Plisson <damien.plisson@yahoo.fr>2009-12-01 13:23:27 +0300
commiteb24e788b82be4f957ca6a43c344173e80f27ff8 (patch)
tree2c0b142561b06401113e4b9aadf6f9c4b30befd6 /intern/ghost
parent99e765ee000503e6e917d52619d96a5ee557943e (diff)
Cocoa: implement Cmd+W to close window, workaround for wrong modifiers key status upon focus retrieval
The carbon GetModifierFlag function (to get the current modifier keys status) is reimplemented in cocoa only from 10.6. So we need to use a workaround to get the correct modifiers when blender application gets focus back. Current one is to assume no modifiers. This at least fixes the issue when blender has been hidden using Cmd+H. The Cmd modifier was still seen as ON until the user pressed again on it.
Diffstat (limited to 'intern/ghost')
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.mm36
1 files changed, 33 insertions, 3 deletions
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index 86203a49da7..eb2abd6cdd0 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -392,6 +392,8 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) {
#pragma mark Cocoa objects
+static bool justGotFocus = false;
+
/**
* CocoaAppDelegate
* ObjC object to capture applicationShouldTerminate, and send quit event
@@ -403,6 +405,7 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) {
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
- (void)applicationWillTerminate:(NSNotification *)aNotification;
+- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
@end
@implementation CocoaAppDelegate : NSObject
@@ -436,6 +439,11 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) {
/*G.afbreek = 0; //Let Cocoa perform the termination at the end
WM_exit(C);*/
}
+
+- (void)applicationWillBecomeActive:(NSNotification *)aNotification
+{
+ justGotFocus = true;
+}
@end
@@ -530,6 +538,9 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
+ menuItem = [windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
+ [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+
menuItem = [[NSMenuItem alloc] init];
[menuItem setSubmenu:windowMenu];
@@ -706,14 +717,33 @@ GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32
GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
{
- unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
- //Direct query to modifierFlags can be used in 10.6
+#ifdef MAC_OS_X_VERSION_10_6
+ unsigned int modifiers = [NSEvent 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);
-
+
+#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;
}