Skip to content

Commit 27f20f6

Browse files
committed
Sync MacVim channel code with Vim
1 parent f3f4ec5 commit 27f20f6

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

src/MacVim/MMBackend.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
5656
unsigned numWholeLineChanges;
5757
unsigned offsetForDrawDataPrune;
5858
BOOL imState;
59-
NSMutableDictionary *channelDict;
6059
int winposX;
6160
int winposY;
6261
#ifdef FEAT_BEVAL
@@ -156,8 +155,8 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
156155
- (BOOL)imState;
157156
- (void)setImState:(BOOL)activated;
158157

159-
- (void)addChannel:(channel_T *)channel;
160-
- (void)removeChannel:(channel_T *)channel;
158+
- (void *)addChannel:(channel_T *)channel which:(int)which;
159+
- (void)removeChannel:(void *)cookie;
161160

162161
#ifdef FEAT_BEVAL
163162
- (void)setLastToolTip:(NSString *)toolTip;

src/MacVim/MMBackend.m

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ - (NSComparisonResult)serverNameCompare:(NSString *)string;
164164

165165

166166
@interface MMChannel : NSObject {
167+
channel_T *channel;
168+
int which;
167169
CFSocketRef socket;
168170
CFRunLoopSourceRef runLoopSource;
169171
}
170172

171-
- (id)initWithChannel:(channel_T *)channel;
173+
- (id)initWithChannel:(channel_T *)c which:(int)w;
174+
- (void)read;
172175
@end
173176

174177

@@ -241,7 +244,6 @@ - (id)init
241244
connectionNameDict = [[NSMutableDictionary alloc] init];
242245
clientProxyDict = [[NSMutableDictionary alloc] init];
243246
serverReplyDict = [[NSMutableDictionary alloc] init];
244-
channelDict = [[NSMutableDictionary alloc] init];
245247

246248
NSBundle *mainBundle = [NSBundle mainBundle];
247249
NSString *path = [mainBundle pathForResource:@"Colors" ofType:@"plist"];
@@ -273,7 +275,6 @@ - (void)dealloc
273275
gui_mch_free_font(oldWideFont); oldWideFont = NOFONT;
274276
[blinkTimer release]; blinkTimer = nil;
275277
[alternateServerName release]; alternateServerName = nil;
276-
[channelDict release]; channelDict = nil;
277278
[serverReplyDict release]; serverReplyDict = nil;
278279
[clientProxyDict release]; clientProxyDict = nil;
279280
[connectionNameDict release]; connectionNameDict = nil;
@@ -1684,18 +1685,17 @@ - (void)setImState:(BOOL)activated
16841685
[self flushQueue:YES];
16851686
}
16861687

1687-
- (void)addChannel:(channel_T *)channel
1688+
- (void *)addChannel:(channel_T *)channel which:(int)which
16881689
{
1689-
NSValue *key = [NSValue valueWithPointer:channel];
16901690
MMChannel *mmChannel =
1691-
[[[MMChannel alloc] initWithChannel:channel] autorelease];
1692-
[channelDict setObject:mmChannel forKey:key];
1691+
[[MMChannel alloc] initWithChannel:channel which:which];
1692+
return (__bridge void *)mmChannel;
16931693
}
16941694

1695-
- (void)removeChannel:(channel_T *)channel
1695+
- (void)removeChannel:(void *)cookie
16961696
{
1697-
NSValue *key = [NSValue valueWithPointer:channel];
1698-
[channelDict removeObjectForKey:key];
1697+
MMChannel *mmChannel = (__bridge MMChannel *)cookie;
1698+
[mmChannel release];
16991699
}
17001700

17011701
#ifdef FEAT_BEVAL
@@ -3428,20 +3428,22 @@ static void socketReadCallback(CFSocketRef s,
34283428
const void *data,
34293429
void *info)
34303430
{
3431-
#ifdef FEAT_CHANNEL
3432-
channel_read((channel_T *)info, FALSE, "socketReadCallback");
3433-
#endif
3431+
MMChannel *mmChannel = (__bridge MMChannel *)info;
3432+
[mmChannel read];
34343433
}
34353434

