From c1124fefceb685f1c6c46403cf4626317f4f5c6e Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Fri, 1 Dec 2017 21:59:31 +0100 Subject: [PATCH] Revert "Use API for resizing" This reverts commit 006f0a026c332cc3d69844ca5dddf52b8522ac7c. --- NeoVimServer/NeoVimMsgIds.h | 1 + NeoVimServer/NeoVimServer.m | 2 ++ NeoVimServer/server_globals.h | 1 + NeoVimServer/server_ui.m | 13 +++++++++++++ SwiftNeoVim/NeoVimAgent.h | 2 ++ SwiftNeoVim/NeoVimAgent.m | 6 ++++++ SwiftNeoVim/NeoVimView+Resize.swift | 3 +-- 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/NeoVimServer/NeoVimMsgIds.h b/NeoVimServer/NeoVimMsgIds.h index 145651ea..f65ff140 100644 --- a/NeoVimServer/NeoVimMsgIds.h +++ b/NeoVimServer/NeoVimMsgIds.h @@ -50,6 +50,7 @@ typedef NS_ENUM(NSInteger, NeoVimAgentMsgId) { NeoVimAgentMsgIdInput, NeoVimAgentMsgIdInputMarked, NeoVimAgentMsgIdDelete, + NeoVimAgentMsgIdResize, NeoVimAgentMsgIdScroll, NeoVimAgentMsgIdGetPwd, diff --git a/NeoVimServer/NeoVimServer.m b/NeoVimServer/NeoVimServer.m index d6bfb558..85ee1b09 100644 --- a/NeoVimServer/NeoVimServer.m +++ b/NeoVimServer/NeoVimServer.m @@ -70,6 +70,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD case NeoVimAgentMsgIdGetEscapeFileNames: return data_sync(data, outputCondition, neovim_escaped_filenames); + case NeoVimAgentMsgIdResize: return data_sync(data, outputCondition, neovim_resize); + case NeoVimAgentMsgIdInput: return data_sync(data, outputCondition, neovim_vim_input); case NeoVimAgentMsgIdInputMarked: return data_sync(data, outputCondition, neovim_vim_input_marked_text); diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index a4561df7..cbcad8a1 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -15,6 +15,7 @@ extern void start_neovim(NSInteger width, NSInteger height, NSArray extern void neovim_scroll(void **argv); extern void neovim_escaped_filenames(void **argv); +extern void neovim_resize(void **argv); extern void neovim_vim_input(void **argv); extern void neovim_vim_input_marked_text(void **argv); diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index bf7f93a7..268e1361 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -729,6 +729,19 @@ void neovim_escaped_filenames(void **argv) { }); } +void neovim_resize(void **argv) { + work_and_write_data_sync(argv, ^NSData *(NSData *data) { + const int *values = data.bytes; + int width = values[0]; + int height = values[1]; + + set_ui_size(_server_ui_data->bridge, width, height); + ui_refresh(); + + return nil; + }); +} + void neovim_vim_input(void **argv) { work_and_write_data_sync(argv, ^NSData *(NSData *data) { NSString *input = [[[NSString alloc] initWithData:data diff --git a/SwiftNeoVim/NeoVimAgent.h b/SwiftNeoVim/NeoVimAgent.h index 9708674b..71c461a8 100644 --- a/SwiftNeoVim/NeoVimAgent.h +++ b/SwiftNeoVim/NeoVimAgent.h @@ -42,6 +42,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)vimInputMarkedText:(NSString *)markedText; - (void)deleteCharacters:(NSInteger)count; +- (void)resizeToWidth:(int)width height:(int)height; + - (NSString * _Nullable)escapedFileName:(NSString *)fileName; - (NSArray *)escapedFileNames:(NSArray *)fileNames; diff --git a/SwiftNeoVim/NeoVimAgent.m b/SwiftNeoVim/NeoVimAgent.m index 0b4e5526..4bf47527 100644 --- a/SwiftNeoVim/NeoVimAgent.m +++ b/SwiftNeoVim/NeoVimAgent.m @@ -288,6 +288,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m [self sendMessageWithId:NeoVimAgentMsgIdDelete data:data expectsReply:NO]; } +- (void)resizeToWidth:(int)width height:(int)height { + int values[] = {width, height}; + NSData *data = [[NSData alloc] initWithBytes:values length:(2 * sizeof(int))]; + [self sendMessageWithId:NeoVimAgentMsgIdResize data:data expectsReply:NO]; +} + - (NSString *)escapedFileName:(NSString *)fileName { NSArray *fileNames = [self escapedFileNames:@[fileName]]; if (fileNames.count == 0) { diff --git a/SwiftNeoVim/NeoVimView+Resize.swift b/SwiftNeoVim/NeoVimView+Resize.swift index d80321d8..56945b60 100644 --- a/SwiftNeoVim/NeoVimView+Resize.swift +++ b/SwiftNeoVim/NeoVimView+Resize.swift @@ -50,7 +50,7 @@ extension NeoVimView { self.xOffset = floor((size.width - self.cellSize.width * CGFloat(discreteSize.width)) / 2) self.yOffset = floor((size.height - self.cellSize.height * CGFloat(discreteSize.height)) / 2) - self.nvim.uiTryResize(width: discreteSize.width, height: discreteSize.height) + self.agent.resize(toWidth: Int32(discreteSize.width), height: Int32(discreteSize.height)) } fileprivate func launchNeoVim(_ size: Size) { @@ -59,7 +59,6 @@ extension NeoVimView { self.nvim.connect() - // We probably should set the following in a .vim file. Otherwise the start screen doesn't get shown. self.nvim.setOption(name: "mouse", value: .string("a")) self.nvim.setOption(name: "title", value: .bool(true)) self.nvim.setOption(name: "termguicolors", value: .bool(true))