From fbf662505997cc6af2e7f8ddb7e8893da622652c Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 1 Jan 2018 02:23:37 +0300 Subject: [PATCH 01/23] Add RPC/GTK clipboard provider --- runtime/plugin/nvim_gui_shim.vim | 11 ++++++- src/nvim/handler.rs | 54 ++++++++++++++++++++++++++++++-- src/nvim/redraw_handler.rs | 40 +++++++++++++++++++++++ src/shell.rs | 6 ++++ 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index 8e48dbe..5cec3cb 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -4,6 +4,16 @@ if !has('nvim') || exists('g:GuiLoaded') endif let g:GuiLoaded = 1 +if !exists('g:GuiExternalClipboard') + function! provider#clipboard#Call(method, args) abort + if a:method == 'get' + return [rpcrequest(1, 'Gui', 'Clipboard', 'Get'), 'v'] + elseif a:method == 'set' + call rpcnotify(1, 'Gui', 'Clipboard', 'Set', join(a:args[0], ' ')) + endif + endfunction +endif + " Set GUI font function! GuiFont(fname, ...) abort call rpcnotify(1, 'Gui', 'Font', s:NvimQtToPangoFont(a:fname)) @@ -42,4 +52,3 @@ function s:GuiFontCommand(fname, bang) abort endfunction command! -nargs=? -bang Guifont call s:GuiFontCommand("", "") command! -nargs=? -bang GuiFont call s:GuiFontCommand("", "") - diff --git a/src/nvim/handler.rs b/src/nvim/handler.rs index 4128617..fe25085 100644 --- a/src/nvim/handler.rs +++ b/src/nvim/handler.rs @@ -1,5 +1,5 @@ use std::result; -use std::sync::Arc; +use std::sync::{Arc, mpsc}; use neovim_lib::{Handler, Value}; @@ -24,6 +24,7 @@ impl NvimHandler { match method { "redraw" => { self.safe_call(move |ui| { + let ui = &mut ui.borrow_mut(); let mut repaint_mode = RepaintMode::Nothing; for ev in params { @@ -63,6 +64,7 @@ impl NvimHandler { if let Value::String(ev_name) = ev_name { let args = params_iter.collect(); self.safe_call(move |ui| { + let ui = &mut ui.borrow_mut(); redraw_handler::call_gui_event( ui, ev_name.as_str().ok_or_else(|| "Event name does not exists")?, @@ -87,14 +89,56 @@ impl NvimHandler { } } + fn nvim_cb_req (&self, method: &str, params: Vec) -> result::Result { + match method { + "Gui" => { + if !params.is_empty() { + let mut params_iter = params.into_iter(); + if let Some(req_name) = params_iter.next() { + if let Value::String(req_name) = req_name { + let args = params_iter.collect(); + let (sender, receiver) = mpsc::channel(); + self.safe_call(move |ui| { + sender.send(redraw_handler::call_gui_request( + &ui.clone(), + req_name.as_str().ok_or_else(|| "Event name does not exists")?, + &args, + )).unwrap(); + { + let ui = &mut ui.borrow_mut(); + ui.on_redraw(&RepaintMode::All); + } + Ok(()) + }); + Ok(receiver.recv().unwrap()?) + } else { + error!("Unsupported request"); + Err(Value::Nil) + } + } else { + error!("Request name does not exist"); + Err(Value::Nil) + } + } else { + error!("Unsupported request {:?}", params); + Err(Value::Nil) + } + }, + _ => { + error!("Request {}({:?})", method, params); + Err(Value::Nil) + } + } + } + fn safe_call(&self, cb: F) where - F: FnOnce(&mut shell::State) -> result::Result<(), String> + 'static + Send, + F: FnOnce(&Arc>) -> result::Result<(), String> + 'static + Send, { let mut cb = Some(cb); let shell = self.shell.clone(); glib::idle_add(move || { - if let Err(msg) = cb.take().unwrap()(&mut shell.borrow_mut()) { + if let Err(msg) = cb.take().unwrap()(&shell) { error!("Error call function: {}", msg); } glib::Continue(false) @@ -106,4 +150,8 @@ impl Handler for NvimHandler { fn handle_notify(&mut self, name: &str, args: Vec) { self.nvim_cb(name, args); } + + fn handle_request(&mut self, name: &str, args: Vec) -> result::Result { + self.nvim_cb_req(name, args) + } } diff --git a/src/nvim/redraw_handler.rs b/src/nvim/redraw_handler.rs index 095fbea..cc452da 100644 --- a/src/nvim/redraw_handler.rs +++ b/src/nvim/redraw_handler.rs @@ -1,9 +1,12 @@ use std::result; +use std::sync::Arc; use neovim_lib::{Value, UiOption}; use neovim_lib::neovim_api::Tabpage; +use ui::UiMutex; use shell; +use gtk::ClipboardExt; use value::ValueMapExt; @@ -111,6 +114,14 @@ pub fn call_gui_event( ) -> result::Result<(), String> { match method { "Font" => ui.set_font(try_str!(args[0])), + "Clipboard" => { + match try_str!(args[0]) { + "Set" => { + ui.clipboard_set(try_str!(args[1])); + }, + opt => error!("Unknown option {}", opt), + } + }, "Option" => { match try_str!(args[0]) { "Popupmenu" => { @@ -137,6 +148,35 @@ pub fn call_gui_event( Ok(()) } +pub fn call_gui_request( + ui: &Arc>, + method: &str, + args: &Vec, +) -> result::Result { + match method { + "Clipboard" => { + match try_str!(args[0]) { + "Get" => { + // NOTE: wait_for_text waits on the main loop. We can't have the ui borrowed + // while it runs, otherwise ui callbacks will get called and try to borrow + // mutably twice! + let clipboard = { + let ui = &mut ui.borrow_mut(); + ui.clipboard.clone() + }; + let t = clipboard.wait_for_text().unwrap_or_else(|| String::new()); + Ok(Value::Array(t.split("\n").map(|s| s.into()).collect::>())) + }, + opt => { + error!("Unknown option {}", opt); + Err(Value::Nil) + }, + } + }, + _ => Err(Value::String(format!("Unsupported request {}({:?})", method, args).into())), + } +} + pub fn call( ui: &mut shell::State, method: &str, diff --git a/src/shell.rs b/src/shell.rs index 57c7f5a..78aeb11 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -80,6 +80,7 @@ pub struct State { cursor: Option, popup_menu: RefCell, settings: Rc>, + pub clipboard: gtk::Clipboard, pub mode: mode::Mode, @@ -113,6 +114,7 @@ impl State { cursor: None, popup_menu, settings, + clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), mode: mode::Mode::new(), @@ -201,6 +203,10 @@ impl State { } } + pub fn clipboard_set(&self, text: &str) { + self.clipboard.set_text(text); + } + fn close_popup_menu(&self) { if self.popup_menu.borrow().is_open() { if let Some(mut nvim) = self.nvim() { From 43755c8f24d0e92ea8b605c971af152eae030ea3 Mon Sep 17 00:00:00 2001 From: daa Date: Mon, 1 Jan 2018 18:52:55 +0300 Subject: [PATCH 02/23] Disable gtk clipboard by default as it does not support PRIMARY --- runtime/plugin/nvim_gui_shim.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index 5cec3cb..319784a 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -4,7 +4,7 @@ if !has('nvim') || exists('g:GuiLoaded') endif let g:GuiLoaded = 1 -if !exists('g:GuiExternalClipboard') +if exists('g:GuiInternalClipboard') function! provider#clipboard#Call(method, args) abort if a:method == 'get' return [rpcrequest(1, 'Gui', 'Clipboard', 'Get'), 'v'] From 30b7fc87e1e92ac2bb102fd6af6a960fc75017ac Mon Sep 17 00:00:00 2001 From: daa Date: Tue, 2 Jan 2018 23:05:32 +0300 Subject: [PATCH 03/23] Simplify resize handling. (#41) --- src/shell.rs | 121 +++++---------------------------------------------- 1 file changed, 12 insertions(+), 109 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index e6c6c55..cb4980e 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -21,8 +21,8 @@ use neovim_lib::neovim_api::Tabpage; use settings::{Settings, FontSource}; use ui_model::{UiModel, Attrs, ModelRect}; use color::{ColorModel, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED}; -use nvim::{self, RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimClient, - NeovimRef, NeovimClientAsync, CompleteItem}; +use nvim::{self, RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimClient, NeovimRef, + NeovimClientAsync, CompleteItem}; use input; use input::keyval_to_input_string; use cursor::Cursor; @@ -49,27 +49,6 @@ macro_rules! idle_cb_call { ) } -#[derive(Debug, Clone, Copy)] -enum ResizeStateEnum { - NvimResizeTimer(usize, usize), - NvimResizeRequest(usize, usize), - Wait, -} - -pub struct ResizeState { - state: ResizeStateEnum, - timer: Option, -} - -impl ResizeState { - pub fn new() -> Self { - ResizeState { - state: ResizeStateEnum::Wait, - timer: None, - } - } -} - pub struct State { pub model: UiModel, pub color_model: ColorModel, @@ -90,8 +69,6 @@ pub struct State { im_context: gtk::IMMulticontext, error_area: error::ErrorArea, - resize_state: Rc>, - options: ShellOptions, detach_cb: Option>>, @@ -125,8 +102,6 @@ impl State { im_context: gtk::IMMulticontext::new(), error_area: error::ErrorArea::new(), - resize_state: Rc::new(RefCell::new(ResizeState::new())), - options, detach_cb: None, @@ -286,73 +261,17 @@ impl State { self.im_context.reset(); } - fn try_nvim_resize(&self) { + fn try_nvim_resize(&mut self) { let (columns, rows) = self.calc_nvim_size(); - let mut resize_state = self.resize_state.borrow_mut(); - - match resize_state.state { - ResizeStateEnum::NvimResizeTimer(req_columns, req_rows) => { - if req_columns == columns && req_rows == rows { - return; - } - glib::source_remove(resize_state.timer.take().unwrap()); - resize_state.state = ResizeStateEnum::Wait; - } - ResizeStateEnum::NvimResizeRequest(req_columns, req_rows) => { - if req_columns == columns && req_rows == rows { - return; - } - } - ResizeStateEnum::Wait => (), - } - - - let resize_state_ref = self.resize_state.clone(); - let nvim = self.nvim.clone(); - - if self.model.rows == rows && self.model.columns == columns { return; } - resize_state.state = ResizeStateEnum::NvimResizeTimer(columns, rows); - resize_state.timer = Some(gtk::timeout_add(250, move || { - let mut resize_state = resize_state_ref.borrow_mut(); - resize_state.state = ResizeStateEnum::NvimResizeRequest(columns, rows); - resize_state.timer = None; - - if let Some(mut nvim) = nvim.nvim().and_then(NeovimRef::non_blocked) { - if let Err(err) = nvim.ui_try_resize(columns as u64, rows as u64) { - error!("Error trying resize nvim {}", err); - } + if let Some(mut nvim) = self.nvim_non_blocked() { + if let Err(err) = nvim.ui_try_resize(columns as u64, rows as u64) { + error!("Error trying resize nvim {}", err); } - Continue(false) - })); - } - - fn resize_main_window(&mut self) { - let &CellMetrics { - line_height, - char_width, - .. - } = self.font_ctx.cell_metrics(); - - let width = self.drawing_area.get_allocated_width(); - let height = self.drawing_area.get_allocated_height(); - let request_height = (self.model.rows as f64 * line_height) as i32; - let request_width = (self.model.columns as f64 * char_width) as i32; - - if width != request_width || height != request_height { - let window: gtk::Window = self.drawing_area - .get_toplevel() - .unwrap() - .downcast() - .unwrap(); - let (win_width, win_height) = window.get_size(); - let h_border = win_width - width; - let v_border = win_height - height; - window.resize(request_width + h_border, request_height + v_border); } } @@ -547,16 +466,14 @@ impl Shell { let ref_state = self.state.clone(); state.drawing_area.connect_realize(move |w| { - let ref_state = ref_state.clone(); - let w = w.clone(); // sometime set_client_window does not work without idle_add // and looks like not enabled im_context - gtk::idle_add(move || { + gtk::idle_add(clone!(ref_state, w => move || { ref_state.borrow().im_context.set_client_window( w.get_window().as_ref(), ); Continue(false) - }); + })); }); let ref_state = self.state.clone(); @@ -566,13 +483,13 @@ impl Shell { let ref_state = self.state.clone(); state.drawing_area.connect_configure_event(move |_, _| { - ref_state.borrow().try_nvim_resize(); + ref_state.borrow_mut().try_nvim_resize(); false }); let ref_state = self.state.clone(); state.drawing_area.connect_size_allocate( - move |_, _| init_nvim(&ref_state), + move |_, _| { init_nvim(&ref_state); }, ); } @@ -958,7 +875,6 @@ fn init_nvim(state_ref: &Arc>) { if state.start_nvim_initialization() { let (cols, rows) = state.calc_nvim_size(); state.model = UiModel::new(rows as u64, cols as u64); - state.resize_state.borrow_mut().state = ResizeStateEnum::NvimResizeRequest(cols, rows); let state_arc = state_ref.clone(); let options = state.options.clone(); @@ -988,21 +904,8 @@ impl RedrawEvents for State { } fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode { - let state = self.resize_state.borrow().state.clone(); - match state { - ResizeStateEnum::NvimResizeTimer(..) => { - if self.model.columns != columns as usize || self.model.rows != rows as usize { - self.model = UiModel::new(rows, columns); - } - } - ResizeStateEnum::Wait | - ResizeStateEnum::NvimResizeRequest(..) => { - if self.model.columns != columns as usize || self.model.rows != rows as usize { - self.resize_state.borrow_mut().state = ResizeStateEnum::Wait; - self.model = UiModel::new(rows, columns); - self.resize_main_window(); - } - } + if self.model.columns != columns as usize || self.model.rows != rows as usize { + self.model = UiModel::new(rows, columns); } if let Some(mut nvim) = self.nvim.nvim() { From 53516f0d9c324835154be72dd34dd035feb1fbef Mon Sep 17 00:00:00 2001 From: Greg V Date: Tue, 2 Jan 2018 22:38:35 +0300 Subject: [PATCH 04/23] Add support for PRIMARY clipboard --- runtime/plugin/nvim_gui_shim.vim | 6 +++--- src/nvim/redraw_handler.rs | 10 ++++++++-- src/shell.rs | 14 ++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index 319784a..f60d293 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -1,15 +1,15 @@ " A Neovim plugin that implements GUI helper commands if !has('nvim') || exists('g:GuiLoaded') - finish + finish endif let g:GuiLoaded = 1 if exists('g:GuiInternalClipboard') function! provider#clipboard#Call(method, args) abort if a:method == 'get' - return [rpcrequest(1, 'Gui', 'Clipboard', 'Get'), 'v'] + return [rpcrequest(1, 'Gui', 'Clipboard', 'Get', a:args[0]), 'v'] elseif a:method == 'set' - call rpcnotify(1, 'Gui', 'Clipboard', 'Set', join(a:args[0], ' ')) + call rpcnotify(1, 'Gui', 'Clipboard', 'Set', a:args[2], join(a:args[0], ' ')) endif endfunction endif diff --git a/src/nvim/redraw_handler.rs b/src/nvim/redraw_handler.rs index 40fd59a..9f7122b 100644 --- a/src/nvim/redraw_handler.rs +++ b/src/nvim/redraw_handler.rs @@ -117,7 +117,10 @@ pub fn call_gui_event( "Clipboard" => { match try_str!(args[0]) { "Set" => { - ui.clipboard_set(try_str!(args[1])); + match try_str!(args[1]) { + "*" => ui.clipboard_primary_set(try_str!(args[2])), + _ => ui.clipboard_clipboard_set(try_str!(args[2])), + } }, opt => error!("Unknown option {}", opt), } @@ -162,7 +165,10 @@ pub fn call_gui_request( // mutably twice! let clipboard = { let ui = &mut ui.borrow_mut(); - ui.clipboard.clone() + match try_str!(args[1]) { + "*" => ui.clipboard_primary.clone(), + _ => ui.clipboard_clipboard.clone(), + } }; let t = clipboard.wait_for_text().unwrap_or_else(|| String::new()); Ok(Value::Array(t.split("\n").map(|s| s.into()).collect::>())) diff --git a/src/shell.rs b/src/shell.rs index cb4980e..da91be3 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -59,7 +59,8 @@ pub struct State { cursor: Option, popup_menu: RefCell, settings: Rc>, - pub clipboard: gtk::Clipboard, + pub clipboard_clipboard: gtk::Clipboard, + pub clipboard_primary: gtk::Clipboard, pub mode: mode::Mode, @@ -91,7 +92,8 @@ impl State { cursor: None, popup_menu, settings, - clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), + clipboard_clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), + clipboard_primary: gtk::Clipboard::get(&gdk::Atom::intern("PRIMARY")), mode: mode::Mode::new(), @@ -178,8 +180,12 @@ impl State { } } - pub fn clipboard_set(&self, text: &str) { - self.clipboard.set_text(text); + pub fn clipboard_clipboard_set(&self, text: &str) { + self.clipboard_clipboard.set_text(text); + } + + pub fn clipboard_primary_set(&self, text: &str) { + self.clipboard_primary.set_text(text); } fn close_popup_menu(&self) { From 87dafda473e343de1a271462c514fc9710ed3180 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 3 Jan 2018 15:49:10 +0300 Subject: [PATCH 05/23] Store last clipboard register type This makes `yy` -> `p` line copying work correctly, but whether external text would be pasted as whole lines or not now depends on the last copy operation. The proper implementation would store the register type in the actual Gtk clipboard, but gtk-rs is not ready for that yet. --- runtime/plugin/nvim_gui_shim.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index f60d293..565b2ff 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -5,10 +5,12 @@ endif let g:GuiLoaded = 1 if exists('g:GuiInternalClipboard') + let s:LastRegType = 'v' function! provider#clipboard#Call(method, args) abort if a:method == 'get' - return [rpcrequest(1, 'Gui', 'Clipboard', 'Get', a:args[0]), 'v'] + return [rpcrequest(1, 'Gui', 'Clipboard', 'Get', a:args[0]), s:LastRegType] elseif a:method == 'set' + let s:LastRegType = a:args[1] call rpcnotify(1, 'Gui', 'Clipboard', 'Set', a:args[2], join(a:args[0], ' ')) endif endfunction From 026891938f7895fa5b4e45815574797eadc95b93 Mon Sep 17 00:00:00 2001 From: daa Date: Fri, 5 Jan 2018 15:56:55 +0300 Subject: [PATCH 06/23] Use async call in some cases --- Cargo.lock | 10 +++++----- Cargo.toml | 7 ++++--- src/shell.rs | 31 ++++++++++++++++++------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d04d7c6..0433b78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -302,10 +302,10 @@ dependencies = [ [[package]] name = "neovim-lib" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.5.1" +source = "git+https://github.com/daa84/neovim-lib?branch=async#d3991cf0c81329baaa78dea905b9845ac1667a45" dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rmpv 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -332,7 +332,7 @@ dependencies = [ "gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "neovim-lib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)", "pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pangocairo 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -643,7 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" -"checksum neovim-lib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1889b79fccec66b11f3f9d3a266ffd97c0944af82a62843ca2b9529fedd82fec" +"checksum neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)" = "" "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070" "checksum pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e81c404ab81ea7ea2fc2431a0a7672507b80e4b8bf4b41eac3fc83cc665104e" "checksum pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34f34a1be107fe16abb2744e0e206bee4b3b07460b5fddd3009a6aaf60bd69ab" diff --git a/Cargo.toml b/Cargo.toml index 4efcd54..91e99b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ gobject-sys = "0.5" #pango-sys = { git = 'https://github.com/gtk-rs/sys' } #gio = { git = 'https://github.com/gtk-rs/gio' } #pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' } -neovim-lib = "0.5" +#neovim-lib = "0.5" phf = "0.7" log = "0.4" env_logger = "0.4" @@ -37,8 +37,9 @@ serde_derive = "1.0" toml = "0.4" serde_json = "1.0" -#[dependencies.neovim-lib] -#git = "https://github.com/daa84/neovim-lib" +[dependencies.neovim-lib] +git = "https://github.com/daa84/neovim-lib" +branch = "async" [build-dependencies] phf_codegen = "0.7" diff --git a/src/shell.rs b/src/shell.rs index cb4980e..5864d16 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -15,7 +15,7 @@ use gtk; use gtk::prelude::*; use pangocairo; -use neovim_lib::{Neovim, NeovimApi, Value}; +use neovim_lib::{Neovim, NeovimApi, NeovimApiAsync, Value}; use neovim_lib::neovim_api::Tabpage; use settings::{Settings, FontSource}; @@ -112,6 +112,7 @@ impl State { /// Return NeovimRef only if vim in non blocking state /// /// Note that this call also do neovim api call get_mode + #[allow(dead_code)] pub fn nvim_non_blocked(&self) -> Option { self.nvim().and_then(NeovimRef::non_blocked) } @@ -268,10 +269,10 @@ impl State { return; } - if let Some(mut nvim) = self.nvim_non_blocked() { - if let Err(err) = nvim.ui_try_resize(columns as u64, rows as u64) { - error!("Error trying resize nvim {}", err); - } + if let Some(mut nvim) = self.nvim() { + nvim.ui_try_resize_async(columns as u64, rows as u64) + .cb(|r| r.report_err()) + .call(); } } @@ -280,10 +281,12 @@ impl State { if let Some(mut nvim) = nvim { if self.mode.is(&mode::NvimMode::Insert) || self.mode.is(&mode::NvimMode::Normal) { let paste_code = format!("normal! \"{}P", clipboard); - nvim.command(&paste_code).report_err(); + nvim.command_async(&paste_code) + .cb(|r| r.report_err()) + .call(); } else { let paste_code = format!("{}", clipboard); - nvim.input(&paste_code).report_err(); + nvim.input_async(&paste_code).cb(|r| r.report_err()).call(); }; } @@ -559,9 +562,10 @@ impl Deref for Shell { } fn gtk_focus_in(state: &mut State) -> Inhibit { - if let Some(mut nvim) = state.nvim_non_blocked() { - nvim.command("if exists('#FocusGained') | doautocmd FocusGained | endif") - .report_err(); + if let Some(mut nvim) = state.nvim() { + nvim.command_async("if exists('#FocusGained') | doautocmd FocusGained | endif") + .cb(|r| r.report_err()) + .call(); } state.im_context.focus_in(); @@ -572,9 +576,10 @@ fn gtk_focus_in(state: &mut State) -> Inhibit { } fn gtk_focus_out(state: &mut State) -> Inhibit { - if let Some(mut nvim) = state.nvim_non_blocked() { - nvim.command("if exists('#FocusLost') | doautocmd FocusLost | endif") - .report_err(); + if let Some(mut nvim) = state.nvim() { + nvim.command_async("if exists('#FocusLost') | doautocmd FocusLost | endif") + .cb(|r| r.report_err()) + .call(); } state.im_context.focus_out(); From 9b6c744fa3cb1d5b8ee1f81bbaf02ed6848642c1 Mon Sep 17 00:00:00 2001 From: daa Date: Fri, 5 Jan 2018 22:07:51 +0300 Subject: [PATCH 07/23] Use package from crates.io --- Cargo.lock | 6 +++--- Cargo.toml | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0433b78..16e5824 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,7 +303,7 @@ dependencies = [ [[package]] name = "neovim-lib" version = "0.5.1" -source = "git+https://github.com/daa84/neovim-lib?branch=async#d3991cf0c81329baaa78dea905b9845ac1667a45" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -332,7 +332,7 @@ dependencies = [ "gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)", + "neovim-lib 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pangocairo 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -643,7 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" -"checksum neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)" = "" +"checksum neovim-lib 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "db5378fd4e5e33e3f3fd7d2d6519a6598fcb9b4c0c5959da1307e16241cef696" "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070" "checksum pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e81c404ab81ea7ea2fc2431a0a7672507b80e4b8bf4b41eac3fc83cc665104e" "checksum pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34f34a1be107fe16abb2744e0e206bee4b3b07460b5fddd3009a6aaf60bd69ab" diff --git a/Cargo.toml b/Cargo.toml index 91e99b3..4efcd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ gobject-sys = "0.5" #pango-sys = { git = 'https://github.com/gtk-rs/sys' } #gio = { git = 'https://github.com/gtk-rs/gio' } #pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' } -#neovim-lib = "0.5" +neovim-lib = "0.5" phf = "0.7" log = "0.4" env_logger = "0.4" @@ -37,9 +37,8 @@ serde_derive = "1.0" toml = "0.4" serde_json = "1.0" -[dependencies.neovim-lib] -git = "https://github.com/daa84/neovim-lib" -branch = "async" +#[dependencies.neovim-lib] +#git = "https://github.com/daa84/neovim-lib" [build-dependencies] phf_codegen = "0.7" From 104cb137408b28674f177334841577e25f82ebef Mon Sep 17 00:00:00 2001 From: daa Date: Fri, 5 Jan 2018 22:13:17 +0300 Subject: [PATCH 08/23] Fix undercurl --- src/render/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index c0c793c..4019df9 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -106,7 +106,7 @@ fn draw_underline( let undercurl_height = (underline_thickness * 4.0).min(max_undercurl_height); let undercurl_y = line_y + underline_position - undercurl_height / 2.0; - pangocairo::functions::error_underline_path(ctx, line_x, undercurl_y, char_width, undercurl_height); + pangocairo::functions::show_error_underline(ctx, line_x, undercurl_y, char_width, undercurl_height); } else if cell.attrs.underline { let fg = color_model.actual_cell_fg(cell); ctx.set_source_rgb(fg.0, fg.1, fg.2); From c146d43bc57f8efa5455ecce1d2a059846e49d17 Mon Sep 17 00:00:00 2001 From: daa Date: Fri, 5 Jan 2018 22:14:31 +0300 Subject: [PATCH 09/23] Update version rustc version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 36154b2..2eeb238 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ environment: PROJECT_NAME: rustfmt matrix: - TARGET: x86_64-pc-windows-gnu - RUST_VERSION: 1.20.0 + RUST_VERSION: 1.22.1 install: # - ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable" From d31ec7d581f7cd634d7db10b25389e58f0127f55 Mon Sep 17 00:00:00 2001 From: daa Date: Mon, 8 Jan 2018 10:52:28 +0300 Subject: [PATCH 10/23] Always make word and kind column visible (#34) Allow popup to make smaller again --- src/popup_menu.rs | 78 ++++++++++++++++++++++++++++++++++++------- src/render/context.rs | 4 +++ src/shell.rs | 4 +-- 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/popup_menu.rs b/src/popup_menu.rs index 1b9e238..76eaf49 100644 --- a/src/popup_menu.rs +++ b/src/popup_menu.rs @@ -6,6 +6,7 @@ use gtk; use gtk::prelude::*; use glib; use gdk::{EventButton, EventType}; +use pango::{self, LayoutExt}; use neovim_lib::{Neovim, NeovimApi}; @@ -23,6 +24,9 @@ struct State { scroll: gtk::ScrolledWindow, css_provider: gtk::CssProvider, info_label: gtk::Label, + word_column: gtk::TreeViewColumn, + kind_column: gtk::TreeViewColumn, + menu_column: gtk::TreeViewColumn, } impl State { @@ -34,24 +38,25 @@ impl State { style_context.add_provider(&css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION); let renderer = gtk::CellRendererText::new(); + renderer.set_property_ellipsize(pango::EllipsizeMode::End); // word - let column = gtk::TreeViewColumn::new(); - column.pack_start(&renderer, true); - column.add_attribute(&renderer, "text", 0); - tree.append_column(&column); + let word_column = gtk::TreeViewColumn::new(); + word_column.pack_start(&renderer, true); + word_column.add_attribute(&renderer, "text", 0); + tree.append_column(&word_column); // kind - let column = gtk::TreeViewColumn::new(); - column.pack_start(&renderer, true); - column.add_attribute(&renderer, "text", 1); - tree.append_column(&column); + let kind_column = gtk::TreeViewColumn::new(); + kind_column.pack_start(&renderer, true); + kind_column.add_attribute(&renderer, "text", 1); + tree.append_column(&kind_column); // menu - let column = gtk::TreeViewColumn::new(); - column.pack_start(&renderer, true); - column.add_attribute(&renderer, "text", 2); - tree.append_column(&column); + let menu_column = gtk::TreeViewColumn::new(); + menu_column.pack_start(&renderer, true); + menu_column.add_attribute(&renderer, "text", 2); + tree.append_column(&menu_column); let info_label = gtk::Label::new(None); info_label.set_line_wrap(true); @@ -63,6 +68,9 @@ impl State { renderer, css_provider, info_label, + word_column, + kind_column, + menu_column, } } @@ -78,11 +86,57 @@ impl State { self.select(selected); } + fn limit_column_widths(&self, menu: &[CompleteItem], shell: &shell::State) { + let layout = shell.font_ctx.create_layout(); + let kind_chars = menu.iter().map(|i| i.kind.len()).max().unwrap(); + let max_width = self.scroll.get_max_content_width(); + let (xpad, _) = self.renderer.get_padding(); + + const DEFAULT_PADDING: i32 = 5; + + if kind_chars > 0 { + layout.set_text("[v]"); + let (kind_width, _) = layout.get_pixel_size(); + + self.word_column.set_fixed_width(max_width - kind_width); + + self.kind_column.set_fixed_width(kind_width + xpad * 2 + DEFAULT_PADDING); + self.kind_column.set_visible(true); + } else { + let max_line = menu.iter().max_by_key(|m| m.word.len()).unwrap(); + layout.set_text(max_line.word); + let (word_max_width, _) = layout.get_pixel_size(); + + self.kind_column.set_visible(false); + + let word_column_width = word_max_width + xpad * 2 + DEFAULT_PADDING; + if word_column_width > max_width { + self.word_column.set_fixed_width(max_width); + } else { + self.word_column.set_fixed_width(word_column_width); + } + } + + + let max_line = menu.iter().max_by_key(|m| m.menu.len()).unwrap(); + + if max_line.menu.len() > 0 { + layout.set_text(max_line.menu); + let (menu_max_width, _) = layout.get_pixel_size(); + self.menu_column.set_fixed_width(menu_max_width + xpad * 2 + DEFAULT_PADDING); + self.menu_column.set_visible(true); + } else { + self.menu_column.set_visible(false); + } + } + fn update_tree(&self, menu: &[CompleteItem], shell: &shell::State) { if menu.is_empty() { return; } + self.limit_column_widths(menu, shell); + self.renderer.set_property_font( Some(&shell.get_font_desc().to_string()), ); diff --git a/src/render/context.rs b/src/render/context.rs index f8d6ba8..62223c0 100644 --- a/src/render/context.rs +++ b/src/render/context.rs @@ -38,6 +38,10 @@ impl Context { .collect() } + pub fn create_layout(&self) -> pango::Layout { + pango::Layout::new(&self.state.pango_context) + } + #[inline] pub fn font_description(&self) -> &pango::FontDescription { &self.state.font_desc diff --git a/src/shell.rs b/src/shell.rs index 5864d16..976a49a 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -836,9 +836,8 @@ fn set_nvim_initialized(state_arc: Arc>) { } fn draw_initializing(state: &State, ctx: &cairo::Context) { - let layout = pangocairo::functions::create_layout(ctx).unwrap(); - let desc = state.get_font_desc(); let alloc = state.drawing_area.get_allocation(); + let layout = state.font_ctx.create_layout(); ctx.set_source_rgb( state.color_model.bg_color.0, @@ -847,7 +846,6 @@ fn draw_initializing(state: &State, ctx: &cairo::Context) { ); ctx.paint(); - layout.set_font_description(desc); layout.set_text("Loading->"); let (width, height) = layout.get_pixel_size(); From 132b869c7b92172e9f266f3946d2cdc28e10f36a Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 8 Jan 2018 14:09:40 +0300 Subject: [PATCH 11/23] Update minimum supported version --- src/shell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell.rs b/src/shell.rs index 59249b0..1226189 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -35,7 +35,7 @@ use render; use render::CellMetrics; const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12"; -pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.1"; +pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.2"; macro_rules! idle_cb_call { ($state:ident.$cb:ident($( $x:expr ),*)) => ( From 4bf2cca12cadff0e986d1b1df2fbdeb921d28c85 Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 8 Jan 2018 16:49:23 +0300 Subject: [PATCH 12/23] Add minimum supported version to about dialog --- src/ui.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui.rs b/src/ui.rs index 98fe539..aeda3e7 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -11,7 +11,7 @@ use gio::prelude::*; use gio::{Menu, MenuExt, MenuItem, SimpleAction}; use settings::Settings; -use shell::{Shell, ShellOptions}; +use shell::{self, Shell, ShellOptions}; use shell_dlg; use project::Projects; use plug_manager; @@ -233,6 +233,13 @@ fn on_help_about(comps: &Components) { about.set_version(env!("CARGO_PKG_VERSION")); about.set_logo_icon_name("org.daa.NeovimGtk"); about.set_authors(&[env!("CARGO_PKG_AUTHORS")]); + about.set_comments( + format!( + "Build on top of neovim\n\ + Minimum supported neovim version: {}", + shell::MINIMUM_SUPPORTED_NVIM_VERSION + ).as_str(), + ); about.connect_response(|about, _| about.destroy()); about.show(); From a6e16d1cbdb64031855612ae25df31592cdee249 Mon Sep 17 00:00:00 2001 From: daa Date: Mon, 8 Jan 2018 23:33:35 +0300 Subject: [PATCH 13/23] Fix popup width in case kind column is visible (#34) --- src/popup_menu.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/popup_menu.rs b/src/popup_menu.rs index 76eaf49..544d775 100644 --- a/src/popup_menu.rs +++ b/src/popup_menu.rs @@ -87,41 +87,37 @@ impl State { } fn limit_column_widths(&self, menu: &[CompleteItem], shell: &shell::State) { + const DEFAULT_PADDING: i32 = 5; + let layout = shell.font_ctx.create_layout(); - let kind_chars = menu.iter().map(|i| i.kind.len()).max().unwrap(); + let kind_exists = menu.iter().find(|i| i.kind.len() > 0).is_some(); let max_width = self.scroll.get_max_content_width(); let (xpad, _) = self.renderer.get_padding(); - const DEFAULT_PADDING: i32 = 5; + let max_word_line = menu.iter().max_by_key(|m| m.word.len()).unwrap(); + layout.set_text(max_word_line.word); + let (word_max_width, _) = layout.get_pixel_size(); + let word_column_width = word_max_width + xpad * 2 + DEFAULT_PADDING; - if kind_chars > 0 { + + if kind_exists { layout.set_text("[v]"); let (kind_width, _) = layout.get_pixel_size(); - self.word_column.set_fixed_width(max_width - kind_width); - self.kind_column.set_fixed_width(kind_width + xpad * 2 + DEFAULT_PADDING); self.kind_column.set_visible(true); + + self.word_column.set_fixed_width(min(max_width - kind_width, word_column_width)); } else { - let max_line = menu.iter().max_by_key(|m| m.word.len()).unwrap(); - layout.set_text(max_line.word); - let (word_max_width, _) = layout.get_pixel_size(); - self.kind_column.set_visible(false); - - let word_column_width = word_max_width + xpad * 2 + DEFAULT_PADDING; - if word_column_width > max_width { - self.word_column.set_fixed_width(max_width); - } else { - self.word_column.set_fixed_width(word_column_width); - } + self.word_column.set_fixed_width(min(max_width, word_column_width)); } - let max_line = menu.iter().max_by_key(|m| m.menu.len()).unwrap(); + let max_menu_line = menu.iter().max_by_key(|m| m.menu.len()).unwrap(); - if max_line.menu.len() > 0 { - layout.set_text(max_line.menu); + if max_menu_line.menu.len() > 0 { + layout.set_text(max_menu_line.menu); let (menu_max_width, _) = layout.get_pixel_size(); self.menu_column.set_fixed_width(menu_max_width + xpad * 2 + DEFAULT_PADDING); self.menu_column.set_visible(true); From 8a025c3a7c07848f118e6415703c37f0992e5809 Mon Sep 17 00:00:00 2001 From: daa Date: Tue, 23 Jan 2018 23:22:19 +0300 Subject: [PATCH 14/23] Implement #52 --- src/ui.rs | 192 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 134 insertions(+), 58 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index aeda3e7..65bcd2b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,16 +1,18 @@ -use std::cell::{RefCell, Ref, RefMut}; +use std::cell::{Ref, RefCell, RefMut}; use std::{env, thread}; use std::rc::Rc; use std::sync::Arc; +use gdk; use gtk; use gtk_sys; use gtk::prelude::*; -use gtk::{ApplicationWindow, HeaderBar, ToolButton, Image, AboutDialog, SettingsExt}; +use gtk::{AboutDialog, ApplicationWindow, HeaderBar, Image, SettingsExt, ToolButton}; use gio::prelude::*; use gio::{Menu, MenuExt, MenuItem, SimpleAction}; +use toml; -use settings::Settings; +use settings::{Settings, SettingsLoader}; use shell::{self, Shell, ShellOptions}; use shell_dlg; use project::Projects; @@ -44,6 +46,7 @@ pub struct Ui { pub struct Components { window: Option, + window_state: WindowState, open_btn: ToolButton, } @@ -55,6 +58,7 @@ impl Components { Components { open_btn: ToolButton::new(Some(&save_image), "Open"), window: None, + window_state: WindowState::load(), } } @@ -98,65 +102,93 @@ impl Ui { let mut settings = self.settings.borrow_mut(); settings.init(); - let mut comps = self.comps.borrow_mut(); + let window = ApplicationWindow::new(app); - self.shell.borrow_mut().init(); + { + // initialize window from comps + // borrowing of comps must be leaved + // for event processing + let mut comps = self.comps.borrow_mut(); - comps.window = Some(ApplicationWindow::new(app)); - let window = comps.window.as_ref().unwrap(); + self.shell.borrow_mut().init(); - let prefer_dark_theme = env::var("NVIM_GTK_PREFER_DARK_THEME") - .map(|opt| opt.trim() == "1") - .unwrap_or(false); - if prefer_dark_theme { - if let Some(settings) = window.get_settings() { - settings.set_property_gtk_application_prefer_dark_theme(true); + comps.window = Some(window.clone()); + + let prefer_dark_theme = env::var("NVIM_GTK_PREFER_DARK_THEME") + .map(|opt| opt.trim() == "1") + .unwrap_or(false); + if prefer_dark_theme { + if let Some(settings) = window.get_settings() { + settings.set_property_gtk_application_prefer_dark_theme(true); + } + } + + // Client side decorations including the toolbar are disabled via NVIM_GTK_NO_HEADERBAR=1 + let use_header_bar = env::var("NVIM_GTK_NO_HEADERBAR") + .map(|opt| opt.trim() != "1") + .unwrap_or(true); + + if app.prefers_app_menu() || use_header_bar { + self.create_main_menu(app); + } + + if use_header_bar { + let header_bar = HeaderBar::new(); + + let projects = self.projects.clone(); + header_bar.pack_start(&comps.open_btn); + comps + .open_btn + .connect_clicked(move |_| projects.borrow_mut().show()); + + let save_image = Image::new_from_icon_name( + "document-save", + gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32, + ); + let save_btn = ToolButton::new(Some(&save_image), "Save"); + + let shell = self.shell.clone(); + save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all()); + header_bar.pack_start(&save_btn); + + let paste_image = Image::new_from_icon_name( + "edit-paste", + gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32, + ); + let paste_btn = ToolButton::new(Some(&paste_image), "Paste"); + let shell = self.shell.clone(); + paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste()); + header_bar.pack_start(&paste_btn); + + header_bar.set_show_close_button(true); + + window.set_titlebar(Some(&header_bar)); + } + + window.set_default_size( + comps.window_state.current_width, + comps.window_state.current_height, + ); + if comps.window_state.is_maximized { + window.maximize(); } } - // Client side decorations including the toolbar are disabled via NVIM_GTK_NO_HEADERBAR=1 - let use_header_bar = env::var("NVIM_GTK_NO_HEADERBAR") - .map(|opt| opt.trim() != "1") - .unwrap_or(true); + let comps_ref = self.comps.clone(); + window.connect_size_allocate(move |window, _| { + gtk_window_size_allocate(window, &mut *comps_ref.borrow_mut()) + }); - if app.prefers_app_menu() || use_header_bar { - self.create_main_menu(app); - } + let comps_ref = self.comps.clone(); + window.connect_window_state_event(move |_, event| { + gtk_window_state_event(event, &mut *comps_ref.borrow_mut()); + Inhibit(false) + }); - if use_header_bar { - let header_bar = HeaderBar::new(); - - let projects = self.projects.clone(); - header_bar.pack_start(&comps.open_btn); - comps.open_btn.connect_clicked( - move |_| projects.borrow_mut().show(), - ); - - let save_image = Image::new_from_icon_name( - "document-save", - gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32, - ); - let save_btn = ToolButton::new(Some(&save_image), "Save"); - - let shell = self.shell.clone(); - save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all()); - header_bar.pack_start(&save_btn); - - let paste_image = Image::new_from_icon_name( - "edit-paste", - gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32, - ); - let paste_btn = ToolButton::new(Some(&paste_image), "Paste"); - let shell = self.shell.clone(); - paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste()); - header_bar.pack_start(&paste_btn); - - header_bar.set_show_close_button(true); - - window.set_titlebar(Some(&header_bar)); - } - - window.set_default_size(800, 600); + let comps_ref = self.comps.clone(); + window.connect_destroy(move |_| { + comps_ref.borrow().window_state.save(); + }); let shell = self.shell.borrow(); window.add(&**shell); @@ -182,9 +214,9 @@ impl Ui { let state_ref = self.shell.borrow().state.clone(); let plug_manager_ref = self.plug_manager.clone(); shell.set_nvim_started_cb(Some(move || { - plug_manager_ref.borrow_mut().init_nvim_client( - state_ref.borrow().nvim_clone(), - ); + plug_manager_ref + .borrow_mut() + .init_nvim_client(state_ref.borrow().nvim_clone()); })); } @@ -236,7 +268,7 @@ fn on_help_about(comps: &Components) { about.set_comments( format!( "Build on top of neovim\n\ - Minimum supported neovim version: {}", + Minimum supported neovim version: {}", shell::MINIMUM_SUPPORTED_NVIM_VERSION ).as_str(), ); @@ -260,6 +292,50 @@ fn gtk_delete(comps: &UiMutex, shell: &RefCell) -> Inhibit { }) } +fn gtk_window_size_allocate(app_window: >k::ApplicationWindow, comps: &mut Components) { + if !app_window.is_maximized() { + let (current_width, current_height) = app_window.get_size(); + comps.window_state.current_width = current_width; + comps.window_state.current_height = current_height; + } +} + +fn gtk_window_state_event(event: &gdk::EventWindowState, comps: &mut Components) { + comps.window_state.is_maximized = event + .get_new_window_state() + .contains(gdk::WindowState::MAXIMIZED); +} + +#[derive(Serialize, Deserialize)] +struct WindowState { + current_width: i32, + current_height: i32, + is_maximized: bool, +} + +impl WindowState { + pub fn new() -> Self { + WindowState { + current_width: 800, + current_height: 600, + is_maximized: false, + } + } +} + +impl SettingsLoader for WindowState { + const SETTINGS_FILE: &'static str = "window.toml"; + + fn empty() -> WindowState { + WindowState::new() + } + + fn from_str(s: &str) -> Result { + toml::from_str(&s).map_err(|e| format!("{}", e)) + } +} + + pub struct UiMutex { thread: thread::ThreadId, data: RefCell, From 925422ff851a01ced650e9812ac39d2c5e83229e Mon Sep 17 00:00:00 2001 From: Jason Chen Date: Sun, 28 Jan 2018 12:12:29 +0800 Subject: [PATCH 15/23] Modified `appveyor.yml` to generate binary for Windows with MinGW-64. --- appveyor.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 2eeb238..41caa0b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: global: - PROJECT_NAME: rustfmt + PROJECT_NAME: neovim-gtk-win64 matrix: - TARGET: x86_64-pc-windows-gnu RUST_VERSION: 1.22.1 @@ -10,6 +10,7 @@ install: # - ps: $env:RUST_VERSION = Get-Content channel-rust-stable | select -first 1 | %{$_.split('-')[1]} - SET RUST_URL=https://static.rust-lang.org/dist/rust-%RUST_VERSION%-%TARGET%.exe - SET PATH=C:\Rust\bin;C:\msys64\mingw64\bin;%PATH%;C:\msys64\usr\bin + - SET PKG_CONFIG_PATH=C:\msys64\mingw64\lib\pkgconfig - ps: Start-FileDownload $env:RUST_URL -FileName rust-dist.exe - rust-dist.exe /VERYSILENT /NORESTART /COMPONENTS="Rustc,Gcc,Cargo,Std" /DIR="C:\Rust" - rustc -V @@ -18,5 +19,34 @@ install: build_script: - cargo test + - cargo build --release + +after_build: + - cmd: >- + mkdir dist + + cd dist + + mkdir bin share lib + + mkdir share\glib-2.0 share\icons lib\gdk-pixbuf-2.0 + + xcopy .\..\target\release\nvim-gtk.exe .\bin 1> nul + + for %%a in (C:\msys64\mingw64\bin\libatk-1.0-0.dll,C:\msys64\mingw64\bin\libbz2-1.dll,C:\msys64\mingw64\bin\libcairo-2.dll,C:\msys64\mingw64\bin\libcairo-gobject-2.dll,C:\msys64\mingw64\bin\libepoxy-0.dll,C:\msys64\mingw64\bin\libexpat-1.dll,C:\msys64\mingw64\bin\libffi-6.dll,C:\msys64\mingw64\bin\libfontconfig-1.dll,C:\msys64\mingw64\bin\libfreetype-6.dll,C:\msys64\mingw64\bin\libgcc_s_seh-1.dll,C:\msys64\mingw64\bin\libgdk-3-0.dll,C:\msys64\mingw64\bin\libgdk_pixbuf-2.0-0.dll,C:\msys64\mingw64\bin\libgio-2.0-0.dll,C:\msys64\mingw64\bin\libglib-2.0-0.dll,C:\msys64\mingw64\bin\libgmodule-2.0-0.dll,C:\msys64\mingw64\bin\libgobject-2.0-0.dll,C:\msys64\mingw64\bin\libgraphite2.dll,C:\msys64\mingw64\bin\libgtk-3-0.dll,C:\msys64\mingw64\bin\libharfbuzz-0.dll,C:\msys64\mingw64\bin\libiconv-2.dll,C:\msys64\mingw64\bin\libintl-8.dll,C:\msys64\mingw64\bin\libpango-1.0-0.dll,C:\msys64\mingw64\bin\libpangocairo-1.0-0.dll,C:\msys64\mingw64\bin\libpangoft2-1.0-0.dll,C:\msys64\mingw64\bin\libpangowin32-1.0-0.dll,C:\msys64\mingw64\bin\libpcre-1.dll,C:\msys64\mingw64\bin\libpixman-1-0.dll,C:\msys64\mingw64\bin\libpng16-16.dll,C:\msys64\mingw64\bin\libstdc++-6.dll,C:\msys64\mingw64\bin\libwinpthread-1.dll,C:\msys64\mingw64\bin\zlib1.dll) do xcopy %%a .\bin 1> nul + + xcopy C:\msys64\mingw64\share\glib-2.0 .\share\glib-2.0 /E 1> nul + + xcopy C:\msys64\mingw64\share\icons .\share\icons /E 1> nul + + xcopy C:\msys64\mingw64\lib\gdk-pixbuf-2.0 .\lib\gdk-pixbuf-2.0 /E 1> nul + + cd .. + + 7z a nvim-gtk-mingw64.7z dist\* + +artifacts: + - path: nvim-gtk-mingw64.7z + name: mingw64-bin test: false From 77426d04ed8d3abc032dffe3e0820767563a7081 Mon Sep 17 00:00:00 2001 From: daa84 Date: Sun, 28 Jan 2018 18:14:44 +0300 Subject: [PATCH 16/23] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0145d51..29618f1 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ makepkg -si ## flatpak Flatpak package available [here](https://github.com/daa84/neovim-gtk-flatpak) +## windows +Windows binaries on appveyor +[latest build](https://ci.appveyor.com/api/projects/daa84/neovim-gtk/artifacts/nvim-gtk-mingw64.7z?branch=master) + # Build ## Linux Install GTK development packages. Install latest rust compiler, better use *rustup* tool. Build command: From cbf927acabc00962f29f7ef578bcc97edc8b72bb Mon Sep 17 00:00:00 2001 From: daa84 Date: Fri, 2 Feb 2018 12:17:19 +0300 Subject: [PATCH 17/23] Fix #54 panic --- src/ui.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 65bcd2b..bd389f8 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -129,7 +129,7 @@ impl Ui { .unwrap_or(true); if app.prefers_app_menu() || use_header_bar { - self.create_main_menu(app); + self.create_main_menu(app, &window); } if use_header_bar { @@ -220,8 +220,7 @@ impl Ui { })); } - fn create_main_menu(&self, app: >k::Application) { - let comps = self.comps.clone(); + fn create_main_menu(&self, app: >k::Application, window: >k::ApplicationWindow) { let plug_manager = self.plug_manager.clone(); let menu = Menu::new(); @@ -240,17 +239,11 @@ impl Ui { let plugs_action = SimpleAction::new("Plugins", None); plugs_action.connect_activate( - clone!(comps => move |_, _| plug_manager::Ui::new(&plug_manager).show( - comps - .borrow() - .window - .as_ref() - .unwrap(), - )), + clone!(window => move |_, _| plug_manager::Ui::new(&plug_manager).show(&window)), ); let about_action = SimpleAction::new("HelpAbout", None); - about_action.connect_activate(move |_, _| on_help_about(&*comps.borrow())); + about_action.connect_activate(clone!(window => move |_, _| on_help_about(&window))); about_action.set_enabled(true); app.add_action(&about_action); @@ -258,9 +251,9 @@ impl Ui { } } -fn on_help_about(comps: &Components) { +fn on_help_about(window: >k::ApplicationWindow) { let about = AboutDialog::new(); - about.set_transient_for(comps.window.as_ref()); + about.set_transient_for(window); about.set_program_name("NeovimGtk"); about.set_version(env!("CARGO_PKG_VERSION")); about.set_logo_icon_name("org.daa.NeovimGtk"); From a5e84af96add209245bb8f8435b352b6510280e9 Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 10 Feb 2018 12:16:28 +0300 Subject: [PATCH 18/23] Fix #56, set WM_CLASS --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index d0c4212..4ad492d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,6 +67,8 @@ fn main() { let app_flags = gio::ApplicationFlags::HANDLES_OPEN | gio::ApplicationFlags::NON_UNIQUE; + glib::set_program_name(Some("NeovimGtk")); + let app = if cfg!(debug_assertions) { gtk::Application::new(Some("org.daa.NeovimGtkDebug"), app_flags) } else { From 0f377b7240f1e611fda9df6f944eeffd3653a869 Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 10 Feb 2018 12:21:17 +0300 Subject: [PATCH 19/23] Update versions --- Cargo.lock | 151 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16e5824..ff7f604 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -45,9 +45,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c_vec 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cairo-sys-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -56,7 +56,7 @@ name = "cairo-sys-rs" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -77,21 +77,21 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fuchsia-zircon" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fuchsia-zircon-sys" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -105,10 +105,10 @@ dependencies = [ "gdk-pixbuf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -118,10 +118,10 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gdk-pixbuf-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -133,7 +133,7 @@ dependencies = [ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -148,7 +148,7 @@ dependencies = [ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -160,10 +160,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -174,20 +174,20 @@ dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "glib" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -196,7 +196,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -207,7 +207,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -225,11 +225,11 @@ dependencies = [ "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -246,7 +246,7 @@ dependencies = [ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -261,11 +261,6 @@ name = "itoa" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazy_static" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "lazy_static" version = "1.0.0" @@ -273,7 +268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.34" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -297,7 +292,7 @@ name = "memchr" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -313,7 +308,15 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.1.41" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -325,7 +328,7 @@ dependencies = [ "gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -351,10 +354,10 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -366,7 +369,7 @@ dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -378,10 +381,10 @@ dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "cairo-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cairo-sys-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pangocairo-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -395,7 +398,7 @@ dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "cairo-sys-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -423,7 +426,7 @@ version = "0.7.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -446,16 +449,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fuchsia-zircon 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -476,7 +490,7 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -484,7 +498,7 @@ name = "rmpv" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -529,7 +543,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -584,7 +598,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -610,6 +624,25 @@ name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [metadata] "checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum atk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "33a67fd81e1922dddc335887516f2f5254534e89c9d39fa89bca5d79bd150d34" @@ -622,29 +655,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" -"checksum fuchsia-zircon 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bd510087c325af53ba24f3be8f1c081b0982319adcb8b03cad764512923ccc19" -"checksum fuchsia-zircon-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "08b3a6f13ad6b96572b53ce7af74543132f1a7055ccceb6d073dd36c54481859" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e51db95be6565011bcd5cd99f9b17fdd585001057a999b21e09f1e8c28deb9" "checksum gdk-pixbuf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16160d212ae91abe9f3324c3fb233929ba322dde63585d15cda3336f8c529ed1" "checksum gdk-pixbuf-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "798f97101eea8180da363d0e80e07ec7ec6d1809306601c0100c1de5bc8b4f52" "checksum gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4ee916f5f25c5f4b21bd9dcb12a216ae697406940ff9476358c308a8ececada" "checksum gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "84ba5a2beb559059a0c9c2bd3681743cdede8d9a36c775840bca800333b22867" "checksum gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a303bbf7a5e75ab3b627117ff10e495d1b9e97e1d68966285ac2b1f6270091bc" -"checksum glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "450247060df7d52fdad31e1d66f30d967e925c9d1d26a0ae050cfe33dcd00d08" +"checksum glib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9b0452824cc63066940f01adc721804919f0b76cdba3cfab977b00b87f16d4a" "checksum glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9693049613ff52b93013cc3d2590366d8e530366d288438724b73f6c7dc4be8" "checksum gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60d507c87a71b1143c66ed21a969be9b99a76df234b342d733e787e6c9c7d7c2" "checksum gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0847c507e52c1feaede13ef56fb4847742438602655449d5f1f782e8633f146f" "checksum gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "905fcfbaaad1b44ec0b4bba9e4d527d728284c62bc2ba41fccedace2b096766f" "checksum htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" -"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" +"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum neovim-lib 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "db5378fd4e5e33e3f3fd7d2d6519a6598fcb9b4c0c5959da1307e16241cef696" -"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070" +"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +"checksum num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10" "checksum pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e81c404ab81ea7ea2fc2431a0a7672507b80e4b8bf4b41eac3fc83cc665104e" "checksum pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34f34a1be107fe16abb2744e0e206bee4b3b07460b5fddd3009a6aaf60bd69ab" "checksum pangocairo 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41a8620ece55098d741bacf4d3aa52398f85ce83cfe0d8f670fa11de88f52c40" @@ -655,8 +688,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum rand 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9e7944d95d25ace8f377da3ac7068ce517e4c646754c43a1b1849177bbf72e59" -"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa" +"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5be5347bde0c48cfd8c3fdc0766cdfe9d8a755ef84d620d6794c778c91de8b2b" "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a3d45d7afc9b132b34a2479648863aa95c5c88e98b32285326a6ebadc80ec5c9" "checksum rmpv 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "29af0205707de955a396a1d3c657677c65f791ebabb63c0596c0b2fec0bf6325" @@ -676,3 +710,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From babf2171f23986e3392292a3ecafb0e910968efa Mon Sep 17 00:00:00 2001 From: daa84 Date: Fri, 16 Feb 2018 12:57:26 +0300 Subject: [PATCH 20/23] Disable load window size option --- src/main.rs | 56 +++++++++++++++++++++++++++++++---------------------- src/ui.rs | 27 ++++++++++++++++---------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4ad492d..d97070c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,29 @@ -extern crate gtk; -extern crate gtk_sys; -extern crate gio; +extern crate cairo; +extern crate env_logger; extern crate gdk; extern crate gdk_sys; +extern crate gio; #[macro_use] extern crate glib; extern crate glib_sys as glib_ffi; extern crate gobject_sys as gobject_ffi; -extern crate cairo; -extern crate pango; -extern crate pango_sys; -extern crate pangocairo; -extern crate pango_cairo_sys; -extern crate neovim_lib; -extern crate phf; +extern crate gtk; +extern crate gtk_sys; +extern crate htmlescape; #[macro_use] extern crate log; -extern crate env_logger; -extern crate htmlescape; +extern crate neovim_lib; +extern crate pango; +extern crate pango_cairo_sys; +extern crate pango_sys; +extern crate pangocairo; +extern crate phf; extern crate serde; #[macro_use] extern crate serde_derive; -extern crate toml; extern crate serde_json; +extern crate toml; mod sys; @@ -49,7 +49,6 @@ mod project; mod tabline; mod error; - use std::env; use std::time::Duration; use std::str::FromStr; @@ -61,6 +60,7 @@ use shell::ShellOptions; const BIN_PATH_ARG: &str = "--nvim-bin-path"; const TIMEOUT_ARG: &str = "--timeout"; +const DISABLE_WIN_STATE_RESTORE: &str = "--disable-win-restore"; fn main() { env_logger::init().expect("Can't initialize env_logger"); @@ -89,6 +89,7 @@ fn main() { let argv: Vec = args.iter() .filter(|a| !a.starts_with(BIN_PATH_ARG)) .filter(|a| !a.starts_with(TIMEOUT_ARG)) + .filter(|a| !a.starts_with(DISABLE_WIN_STATE_RESTORE)) .cloned() .collect(); app.run(&argv); @@ -102,7 +103,7 @@ fn open(app: >k::Application, files: &[gio::File], _: &str) { nvim_timeout(std::env::args()), )); - ui.init(app); + ui.init(app, !nvim_disable_win_state(std::env::args())); } } @@ -113,16 +114,15 @@ fn activate(app: >k::Application) { nvim_timeout(std::env::args()), )); - ui.init(app); + ui.init(app, !nvim_disable_win_state(std::env::args())); } fn nvim_bin_path(mut args: I) -> Option where I: Iterator, { - args.find(|a| a.starts_with(BIN_PATH_ARG)).and_then(|p| { - p.split('=').nth(1).map(str::to_owned) - }) + args.find(|a| a.starts_with(BIN_PATH_ARG)) + .and_then(|p| p.split('=').nth(1).map(str::to_owned)) } fn nvim_timeout(mut args: I) -> Option @@ -141,6 +141,15 @@ where .map(|timeout| Duration::from_secs(timeout)) } +fn nvim_disable_win_state(mut args: I) -> bool +where + I: Iterator, +{ + args.find(|a| a.starts_with(DISABLE_WIN_STATE_RESTORE)) + .map(|_| true) + .unwrap_or(false) +} + #[cfg(test)] mod tests { use super::*; @@ -157,14 +166,15 @@ mod tests { ); } - #[test] fn test_timeout_arg() { assert_eq!( Some(Duration::from_secs(100)), - nvim_timeout(vec!["neovim-gtk", "--timeout=100"].iter().map( - |s| s.to_string(), - )) + nvim_timeout( + vec!["neovim-gtk", "--timeout=100"] + .iter() + .map(|s| s.to_string(),) + ) ); } } diff --git a/src/ui.rs b/src/ui.rs index bd389f8..fd77e4b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -35,6 +35,9 @@ macro_rules! clone { ); } +const DEFAULT_WIDTH: i32 = 800; +const DEFAULT_HEIGHT: i32 = 600; + pub struct Ui { initialized: bool, comps: Arc>, @@ -93,7 +96,7 @@ impl Ui { } } - pub fn init(&mut self, app: >k::Application) { + pub fn init(&mut self, app: >k::Application, restore_win_state: bool) { if self.initialized { return; } @@ -165,12 +168,17 @@ impl Ui { window.set_titlebar(Some(&header_bar)); } - window.set_default_size( - comps.window_state.current_width, - comps.window_state.current_height, - ); - if comps.window_state.is_maximized { - window.maximize(); + if restore_win_state { + if comps.window_state.is_maximized { + window.maximize(); + } + + window.set_default_size( + comps.window_state.current_width, + comps.window_state.current_height, + ); + } else { + window.set_default_size(DEFAULT_WIDTH, DEFAULT_HEIGHT); } } @@ -309,8 +317,8 @@ struct WindowState { impl WindowState { pub fn new() -> Self { WindowState { - current_width: 800, - current_height: 600, + current_width: DEFAULT_WIDTH, + current_height: DEFAULT_HEIGHT, is_maximized: false, } } @@ -328,7 +336,6 @@ impl SettingsLoader for WindowState { } } - pub struct UiMutex { thread: thread::ThreadId, data: RefCell, From 14319b58cf276c91e5143cf65a77ec98aa930e78 Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 17 Feb 2018 13:07:06 +0300 Subject: [PATCH 21/23] Add logs to shell resize events, update env_logger version --- Cargo.lock | 126 +++++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 2 +- src/main.rs | 2 +- src/shell.rs | 10 +++- 4 files changed, 124 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff7f604..737c315 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,16 @@ dependencies = [ "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "atty" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "0.9.1" @@ -66,6 +76,15 @@ name = "cfg-if" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "chrono" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dtoa" version = "0.4.2" @@ -73,11 +92,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "env_logger" -version = "0.4.3" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -271,14 +293,6 @@ name = "libc" version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "log" version = "0.4.1" @@ -306,6 +320,33 @@ dependencies = [ "unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-traits" version = "0.1.43" @@ -324,7 +365,7 @@ name = "nvim-gtk" version = "0.2.0" dependencies = [ "cairo-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -467,6 +508,19 @@ dependencies = [ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_syscall" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "0.2.6" @@ -570,6 +624,24 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "termcolor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "termion" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread_local" version = "0.3.5" @@ -579,6 +651,16 @@ dependencies = [ "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "time" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "toml" version = "0.4.5" @@ -643,9 +725,18 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wincolor" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum atk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "33a67fd81e1922dddc335887516f2f5254534e89c9d39fa89bca5d79bd150d34" +"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" @@ -653,8 +744,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cairo-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6b5695f59fd036fe5741bc5a4eb20c78fbe42256e3b08a2af26bbcbe8070bf3" "checksum cairo-sys-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6e18fecaeac51809db57f45f4553cc0975225a7eb435a7a7e91e5e8113a84d" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" +"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" -"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" +"checksum env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f15f0b172cb4f52ed5dbf47f774a387cd2315d1bf7894ab5af9b083ae27efa5a" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e51db95be6565011bcd5cd99f9b17fdd585001057a999b21e09f1e8c28deb9" @@ -672,10 +764,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" -"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum neovim-lib 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "db5378fd4e5e33e3f3fd7d2d6519a6598fcb9b4c0c5959da1307e16241cef696" +"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +"checksum num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d26da319fb45674985c78f1d1caf99aa4941f785d384a2ae36d0740bc3e2fe" +"checksum num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "4b226df12c5a59b63569dd57fafb926d91b385dfce33d8074a412411b689d593" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10" "checksum pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e81c404ab81ea7ea2fc2431a0a7672507b80e4b8bf4b41eac3fc83cc665104e" @@ -690,6 +784,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5be5347bde0c48cfd8c3fdc0766cdfe9d8a755ef84d620d6794c778c91de8b2b" "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a3d45d7afc9b132b34a2479648863aa95c5c88e98b32285326a6ebadc80ec5c9" @@ -702,7 +798,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +"checksum termcolor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "73e83896da740a4541a6f21606b35f2aa4bada5b65d89dc61114bf9d6ff2dc7e" +"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" +"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" @@ -713,3 +812,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" diff --git a/Cargo.toml b/Cargo.toml index 4efcd54..fe5f19e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ gobject-sys = "0.5" neovim-lib = "0.5" phf = "0.7" log = "0.4" -env_logger = "0.4" +env_logger = "0.5" htmlescape = "0.3" serde = "1.0" diff --git a/src/main.rs b/src/main.rs index d97070c..2faa62d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ const TIMEOUT_ARG: &str = "--timeout"; const DISABLE_WIN_STATE_RESTORE: &str = "--disable-win-restore"; fn main() { - env_logger::init().expect("Can't initialize env_logger"); + env_logger::init(); let app_flags = gio::ApplicationFlags::HANDLES_OPEN | gio::ApplicationFlags::NON_UNIQUE; diff --git a/src/shell.rs b/src/shell.rs index 1226189..869af9b 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -276,6 +276,8 @@ impl State { } if let Some(mut nvim) = self.nvim() { + debug!("ui_try_resize {}/{}", columns, rows); + nvim.ui_try_resize_async(columns as u64, rows as u64) .cb(|r| r.report_err()) .call(); @@ -491,7 +493,8 @@ impl Shell { }); let ref_state = self.state.clone(); - state.drawing_area.connect_configure_event(move |_, _| { + state.drawing_area.connect_configure_event(move |_, ev| { + debug!("configure_event {:?}", ev.get_size()); ref_state.borrow_mut().try_nvim_resize(); false }); @@ -883,6 +886,9 @@ fn init_nvim(state_ref: &Arc>) { let mut state = state_ref.borrow_mut(); if state.start_nvim_initialization() { let (cols, rows) = state.calc_nvim_size(); + + debug!("Init nvim {}/{}", cols, rows); + state.model = UiModel::new(rows as u64, cols as u64); let state_arc = state_ref.clone(); @@ -913,6 +919,8 @@ impl RedrawEvents for State { } fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode { + debug!("on_resize {}/{}", columns, rows); + if self.model.columns != columns as usize || self.model.rows != rows as usize { self.model = UiModel::new(rows, columns); } From 8bf342ec7f6b0bc0f0877d62a491d4322f9ce266 Mon Sep 17 00:00:00 2001 From: daa Date: Sat, 17 Feb 2018 16:57:57 +0300 Subject: [PATCH 22/23] Try to fix resize issue #58 Some time during initialization phase configure event come and don't processed. --- src/shell.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shell.rs b/src/shell.rs index 869af9b..694a302 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -835,6 +835,9 @@ fn set_nvim_initialized(state_arc: Arc>) { let mut state = state_arc.borrow_mut(); state.nvim.async_to_sync(); state.nvim.set_initialized(); + // in some case resize can happens while initilization in progress + // so force resize here + state.try_nvim_resize(); state.cursor.as_mut().unwrap().start(); Continue(false) From 7e857a1dad75e1a9079997b2e29f65d2b2ea3e9a Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 19 Feb 2018 13:03:46 +0300 Subject: [PATCH 23/23] Resize timer (#58) --- src/shell.rs | 133 +++++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index 1226189..dc1d907 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -1,4 +1,4 @@ -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::rc::Rc; use std::sync::{Arc, Condvar, Mutex}; use std::ops::Deref; @@ -6,9 +6,9 @@ use std::thread; use std::time::Duration; use cairo; -use pango::{LayoutExt, FontDescription}; +use pango::{FontDescription, LayoutExt}; use gdk; -use gdk::{ModifierType, EventButton, EventMotion, EventType, EventScroll}; +use gdk::{EventButton, EventMotion, EventScroll, EventType, ModifierType}; use gdk_sys; use glib; use gtk; @@ -18,11 +18,11 @@ use pangocairo; use neovim_lib::{Neovim, NeovimApi, NeovimApiAsync, Value}; use neovim_lib::neovim_api::Tabpage; -use settings::{Settings, FontSource}; -use ui_model::{UiModel, Attrs, ModelRect}; -use color::{ColorModel, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED}; -use nvim::{self, RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimClient, NeovimRef, - NeovimClientAsync, CompleteItem}; +use settings::{FontSource, Settings}; +use ui_model::{Attrs, ModelRect, UiModel}; +use color::{Color, ColorModel, COLOR_BLACK, COLOR_RED, COLOR_WHITE}; +use nvim::{self, CompleteItem, ErrorReport, GuiApi, NeovimClient, NeovimClientAsync, NeovimRef, + RedrawEvents, RepaintMode}; use input; use input::keyval_to_input_string; use cursor::Cursor; @@ -59,6 +59,7 @@ pub struct State { cursor: Option, popup_menu: RefCell, settings: Rc>, + resize_timer: Rc>>, pub clipboard_clipboard: gtk::Clipboard, pub clipboard_primary: gtk::Clipboard, @@ -92,6 +93,7 @@ impl State { cursor: None, popup_menu, settings, + resize_timer: Rc::new(Cell::new(None)), clipboard_clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), clipboard_primary: gtk::Clipboard::get(&gdk::Atom::intern("PRIMARY")), @@ -275,11 +277,25 @@ impl State { return; } - if let Some(mut nvim) = self.nvim() { - nvim.ui_try_resize_async(columns as u64, rows as u64) - .cb(|r| r.report_err()) - .call(); + let resize_timer = self.resize_timer.take(); + if let Some(resize_timer) = resize_timer { + glib::source_remove(resize_timer); } + + let nvim = self.nvim.clone(); + let resize_timer = self.resize_timer.clone(); + + let resize_id = gtk::timeout_add(200, move || { + resize_timer.set(None); + if let Some(mut nvim) = nvim.nvim() { + nvim.ui_try_resize_async(columns as u64, rows as u64) + .cb(|r| r.report_err()) + .call(); + } + Continue(false) + }); + + self.resize_timer.set(Some(resize_id)); } fn edit_paste(&self, clipboard: &str) { @@ -294,7 +310,6 @@ impl State { let paste_code = format!("{}", clipboard); nvim.input_async(&paste_code).cb(|r| r.report_err()).call(); }; - } } } @@ -379,12 +394,14 @@ impl Shell { self.widget.pack_start(&state.stack, true, true, 0); - state.drawing_area.set_events( - (gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK | - gdk_sys::GDK_BUTTON_MOTION_MASK | gdk_sys::GDK_SCROLL_MASK | - gdk_sys::GDK_SMOOTH_SCROLL_MASK) - .bits() as i32, - ); + state + .drawing_area + .set_events( + (gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK + | gdk_sys::GDK_BUTTON_MOTION_MASK | gdk_sys::GDK_SCROLL_MASK + | gdk_sys::GDK_SMOOTH_SCROLL_MASK) + .bits() as i32, + ); let ref_state = self.state.clone(); let ref_ui_state = self.ui_state.clone(); @@ -398,33 +415,32 @@ impl Shell { let ref_state = self.state.clone(); let ref_ui_state = self.ui_state.clone(); - state.drawing_area.connect_button_release_event( - move |_, ev| { + state + .drawing_area + .connect_button_release_event(move |_, ev| { gtk_button_release( &mut *ref_state.borrow_mut(), &mut *ref_ui_state.borrow_mut(), ev, ) - }, - ); - + }); let ref_state = self.state.clone(); let ref_ui_state = self.ui_state.clone(); - state.drawing_area.connect_motion_notify_event( - move |_, ev| { + state + .drawing_area + .connect_motion_notify_event(move |_, ev| { gtk_motion_notify( &mut *ref_state.borrow_mut(), &mut *ref_ui_state.borrow_mut(), ev, ) - }, - ); + }); let ref_state = self.state.clone(); - state.drawing_area.connect_draw( - move |_, ctx| gtk_draw(&ref_state, ctx), - ); + state + .drawing_area + .connect_draw(move |_, ctx| gtk_draw(&ref_state, ctx)); let ref_state = self.state.clone(); state.drawing_area.connect_key_press_event(move |_, ev| { @@ -464,14 +480,14 @@ impl Shell { }); let ref_state = self.state.clone(); - state.drawing_area.connect_focus_in_event(move |_, _| { - gtk_focus_in(&mut *ref_state.borrow_mut()) - }); + state + .drawing_area + .connect_focus_in_event(move |_, _| gtk_focus_in(&mut *ref_state.borrow_mut())); let ref_state = self.state.clone(); - state.drawing_area.connect_focus_out_event(move |_, _| { - gtk_focus_out(&mut *ref_state.borrow_mut()) - }); + state + .drawing_area + .connect_focus_out_event(move |_, _| gtk_focus_out(&mut *ref_state.borrow_mut())); let ref_state = self.state.clone(); state.drawing_area.connect_realize(move |w| { @@ -486,9 +502,9 @@ impl Shell { }); let ref_state = self.state.clone(); - state.im_context.connect_commit(move |_, ch| { - ref_state.borrow().im_commit(ch) - }); + state + .im_context + .connect_commit(move |_, ch| ref_state.borrow().im_commit(ch)); let ref_state = self.state.clone(); state.drawing_area.connect_configure_event(move |_, _| { @@ -497,10 +513,9 @@ impl Shell { }); let ref_state = self.state.clone(); - state.drawing_area.connect_size_allocate( - move |_, _| { init_nvim(&ref_state); }, - ); - + state.drawing_area.connect_size_allocate(move |_, _| { + init_nvim(&ref_state); + }); } #[cfg(unix)] @@ -676,9 +691,8 @@ fn mouse_input(shell: &mut State, input: &str, state: ModifierType, position: (f let nvim = shell.nvim(); if let Some(mut nvim) = nvim { - nvim.input(&input_str).expect( - "Can't send mouse input event", - ); + nvim.input(&input_str) + .expect("Can't send mouse input event"); } } @@ -705,7 +719,6 @@ fn gtk_motion_notify(shell: &mut State, ui_state: &mut UiState, ev: &EventMotion } fn gtk_draw(state_arc: &Arc>, ctx: &cairo::Context) -> Inhibit { - let state = state_arc.borrow(); if state.nvim.is_initialized() { render::render( @@ -788,12 +801,8 @@ fn init_nvim_async( }); // attach ui - if let Err(err) = nvim::post_start_init( - nvim, - options.open_path.as_ref(), - cols as u64, - rows as u64, - ) + if let Err(err) = + nvim::post_start_init(nvim, options.open_path.as_ref(), cols as u64, rows as u64) { show_nvim_init_error(&err, state_arc.clone()); } else { @@ -837,7 +846,6 @@ fn set_nvim_initialized(state_arc: Arc>) { Continue(false) })); - idle_cb_call!(state_arc.nvim_started_cb()); } @@ -867,7 +875,6 @@ fn draw_initializing(state: &State, ctx: &cairo::Context) { pangocairo::functions::update_layout(ctx, &layout); pangocairo::functions::show_layout(ctx, &layout); - ctx.move_to(x + width as f64, y); state.cursor.as_ref().unwrap().draw( ctx, @@ -891,7 +898,6 @@ fn init_nvim(state_ref: &Arc>) { } } - impl RedrawEvents for State { fn on_cursor_goto(&mut self, row: u64, col: u64) -> RepaintMode { let repaint_area = self.model.set_cursor(row as usize, col as usize); @@ -1037,15 +1043,9 @@ impl RedrawEvents for State { let point = ModelRect::point(col as usize, row as usize); let (x, y, width, height) = point.to_area(self.font_ctx.cell_metrics()); - self.popup_menu.borrow_mut().show( - self, - menu, - selected, - x, - y, - width, - height, - ); + self.popup_menu + .borrow_mut() + .show(self, menu, selected, x, y, width, height); RepaintMode::Nothing } @@ -1060,7 +1060,6 @@ impl RedrawEvents for State { RepaintMode::Nothing } - fn tabline_update( &mut self, selected: Tabpage,