From 0430474168889760bdc7afddc8a11cb8e660d8aa Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 20 May 2008 14:40:57 +0200 Subject: [PATCH] Coerce MacVim to work with LCC The LCC (Logitech Control Center) comes with an input manager which registers its own root object with the default NSConnection. MacVim uses the root object of the default connection to vend the frontend object, so LCC would cause MacVim to never open any new windows. To work around this problem the default connection is no longer used in MacVim, instead a new connection is created and this connection is used to vend the frontend object instead. --- src/MacVim/MMAppController.h | 1 + src/MacVim/MMAppController.m | 37 +++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index c464cf116d..db3d61af48 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -16,6 +16,7 @@ @interface MMAppController : NSObject { + NSConnection *connection; NSMutableArray *vimControllers; NSString *openSelectionString; ATSFontContainerRef fontContainerRef; diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index c3588683e5..002bec6bdd 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -140,24 +140,30 @@ static int executeInLoginShell(NSString *path, NSArray *args); vimControllers = [NSMutableArray new]; pidArguments = [NSMutableDictionary new]; + // NOTE: Do not use the default connection since the Logitech Control + // Center (LCC) input manager steals and this would cause MacVim to + // never open any windows. (This is a bug in LCC but since they are + // unlikely to fix it, we graciously give them the default connection.) + connection = [[NSConnection alloc] initWithReceivePort:[NSPort port] + sendPort:nil]; + [connection setRootObject:self]; + [connection setRequestTimeout:MMRequestTimeout]; + [connection setReplyTimeout:MMReplyTimeout]; + + // NOTE: When the user is resizing the window the AppKit puts the run + // loop in event tracking mode. Unless the connection listens to + // request in this mode, live resizing won't work. + [connection addRequestMode:NSEventTrackingRunLoopMode]; + // NOTE! If the name of the connection changes here it must also be // updated in MMBackend.m. - NSConnection *connection = [NSConnection defaultConnection]; NSString *name = [NSString stringWithFormat:@"%@-connection", [[NSBundle mainBundle] bundleIdentifier]]; //NSLog(@"Registering connection with name '%@'", name); - if ([connection registerName:name]) { - [connection setRequestTimeout:MMRequestTimeout]; - [connection setReplyTimeout:MMReplyTimeout]; - [connection setRootObject:self]; - - // NOTE: When the user is resizing the window the AppKit puts the - // run loop in event tracking mode. Unless the connection listens - // to request in this mode, live resizing won't work. - [connection addRequestMode:NSEventTrackingRunLoopMode]; - } else { - NSLog(@"WARNING: Failed to register connection with name '%@'", + if (![connection registerName:name]) { + NSLog(@"FATAL ERROR: Failed to register connection with name '%@'", name); + [connection release]; connection = nil; } } @@ -168,6 +174,7 @@ static int executeInLoginShell(NSString *path, NSArray *args); { //NSLog(@"MMAppController dealloc"); + [connection release]; connection = nil; [pidArguments release]; pidArguments = nil; [vimControllers release]; vimControllers = nil; [openSelectionString release]; openSelectionString = nil; @@ -456,9 +463,9 @@ static int executeInLoginShell(NSString *path, NSArray *args); andEventID:'MOD ']; #endif - // This will invalidate all connections (since they were spawned from the - // default connection). - [[NSConnection defaultConnection] invalidate]; + // This will invalidate all connections (since they were spawned from this + // connection). + [connection invalidate]; // Send a SIGINT to all running Vim processes, so that they are sure to // receive the connectionDidDie: notification (a process has to be checking