Improve interoperation with workspace manager.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22400 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-02-01 12:27:08 +00:00
parent 2fe4dfa138
commit 9bf1d32a7b
3 changed files with 95 additions and 115 deletions

View file

@ -1,3 +1,12 @@
2006-02-01 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org> 2006-01-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSApplication.m: pass more informative user info in * Source/NSApplication.m: pass more informative user info in

View file

@ -1124,8 +1124,9 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
// TODO: Currently the flag is ignored // TODO: Currently the flag is ignored
if (_app_is_active == NO) if (_app_is_active == NO)
{ {
unsigned count; unsigned count;
unsigned i; unsigned i;
NSDictionary *info;
/* /*
* Menus should observe this notification in order to make themselves * Menus should observe this notification in order to make themselves
@ -1174,9 +1175,14 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
[menu_window windowNumber]]; [menu_window windowNumber]];
} }
info = [self _notificationUserInfo];
[nc postNotificationName: NSApplicationDidBecomeActiveNotification [nc postNotificationName: NSApplicationDidBecomeActiveNotification
object: self 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) if (_app_is_active == YES)
{ {
NSArray *windows_list = [self windows]; NSArray *windows_list = [self windows];
unsigned count = [windows_list count]; unsigned count = [windows_list count];
unsigned i; unsigned i;
NSDictionary *info;
[nc postNotificationName: NSApplicationWillResignActiveNotification [nc postNotificationName: NSApplicationWillResignActiveNotification
object: self]; object: self];
@ -1237,9 +1244,14 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
} }
} }
info = [self _notificationUserInfo];
[nc postNotificationName: NSApplicationDidResignActiveNotification [nc postNotificationName: NSApplicationDidResignActiveNotification
object: self object: self
userInfo: [self _notificationUserInfo]]; userInfo: info];
nc = [[NSWorkspace sharedWorkspace] notificationCenter];
[nc postNotificationName: NSApplicationDidResignActiveNotification
object: [NSWorkspace sharedWorkspace]
userInfo: info];
} }
} }

View file

@ -241,7 +241,6 @@ static id GSLaunched(NSNotification *notification, BOOL active)
{ {
NSDistributedNotificationCenter *remote; NSDistributedNotificationCenter *remote;
} }
- (void) _handleApplicationNotification: (NSNotification*)aNotification;
- (void) _handleRemoteNotification: (NSNotification*)aNotification; - (void) _handleRemoteNotification: (NSNotification*)aNotification;
- (void) _postLocal: (NSString*)name userInfo: (NSDictionary*)info; - (void) _postLocal: (NSString*)name userInfo: (NSDictionary*)info;
@end @end
@ -250,14 +249,6 @@ static id GSLaunched(NSNotification *notification, BOOL active)
- (void) dealloc - (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]; [remote removeObserver: self name: nil object: GSWorkspaceNotification];
RELEASE(remote); RELEASE(remote);
[super dealloc]; [super dealloc];
@ -268,17 +259,6 @@ static id GSLaunched(NSNotification *notification, BOOL active)
self = [super init]; self = [super init];
if (self != nil) 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]); remote = RETAIN([NSDistributedNotificationCenter defaultCenter]);
NS_DURING NS_DURING
{ {
@ -318,7 +298,9 @@ static id GSLaunched(NSNotification *notification, BOOL active)
NSDictionary *info = [aNotification userInfo]; NSDictionary *info = [aNotification userInfo];
if ([name isEqual: NSWorkspaceDidTerminateApplicationNotification] == YES if ([name isEqual: NSWorkspaceDidTerminateApplicationNotification] == YES
|| [name isEqual: NSWorkspaceDidLaunchApplicationNotification] == YES) || [name isEqual: NSWorkspaceDidLaunchApplicationNotification] == YES
|| [name isEqualToString: NSApplicationDidBecomeActiveNotification] == YES
|| [name isEqualToString: NSApplicationDidResignActiveNotification] == YES)
{ {
GSLaunched(aNotification, YES); GSLaunched(aNotification, YES);
} }
@ -363,17 +345,6 @@ static id GSLaunched(NSNotification *notification, BOOL active)
userInfo: info]]; 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 * Forward a notification from a remote application to observers in this
* application. * application.
@ -413,8 +384,7 @@ static id GSLaunched(NSNotification *notification, BOOL active)
// application communication // application communication
- (BOOL) _launchApplication: (NSString*)appName - (BOOL) _launchApplication: (NSString*)appName
arguments: (NSArray*)args arguments: (NSArray*)args;
locally: (BOOL)locally;
- (id) _connectApplication: (NSString*)appName; - (id) _connectApplication: (NSString*)appName;
- (id) _workspaceApplication; - (id) _workspaceApplication;
@ -732,7 +702,7 @@ static NSString *_rootPath = @"/";
NSArray *args; NSArray *args;
args = [NSArray arrayWithObjects: @"-GSFilePath", fullPath, nil]; args = [NSArray arrayWithObjects: @"-GSFilePath", fullPath, nil];
return [self _launchApplication: appName arguments: args locally: NO]; return [self _launchApplication: appName arguments: args];
} }
else else
{ {
@ -794,7 +764,7 @@ static NSString *_rootPath = @"/";
NSArray *args; NSArray *args;
args = [NSArray arrayWithObjects: @"-GSTempPath", fullPath, nil]; args = [NSArray arrayWithObjects: @"-GSTempPath", fullPath, nil];
return [self _launchApplication: appName arguments: args locally: NO]; return [self _launchApplication: appName arguments: args];
} }
else else
{ {
@ -1393,7 +1363,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
{ {
args = [NSArray arrayWithObjects: @"-autolaunch", @"YES", nil]; args = [NSArray arrayWithObjects: @"-autolaunch", @"YES", nil];
} }
return [self _launchApplication: appName arguments: args locally: NO]; return [self _launchApplication: appName arguments: args];
} }
else else
{ {
@ -2349,91 +2319,81 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
} }
/** /**
* Launch an application ... if there is a workspace application and * Launch an application locally (ie without reference to the workspace
* we have not been specifically asked to launch locally, ask the * manager application). We should only call this method when we want
* workspace application to perform the launch for us. * the application launched by this process, either because what we are
* Otherwise we try to launch the app ourself as long as it is on * launching IS the workspace manager, or because we have tried to get
* the same host as we are. * the workspace manager to do the job and been unable to do so.
*/ */
- (BOOL) _launchApplication: (NSString*)appName - (BOOL) _launchApplication: (NSString*)appName
arguments: (NSArray*)args 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; NSHost *h;
NSString *path;
NSDictionary *userinfo;
NSString *host;
path = [self locateApplicationBinary: appName]; h = [NSHost hostWithName: host];
if (path == nil) if ([h isEqual: [NSHost currentHost]] == NO)
{ {
return NO; if ([args containsObject: @"-NSHost"] == 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) NSMutableArray *a;
{
NSMutableArray *a;
if (args == nil) if (args == nil)
{ {
a = [NSMutableArray arrayWithCapacity: 2]; a = [NSMutableArray arrayWithCapacity: 2];
}
else
{
a = AUTORELEASE([args mutableCopy]);
}
[a insertObject: @"-NSHost" atIndex: 0];
[a insertObject: host atIndex: 1];
args = a;
} }
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 - (id) _connectApplication: (NSString*)appName
@ -2589,8 +2549,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
if ([host isEqual: @""] == YES) if ([host isEqual: @""] == YES)
{ {
if ([self _launchApplication: appName if ([self _launchApplication: appName
arguments: nil arguments: nil] == YES)
locally: YES] == YES)
{ {
app = [self _connectApplication: appName]; app = [self _connectApplication: appName];
} }