3436-
- (id)initWithChannel:(channel_T *)channel
3435+
- (id)initWithChannel:(channel_T *)c which:(int)w
34373436
{
34383437
self = [super init];
34393438
if (!self) return nil;
34403439

3440+
channel = c;
3441+
which = w;
3442+
34413443
// Tell CFRunLoop that we are interested in channel socket input.
3442-
CFSocketContext ctx = {0, channel, NULL, NULL, NULL};
3444+
CFSocketContext ctx = {0, (__bridge void *)self, NULL, NULL, NULL};
34433445
socket = CFSocketCreateWithNative(kCFAllocatorDefault,
3444-
channel->ch_sock,
3446+
channel->ch_pfd[which].ch_fd,
34453447
kCFSocketReadCallBack,
34463448
&socketReadCallback,
34473449
&ctx);
@@ -3455,4 +3457,11 @@ - (id)initWithChannel:(channel_T *)channel
34553457
return self;
34563458
}
34573459

3460+
- (void)read
3461+
{
3462+
#ifdef FEAT_CHANNEL
3463+
channel_read(channel, which, "MMChannel_read");
3464+
#endif
3465+
}
3466+
34583467
@end

src/MacVim/gui_macvim.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,16 +2241,16 @@ static int vimModMaskToEventModifierFlags(int mods)
22412241

22422242
// -- Channel Support ------------------------------------------------------
22432243

2244-
void
2245-
gui_macvim_add_channel(channel_T *channel)
2244+
void *
2245+
gui_macvim_add_channel(channel_T *channel, int which)
22462246
{
2247-
[[MMBackend sharedInstance] addChannel:channel];
2247+
return [[MMBackend sharedInstance] addChannel:channel which:which];
22482248
}
22492249

22502250
void
2251-
gui_macvim_remove_channel(channel_T *channel)
2251+
gui_macvim_remove_channel(void *cookie)
22522252
{
2253-
[[MMBackend sharedInstance] removeChannel:channel];
2253+
[[MMBackend sharedInstance] removeChannel:cookie];
22542254
}
22552255

22562256

src/channel.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ add_channel(void)
239239
channel->ch_pfd[which].ch_inputHandler = -1;
240240
#endif
241241
#ifdef FEAT_GUI_MACVIM
242-
channel->ch_inputHandler = -1;
242+
channel->ch_pfd[which].ch_inputHandler = 0;
243243
#endif
244244
}
245245

@@ -359,10 +359,9 @@ channel_gui_register_one(channel_T *channel, int which)
359359
# ifdef FEAT_GUI_MACVIM
360360
/* Tell Core Foundation we are interested in being called when there
361361
* is input on the editor connection socket. */
362-
if (channel->ch_pfd[which].ch_inputHandler == -1) {
363-
channel->ch_pfd[which].ch_inputHandler = 0;
364-
gui_macvim_add_channel(channel);
365-
}
362+
if (channel->ch_pfd[which].ch_inputHandler == 0)
363+
channel->ch_pfd[which].ch_inputHandler = gui_macvim_add_channel(
364+
channel, which);
366365
# endif
367366
# endif
368367
# endif
@@ -431,10 +430,10 @@ channel_gui_unregister(channel_T *channel)
431430
}
432431
# else
433432
# ifdef FEAT_GUI_MACVIM
434-
if (channel->ch_pfd[which].ch_inputHandler == 0)
433+
if (channel->ch_pfd[which].ch_inputHandler != 0)
435434
{
436-
gui_macvim_remove_channel(channel);
437-
channel->ch_pfd[which].ch_inputHandler = -1;
435+
gui_macvim_remove_channel(channel->ch_pfd[which].ch_inputHandler);
436+
channel->ch_pfd[which].ch_inputHandler = 0;
438437
}
439438
# endif
440439
# endif

src/proto/gui_macvim.pro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ gui_mch_replace_dialog(exarg_T *eap);
227227
void
228228
im_set_control(int enable);
229229

230+
void *
231+
gui_macvim_add_channel(channel_T *channel, int which);
230232
void
231-
gui_macvim_add_channel(channel_T *channel);
232-
void
233-
gui_macvim_remove_channel(channel_T *channel);
233+
gui_macvim_remove_channel(void *cookie);
234234

235235
void
236236
gui_mch_drawsign(int row, int col, int typenr);

src/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ typedef struct {
13351335
int ch_inputHandler; /* ret.value of WSAAsyncSelect() */
13361336
#endif
13371337
#ifdef FEAT_GUI_MACVIM
1338-
int ch_inputHandler; /* Cookie for input */
1338+
void *ch_inputHandler; /* Cookie for input */
13391339
#endif
13401340
} chan_fd_T;
13411341

0 commit comments

Comments
 (0)