Skip to content

Commit a42ef3c

Browse files
authored
Merge pull request #316 from macvim-dev/fix/channel
Fix channel in GUI
2 parents 93c8f82 + 41132b4 commit a42ef3c

File tree

3 files changed

+13
-95
lines changed

3 files changed

+13
-95
lines changed

src/MacVim/MMBackend.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ extern NSTimeInterval MMBalloonEvalInternalDelay;
155155
- (BOOL)imState;
156156
- (void)setImState:(BOOL)activated;
157157

158-
- (void *)addChannel:(channel_T *)channel part:(int)part;
159-
- (void)removeChannel:(void *)cookie;
160-
161158
#ifdef FEAT_BEVAL
162159
- (void)setLastToolTip:(NSString *)toolTip;
163160
#endif

src/MacVim/MMBackend.m

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,6 @@ - (NSComparisonResult)serverNameCompare:(NSString *)string;
163163
@end
164164

165165

166-
@interface MMChannel : NSObject {
167-
channel_T *channel;
168-
int part;
169-
CFSocketRef socket;
170-
CFRunLoopSourceRef runLoopSource;
171-
}
172-
173-
- (id)initWithChannel:(channel_T *)c part:(int)p;
174-
- (void)read;
175-
@end
176-
177-
178166
@interface MMBackend (Private)
179167
- (void)clearDrawData;
180168
- (void)didChangeWholeLine;
@@ -1685,19 +1673,6 @@ - (void)setImState:(BOOL)activated
16851673
[self flushQueue:YES];
16861674
}
16871675

1688-
- (void *)addChannel:(channel_T *)channel part:(int)part
1689-
{
1690-
MMChannel *mmChannel =
1691-
[[MMChannel alloc] initWithChannel:channel part:part];
1692-
return (void *)mmChannel;
1693-
}
1694-
1695-
- (void)removeChannel:(void *)cookie
1696-
{
1697-
MMChannel *mmChannel = (MMChannel *)cookie;
1698-
[mmChannel release];
1699-
}
1700-
17011676
#ifdef FEAT_BEVAL
17021677
- (void)setLastToolTip:(NSString *)toolTip
17031678
{
@@ -3409,68 +3384,3 @@ - (char_u *)vimStringSave
34093384
}
34103385

34113386
@end // NSString (VimStrings)
3412-
3413-
3414-
3415-
@implementation MMChannel
3416-
3417-
- (void)dealloc
3418-
{
3419-
CFSocketInvalidate(socket);
3420-
CFRunLoopSourceInvalidate(runLoopSource);
3421-
CFRelease(runLoopSource);
3422-
CFRelease(socket);
3423-
[super dealloc];
3424-
}
3425-
3426-
static void socketReadCallback(CFSocketRef s,
3427-
CFSocketCallBackType callbackType,
3428-
CFDataRef address,
3429-
const void *data,
3430-
void *info)
3431-
{
3432-
MMChannel *mmChannel = (MMChannel *)info;
3433-
[mmChannel read];
3434-
}
3435-
3436-
- (id)initWithChannel:(channel_T *)c part:(int)p
3437-
{
3438-
self = [super init];
3439-
if (!self) return nil;
3440-
3441-
channel = c;
3442-
part = p;
3443-
3444-
// Tell CFRunLoop that we are interested in channel socket input.
3445-
CFSocketContext ctx = {0, (void *)self, NULL, NULL, NULL};
3446-
socket = CFSocketCreateWithNative(kCFAllocatorDefault,
3447-
channel->ch_part[part].ch_fd,
3448-
kCFSocketReadCallBack,
3449-
&socketReadCallback,
3450-
&ctx);
3451-
CFOptionFlags opt = CFSocketGetSocketFlags(socket);
3452-
opt &= ~(kCFSocketCloseOnInvalidate|kCFSocketLeaveErrors);
3453-
CFSocketSetSocketFlags(socket, opt);
3454-
runLoopSource = CFSocketCreateRunLoopSource(NULL,
3455-
socket,
3456-
0);
3457-
CFRunLoopAddSource(CFRunLoopGetCurrent(),
3458-
runLoopSource,
3459-
kCFRunLoopCommonModes);
3460-
3461-
return self;
3462-
}
3463-
3464-
- (void)read
3465-
{
3466-
int fd = channel->ch_part[part].ch_fd;
3467-
fd_set fds;
3468-
FD_ZERO(&fds);
3469-
FD_SET(fd, &fds);
3470-
struct timeval t;
3471-
memset(&t, 0, sizeof(t));
3472-
if (select(FD_SETSIZE, &fds, NULL, NULL, &t) > 0)
3473-
channel_read(channel, part, "MMChannel_read");
3474-
}
3475-
3476-
@end

src/MacVim/gui_macvim.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,13 +2260,24 @@ static int vimModMaskToEventModifierFlags(int mods)
22602260
void *
22612261
gui_macvim_add_channel(channel_T *channel, int part)
22622262
{
2263-
return [[MMBackend sharedInstance] addChannel:channel part:part];
2263+
dispatch_source_t s =
2264+
dispatch_source_create(DISPATCH_SOURCE_TYPE_READ,
2265+
channel->ch_part[part].ch_fd,
2266+
0,
2267+
dispatch_get_main_queue());
2268+
dispatch_source_set_event_handler(s, ^{
2269+
channel_read(channel, part, "gui_macvim_add_channel");
2270+
});
2271+
dispatch_resume(s);
2272+
return s;
22642273
}
22652274

22662275
void
22672276
gui_macvim_remove_channel(void *cookie)
22682277
{
2269-
[[MMBackend sharedInstance] removeChannel:cookie];
2278+
dispatch_source_t s = (dispatch_source_t)cookie;
2279+
dispatch_source_cancel(s);
2280+
dispatch_release(s);
22702281
}
22712282

22722283

0 commit comments

Comments
 (0)