diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index b55890fab2..82bebe98ff 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -56,7 +56,6 @@ extern NSTimeInterval MMBalloonEvalInternalDelay; unsigned numWholeLineChanges; unsigned offsetForDrawDataPrune; BOOL imState; - NSMutableDictionary *channelDict; int winposX; int winposY; #ifdef FEAT_BEVAL @@ -156,8 +155,8 @@ extern NSTimeInterval MMBalloonEvalInternalDelay; - (BOOL)imState; - (void)setImState:(BOOL)activated; -- (void)addChannel:(channel_T *)channel; -- (void)removeChannel:(channel_T *)channel; +- (void *)addChannel:(channel_T *)channel which:(int)which; +- (void)removeChannel:(void *)cookie; #ifdef FEAT_BEVAL - (void)setLastToolTip:(NSString *)toolTip; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index e7dad6509f..4dcd02ab7a 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -164,11 +164,14 @@ extern GuiFont gui_mch_retain_font(GuiFont font); @interface MMChannel : NSObject { + channel_T *channel; + int which; CFSocketRef socket; CFRunLoopSourceRef runLoopSource; } -- (id)initWithChannel:(channel_T *)channel; +- (id)initWithChannel:(channel_T *)c which:(int)w; +- (void)read; @end @@ -241,7 +244,6 @@ extern GuiFont gui_mch_retain_font(GuiFont font); connectionNameDict = [[NSMutableDictionary alloc] init]; clientProxyDict = [[NSMutableDictionary alloc] init]; serverReplyDict = [[NSMutableDictionary alloc] init]; - channelDict = [[NSMutableDictionary alloc] init]; NSBundle *mainBundle = [NSBundle mainBundle]; NSString *path = [mainBundle pathForResource:@"Colors" ofType:@"plist"]; @@ -273,7 +275,6 @@ extern GuiFont gui_mch_retain_font(GuiFont font); gui_mch_free_font(oldWideFont); oldWideFont = NOFONT; [blinkTimer release]; blinkTimer = nil; [alternateServerName release]; alternateServerName = nil; - [channelDict release]; channelDict = nil; [serverReplyDict release]; serverReplyDict = nil; [clientProxyDict release]; clientProxyDict = nil; [connectionNameDict release]; connectionNameDict = nil; @@ -1684,18 +1685,17 @@ extern GuiFont gui_mch_retain_font(GuiFont font); [self flushQueue:YES]; } -- (void)addChannel:(channel_T *)channel +- (void *)addChannel:(channel_T *)channel which:(int)which { - NSValue *key = [NSValue valueWithPointer:channel]; MMChannel *mmChannel = - [[[MMChannel alloc] initWithChannel:channel] autorelease]; - [channelDict setObject:mmChannel forKey:key]; + [[MMChannel alloc] initWithChannel:channel which:which]; + return (__bridge void *)mmChannel; } -- (void)removeChannel:(channel_T *)channel +- (void)removeChannel:(void *)cookie { - NSValue *key = [NSValue valueWithPointer:channel]; - [channelDict removeObjectForKey:key]; + MMChannel *mmChannel = (__bridge MMChannel *)cookie; + [mmChannel release]; } #ifdef FEAT_BEVAL @@ -3428,20 +3428,22 @@ static void socketReadCallback(CFSocketRef s, const void *data, void *info) { -#ifdef FEAT_CHANNEL - channel_read((channel_T *)info, FALSE, "socketReadCallback"); -#endif + MMChannel *mmChannel = (__bridge MMChannel *)info; + [mmChannel read]; } -- (id)initWithChannel:(channel_T *)channel +- (id)initWithChannel:(channel_T *)c which:(int)w { self = [super init]; if (!self) return nil; + channel = c; + which = w; + // Tell CFRunLoop that we are interested in channel socket input. - CFSocketContext ctx = {0, channel, NULL, NULL, NULL}; + CFSocketContext ctx = {0, (__bridge void *)self, NULL, NULL, NULL}; socket = CFSocketCreateWithNative(kCFAllocatorDefault, - channel->ch_sock, + channel->ch_pfd[which].ch_fd, kCFSocketReadCallBack, &socketReadCallback, &ctx); @@ -3455,4 +3457,11 @@ static void socketReadCallback(CFSocketRef s, return self; } +- (void)read +{ +#ifdef FEAT_CHANNEL + channel_read(channel, which, "MMChannel_read"); +#endif +} + @end diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index fd1a304100..72deb6a033 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -2241,16 +2241,16 @@ static int vimModMaskToEventModifierFlags(int mods) // -- Channel Support ------------------------------------------------------ - void -gui_macvim_add_channel(channel_T *channel) + void * +gui_macvim_add_channel(channel_T *channel, int which) { - [[MMBackend sharedInstance] addChannel:channel]; + return [[MMBackend sharedInstance] addChannel:channel which:which]; } void -gui_macvim_remove_channel(channel_T *channel) +gui_macvim_remove_channel(void *cookie) { - [[MMBackend sharedInstance] removeChannel:channel]; + [[MMBackend sharedInstance] removeChannel:cookie]; } diff --git a/src/channel.c b/src/channel.c index a726588847..76e103c550 100644 --- a/src/channel.c +++ b/src/channel.c @@ -239,7 +239,7 @@ add_channel(void) channel->ch_pfd[which].ch_inputHandler = -1; #endif #ifdef FEAT_GUI_MACVIM - channel->ch_inputHandler = -1; + channel->ch_pfd[which].ch_inputHandler = 0; #endif } @@ -359,10 +359,9 @@ channel_gui_register_one(channel_T *channel, int which) # ifdef FEAT_GUI_MACVIM /* Tell Core Foundation we are interested in being called when there * is input on the editor connection socket. */ - if (channel->ch_pfd[which].ch_inputHandler == -1) { - channel->ch_pfd[which].ch_inputHandler = 0; - gui_macvim_add_channel(channel); - } + if (channel->ch_pfd[which].ch_inputHandler == 0) + channel->ch_pfd[which].ch_inputHandler = gui_macvim_add_channel( + channel, which); # endif # endif # endif @@ -431,10 +430,10 @@ channel_gui_unregister(channel_T *channel) } # else # ifdef FEAT_GUI_MACVIM - if (channel->ch_pfd[which].ch_inputHandler == 0) + if (channel->ch_pfd[which].ch_inputHandler != 0) { - gui_macvim_remove_channel(channel); - channel->ch_pfd[which].ch_inputHandler = -1; + gui_macvim_remove_channel(channel->ch_pfd[which].ch_inputHandler); + channel->ch_pfd[which].ch_inputHandler = 0; } # endif # endif diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index dbf575be3e..59047b0520 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -227,10 +227,10 @@ gui_mch_replace_dialog(exarg_T *eap); void im_set_control(int enable); + void * +gui_macvim_add_channel(channel_T *channel, int which); void -gui_macvim_add_channel(channel_T *channel); - void -gui_macvim_remove_channel(channel_T *channel); +gui_macvim_remove_channel(void *cookie); void gui_mch_drawsign(int row, int col, int typenr); diff --git a/src/structs.h b/src/structs.h index 9a40a833dc..9a19b74666 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1335,7 +1335,7 @@ typedef struct { int ch_inputHandler; /* ret.value of WSAAsyncSelect() */ #endif #ifdef FEAT_GUI_MACVIM - int ch_inputHandler; /* Cookie for input */ + void *ch_inputHandler; /* Cookie for input */ #endif } chan_fd_T;