From 9bf1d32a7b05ebcedb135a5734b0b39cc97e91bd Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 1 Feb 2006 12:27:08 +0000 Subject: [PATCH] Improve interoperation with workspace manager. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22400 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++ Source/NSApplication.m | 26 ++++-- Source/NSWorkspace.m | 175 ++++++++++++++++------------------------- 3 files changed, 95 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82992c756..90d642b85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-02-01 Richard Frith-Macdonald + + * Source/NSApplication.m: Send activation/deactivation notifications + to workspace center too ... so workspace manager will know about it. + * Source/NSWorkspace.m: Change internal method to launch applications + so that it never asks the workspace manager to do it ... that should + be handled by the public methods instead. Simplify a little to take + advantage of change to NSApplication. + 2006-01-27 Richard Frith-Macdonald * Source/NSApplication.m: pass more informative user info in diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 777df69b5..27ce86892 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -1124,8 +1124,9 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) // TODO: Currently the flag is ignored if (_app_is_active == NO) { - unsigned count; - unsigned i; + unsigned count; + unsigned i; + NSDictionary *info; /* * Menus should observe this notification in order to make themselves @@ -1174,9 +1175,14 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) [menu_window windowNumber]]; } + info = [self _notificationUserInfo]; [nc postNotificationName: NSApplicationDidBecomeActiveNotification object: self - userInfo: [self _notificationUserInfo]]; + userInfo: info]; + nc = [[NSWorkspace sharedWorkspace] notificationCenter]; + [nc postNotificationName: NSApplicationDidBecomeActiveNotification + object: [NSWorkspace sharedWorkspace] + userInfo: info]; } } @@ -1188,9 +1194,10 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) { if (_app_is_active == YES) { - NSArray *windows_list = [self windows]; - unsigned count = [windows_list count]; - unsigned i; + NSArray *windows_list = [self windows]; + unsigned count = [windows_list count]; + unsigned i; + NSDictionary *info; [nc postNotificationName: NSApplicationWillResignActiveNotification object: self]; @@ -1237,9 +1244,14 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) } } + info = [self _notificationUserInfo]; [nc postNotificationName: NSApplicationDidResignActiveNotification object: self - userInfo: [self _notificationUserInfo]]; + userInfo: info]; + nc = [[NSWorkspace sharedWorkspace] notificationCenter]; + [nc postNotificationName: NSApplicationDidResignActiveNotification + object: [NSWorkspace sharedWorkspace] + userInfo: info]; } } diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index 886901fb5..b2fe1bd22 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -241,7 +241,6 @@ static id GSLaunched(NSNotification *notification, BOOL active) { NSDistributedNotificationCenter *remote; } -- (void) _handleApplicationNotification: (NSNotification*)aNotification; - (void) _handleRemoteNotification: (NSNotification*)aNotification; - (void) _postLocal: (NSString*)name userInfo: (NSDictionary*)info; @end @@ -250,14 +249,6 @@ static id GSLaunched(NSNotification *notification, BOOL active) - (void) dealloc { - [[NSNotificationCenter defaultCenter] - removeObserver: self - name: NSApplicationDidBecomeActiveNotification - object: nil]; - [[NSNotificationCenter defaultCenter] - removeObserver: self - name: NSApplicationDidResignActiveNotification - object: nil]; [remote removeObserver: self name: nil object: GSWorkspaceNotification]; RELEASE(remote); [super dealloc]; @@ -268,17 +259,6 @@ static id GSLaunched(NSNotification *notification, BOOL active) self = [super init]; if (self != nil) { - [[NSNotificationCenter defaultCenter] - addObserver: self - selector: @selector(_handleApplicationNotification:) - name: NSApplicationDidResignActiveNotification - object: nil]; - [[NSNotificationCenter defaultCenter] - addObserver: self - selector: @selector(_handleApplicationNotification:) - name: NSApplicationDidBecomeActiveNotification - object: nil]; - remote = RETAIN([NSDistributedNotificationCenter defaultCenter]); NS_DURING { @@ -318,7 +298,9 @@ static id GSLaunched(NSNotification *notification, BOOL active) NSDictionary *info = [aNotification userInfo]; if ([name isEqual: NSWorkspaceDidTerminateApplicationNotification] == YES - || [name isEqual: NSWorkspaceDidLaunchApplicationNotification] == YES) + || [name isEqual: NSWorkspaceDidLaunchApplicationNotification] == YES + || [name isEqualToString: NSApplicationDidBecomeActiveNotification] == YES + || [name isEqualToString: NSApplicationDidResignActiveNotification] == YES) { GSLaunched(aNotification, YES); } @@ -363,17 +345,6 @@ static id GSLaunched(NSNotification *notification, BOOL active) userInfo: info]]; } -- (void) _handleApplicationNotification: (NSNotification*)aNotification -{ - NSString *name = [aNotification name]; - - if ([name isEqualToString: NSApplicationDidBecomeActiveNotification] == YES - || [name isEqualToString: NSApplicationDidResignActiveNotification] == YES) - { - GSLaunched(aNotification, YES); - } -} - /* * Forward a notification from a remote application to observers in this * application. @@ -413,8 +384,7 @@ static id GSLaunched(NSNotification *notification, BOOL active) // application communication - (BOOL) _launchApplication: (NSString*)appName - arguments: (NSArray*)args - locally: (BOOL)locally; + arguments: (NSArray*)args; - (id) _connectApplication: (NSString*)appName; - (id) _workspaceApplication; @@ -732,7 +702,7 @@ static NSString *_rootPath = @"/"; NSArray *args; args = [NSArray arrayWithObjects: @"-GSFilePath", fullPath, nil]; - return [self _launchApplication: appName arguments: args locally: NO]; + return [self _launchApplication: appName arguments: args]; } else { @@ -794,7 +764,7 @@ static NSString *_rootPath = @"/"; NSArray *args; args = [NSArray arrayWithObjects: @"-GSTempPath", fullPath, nil]; - return [self _launchApplication: appName arguments: args locally: NO]; + return [self _launchApplication: appName arguments: args]; } else { @@ -1393,7 +1363,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath { args = [NSArray arrayWithObjects: @"-autolaunch", @"YES", nil]; } - return [self _launchApplication: appName arguments: args locally: NO]; + return [self _launchApplication: appName arguments: args]; } else { @@ -2349,91 +2319,81 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath } /** - * Launch an application ... if there is a workspace application and - * we have not been specifically asked to launch locally, ask the - * workspace application to perform the launch for us. - * Otherwise we try to launch the app ourself as long as it is on - * the same host as we are. + * Launch an application locally (ie without reference to the workspace + * manager application). We should only call this method when we want + * the application launched by this process, either because what we are + * launching IS the workspace manager, or because we have tried to get + * the workspace manager to do the job and been unable to do so. */ - (BOOL) _launchApplication: (NSString*)appName arguments: (NSArray*)args - locally: (BOOL)locally { - id app; + NSTask *task; + NSString *path; + NSDictionary *userinfo; + NSString *host; - if (locally == NO && (app = [self _workspaceApplication]) != nil) + path = [self locateApplicationBinary: appName]; + if (path == nil) { - return [app _launchApplication: appName arguments: args locally: YES]; + return NO; } - else + + /* + * Try to ensure that apps we launch display in this workspace + * ie they have the same -NSHost specification. + */ + host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"]; + if (host != nil) { - NSTask *task; - NSString *path; - NSDictionary *userinfo; - NSString *host; + NSHost *h; - path = [self locateApplicationBinary: appName]; - if (path == nil) + h = [NSHost hostWithName: host]; + if ([h isEqual: [NSHost currentHost]] == NO) { - return NO; - } - - /* - * Try to ensure that apps we launch display in this workspace - * ie they have the same -NSHost specification. - */ - host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"]; - if (host != nil) - { - NSHost *h; - - h = [NSHost hostWithName: host]; - if ([h isEqual: [NSHost currentHost]] == NO) + if ([args containsObject: @"-NSHost"] == NO) { - if ([args containsObject: @"-NSHost"] == NO) - { - NSMutableArray *a; + NSMutableArray *a; - if (args == nil) - { - a = [NSMutableArray arrayWithCapacity: 2]; - } - else - { - a = AUTORELEASE([args mutableCopy]); - } - [a insertObject: @"-NSHost" atIndex: 0]; - [a insertObject: host atIndex: 1]; - args = a; + if (args == nil) + { + a = [NSMutableArray arrayWithCapacity: 2]; } + else + { + a = AUTORELEASE([args mutableCopy]); + } + [a insertObject: @"-NSHost" atIndex: 0]; + [a insertObject: host atIndex: 1]; + args = a; } } - /* - * App being launched, send - * NSWorkspaceWillLaunchApplicationNotification - */ - userinfo = [NSDictionary dictionaryWithObjectsAndKeys: - [[appName lastPathComponent] stringByDeletingPathExtension], - @"NSApplicationName", - appName, @"NSApplicationPath", - nil]; - [_workspaceCenter - postNotificationName: NSWorkspaceWillLaunchApplicationNotification - object: self - userInfo: userinfo]; - - task = [NSTask launchedTaskWithLaunchPath: path arguments: args]; - if (task == nil) - { - return NO; - } - /* - * The NSWorkspaceDidLaunchApplicationNotification will be - * sent by the started application itself. - */ - [_launched setObject: task forKey: appName]; - return YES; } + /* + * App being launched, send + * NSWorkspaceWillLaunchApplicationNotification + */ + userinfo = [NSDictionary dictionaryWithObjectsAndKeys: + [[appName lastPathComponent] stringByDeletingPathExtension], + @"NSApplicationName", + appName, @"NSApplicationPath", + nil]; + [_workspaceCenter + postNotificationName: NSWorkspaceWillLaunchApplicationNotification + object: self + userInfo: userinfo]; + + task = [NSTask launchedTaskWithLaunchPath: path arguments: args]; + if (task == nil) + { + return NO; + } + /* + * The NSWorkspaceDidLaunchApplicationNotification will be + * sent by the started application itself. + */ + [_launched setObject: task forKey: appName]; + return YES; } - (id) _connectApplication: (NSString*)appName @@ -2589,8 +2549,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath if ([host isEqual: @""] == YES) { if ([self _launchApplication: appName - arguments: nil - locally: YES] == YES) + arguments: nil] == YES) { app = [self _connectApplication: appName]; }