diff options
author | culler <culler> | 2017-11-25 05:38:40 (GMT) |
---|---|---|
committer | culler <culler> | 2017-11-25 05:38:40 (GMT) |
commit | f9c9a4fdced6feae7223d9187fddc4003338fd87 (patch) | |
tree | 94b8477858ab44c719ff91fb24d083ed10dab76b /macosx | |
parent | b3b49a0076376394282c87005ae71ea8bfda6b78 (diff) | |
parent | 697ee9344178923ec3f086602a3a21916ee61f1b (diff) | |
download | tk-f9c9a4fdced6feae7223d9187fddc4003338fd87.zip tk-f9c9a4fdced6feae7223d9187fddc4003338fd87.tar.gz tk-f9c9a4fdced6feae7223d9187fddc4003338fd87.tar.bz2 |
merge bug-88f02fa81a into core-8-6-branch.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXInit.c | 210 | ||||
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 10 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 5 |
3 files changed, 98 insertions, 127 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 2bed5d1..5c8c0b7 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -7,6 +7,7 @@ * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2017 Marc Culler * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -110,28 +111,82 @@ static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFSt #endif } -- (void) _setupEventLoop +-(void)applicationWillFinishLaunching:(NSNotification *)aNotification { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [self finishLaunching]; - [self setWindowsNeedUpdate:YES]; - [pool drain]; + + /* + * Initialize notifications. + */ +#ifdef TK_MAC_DEBUG_NOTIFICATIONS + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_postedNotification:) name:nil object:nil]; +#endif + [self _setupWindowNotifications]; + [self _setupApplicationNotifications]; + + /* + * Construct the menu bar. + */ + _defaultMainMenu = nil; + [self _setupMenus]; + + /* + * Set the application icon. This is unnecessary when running Wish.app + * but it is easier than testing for that situation to just do it. + */ + NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"]; + if (path) { + NSImage *image = [[NSImage alloc] initWithContentsOfFile:path]; + if (image) { + [NSApp setApplicationIconImage:image]; + [image release]; + } + } + + /* + * Initialize event processing. + */ + TkMacOSXInitAppleEvents(_eventInterp); + + /* + * Initialize the graphics context. + */ + TkMacOSXUseAntialiasedText(_eventInterp, -1); + TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0); +} + +-(void)applicationDidFinishLaunching:(NSNotification *)notification +{ + /* + * It is not safe to force activation of the NSApp until this + * method is called. Activating too early can cause the menu + * bar to be unresponsive. + */ + [NSApp activateIgnoringOtherApps: YES]; } - (void) _setup: (Tcl_Interp *) interp { + /* + * Remember our interpreter. + */ _eventInterp = interp; + + /* + * Install the global autoreleasePool. + */ _mainPool = [NSAutoreleasePool new]; [NSApp setPoolLock:0]; - _defaultMainMenu = nil; - [self _setupMenus]; + + /* + * Be our own delegate. + */ [self setDelegate:self]; -#ifdef TK_MAC_DEBUG_NOTIFICATIONS - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_postedNotification:) name:nil object:nil]; -#endif - [self _setupWindowNotifications]; - [self _setupApplicationNotifications]; + + /* + * Make sure we are allowed to open windows. + */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; } - (NSString *) tkFrameworkImagePath: (NSString *) image @@ -181,38 +236,6 @@ static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFSt /* *---------------------------------------------------------------------- * - * DoWindowActivate -- - * - * Idle handler that sets the application icon to the generic Tk icon. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static void -SetApplicationIcon( - ClientData clientData) -{ - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"]; - if (path) { - NSImage *image = [[NSImage alloc] initWithContentsOfFile:path]; - if (image) { - [NSApp setApplicationIconImage:image]; - [image release]; - } - } - [pool drain]; -} - -/* - *---------------------------------------------------------------------- - * * TkpInit -- * * Performs Mac-specific interpreter initialization related to the @@ -284,85 +307,7 @@ TkpInit( TkMacOSXDbgMsg("Tcl_MacOSXOpenVersionedBundleResources failed"); } #endif - - { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [[NSUserDefaults standardUserDefaults] registerDefaults: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:YES], - @"_NSCanWrapButtonTitles", - [NSNumber numberWithInt:-1], - @"NSStringDrawingTypesetterBehavior", - nil]]; - [TKApplication sharedApplication]; - [pool drain]; - [NSApp _setup:interp]; - } - - /* Check whether we are a bundled executable: */ - bundleRef = CFBundleGetMainBundle(); - if (bundleRef) { - bundleUrl = CFBundleCopyBundleURL(bundleRef); - } - if (bundleUrl) { - /* - * A bundled executable is two levels down from its main bundle - * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas an - * unbundled executable's main bundle directory is just the - * directory containing the executable. So to check whether we are - * bundled, we delete the last three path components of the - * executable's url and compare the resulting url with the main - * bundle url. - */ - - int j = 3; - CFURLRef url = CFBundleCopyExecutableURL(bundleRef); - - while (url && j--) { - CFURLRef parent = - CFURLCreateCopyDeletingLastPathComponent(NULL, url); - - CFRelease(url); - url = parent; - } - if (url) { - bundledExecutable = CFEqual(bundleUrl, url); - CFRelease(url); - } - CFRelease(bundleUrl); - } - - if (!bundledExecutable) { - /* - * If we are loaded into an executable that is not a bundled - * application, the window server does not let us come to the - * foreground. For such an executable, notify the window server - * that we are now a full GUI application. - */ - - OSStatus err = procNotFound; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - - err = ChkErr(TransformProcessType, &psn, - kProcessTransformToForegroundApplication); - - /* - * Set application icon to generic Tk icon, do it at idle time - * instead of now to ensure tk_library is setup. - */ - - Tcl_DoWhenIdle(SetApplicationIcon, NULL); - } - - { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [NSApp _setupEventLoop]; - TkMacOSXInitAppleEvents(interp); - TkMacOSXUseAntialiasedText(interp, -1); - TkMacOSXInitCGDrawing(interp, TRUE, 0); - [pool drain]; - } - + /* * FIXME: Close stdin & stdout for remote debugging otherwise we will * fight with gdb for stdin & stdout @@ -405,6 +350,23 @@ TkpInit( return TCL_ERROR; } } + + /* + * Instantiate our NSApplication object. + */ + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + [[NSUserDefaults standardUserDefaults] registerDefaults: + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], + @"_NSCanWrapButtonTitles", + [NSNumber numberWithInt:-1], + @"NSStringDrawingTypesetterBehavior", + nil]]; + [TKApplication sharedApplication]; + [pool drain]; + [NSApp _setup:interp]; + [NSApp finishLaunching]; } Tk_MacOSXSetupTkNotifier(); diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 12beb1b..2c036bb 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -149,7 +149,15 @@ XMapWindow( if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { NSWindow *win = TkMacOSXDrawableWindow(window); - [NSApp activateIgnoringOtherApps:YES]; + /* + * We want to activate Tk when a toplevel is mapped + * but we must not supply YES here. This is because + * during Tk initialization the root window is mapped + * before applicationDidFinishLaunching returns. Forcing + * the app to activate too early can make the menu bar + * unresponsive. + */ + [NSApp activateIgnoringOtherApps:NO]; if ( [win canBecomeKeyWindow] ) { [win makeKeyAndOrderFront:NSApp]; } diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 832cf2f..965edd5 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -930,8 +930,9 @@ TkWmDeadWindow( } } /* - * Process all events immediately to force the closed window - * to be deallocated. + * Process all window events immediately to force the closed window to + * be deallocated. But don't do this for the root window as that is + * unnecessary and can lead to segfaults. */ if (winPtr->parentPtr) { while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} |