From e30825e76ae2c2b23c38b4333282322dec78f26c Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 9 Nov 2004 17:57:45 +0000 Subject: [PATCH] 2004-11-09 18:55 Alexander Malmberg * Source/NSPasteboard.m (+_pbs): Give gpbs a --GSStartupNotification argument. Listen for the notification and connect immediately if it arrives. Clarify the user message. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20325 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++++ Source/NSPasteboard.m | 54 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26a0dea0d..2973608df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-11-09 18:55 Alexander Malmberg + + * Source/NSPasteboard.m (+_pbs): Give gpbs a --GSStartupNotification + argument. Listen for the notification and connect immediately if it + arrives. Clarify the user message. + 2004-11-08 Quentin Mathe * Source/NSButtonCell.m (-setImage:): Added overriden NSCell method in diff --git a/Source/NSPasteboard.m b/Source/NSPasteboard.m index bb7e4135a..f6ead75e5 100644 --- a/Source/NSPasteboard.m +++ b/Source/NSPasteboard.m @@ -529,6 +529,7 @@ #include #include #include +#include #include #include #include @@ -1963,7 +1964,6 @@ static NSMapTable *mimeMap = NULL; { static BOOL recursion = NO; static NSString *cmd = nil; - static NSArray *args = nil; if (cmd == nil && recursion ==NO) { @@ -1985,23 +1985,61 @@ static NSMapTable *mimeMap = NULL; } else { + NSDistributedNotificationCenter *nc; + NSMutableArray *startIndicator; + NSArray *args = nil; + NSDate *timeoutDate; + NSLog(@"\nI couldn't contact the pasteboard server for %@ -\n" -@"so I'm attempting to to start one - which will take a few seconds.\n" +@"so I'm attempting to start one - which might take a few seconds.\n" @"Trying to launch gpbs from %@ or a machine/operating-system subdirectory.\n" @"It is recommended that you start the pasteboard server (gpbs) when\n" @"your windowing system is started up.\n", description, [cmd stringByDeletingLastPathComponent]); + if ([host length] > 0) { args = [[NSArray alloc] initWithObjects: - @"-NSHost", host, nil]; + @"-NSHost", host, + @"-GSStartupNotification",@"GSStartup-GPBS", nil]; } + else + { + args = [[NSArray alloc] initWithObjects: + @"-GSStartupNotification",@"GSStartup-GPBS", nil]; + } + + /* + Trick: To avoid having to use global variables or new methods + to track whether the notification has been received or not, we + use a mutable array as an indicator. When the notification is + received, the array is emptied, so we just check the count. + */ + startIndicator = [[NSMutableArray alloc] initWithObjects: + AUTORELEASE([[NSObject alloc] init]), nil]; + + nc = [NSDistributedNotificationCenter defaultCenter]; + [nc addObserver: startIndicator + selector: @selector(removeAllObjects) + name: @"GSStartup-GPBS" + object: nil]; + [NSTask launchedTaskWithLaunchPath: cmd arguments: args]; - [NSTimer scheduledTimerWithTimeInterval: 5.0 - invocation: nil - repeats: NO]; - [[NSRunLoop currentRunLoop] runUntilDate: - [NSDate dateWithTimeIntervalSinceNow: 5.0]]; + RELEASE(args); + + timeoutDate = [NSDate dateWithTimeIntervalSinceNow: 5.0]; + + while ([startIndicator count] + && [timeoutDate timeIntervalSinceNow] > 0.0) + { + [[NSRunLoop currentRunLoop] + runMode: NSDefaultRunLoopMode + beforeDate: timeoutDate]; + } + + [nc removeObserver: startIndicator]; + DESTROY(startIndicator); + recursion = YES; [self _pbs]; recursion = NO;