Fix: resize some time does not work

This commit is contained in:
daa84 2017-05-16 12:01:32 +03:00
parent 9cf24e0950
commit 1f929023f4

View File

@ -53,7 +53,7 @@ pub struct State {
line_height: Option<f64>, line_height: Option<f64>,
char_width: Option<f64>, char_width: Option<f64>,
request_width: bool, request_resize: bool,
resize_timer: Option<glib::SourceId>, resize_timer: Option<glib::SourceId>,
parent: sync::Weak<UiMutex<ui::Components>>, parent: sync::Weak<UiMutex<ui::Components>>,
@ -79,7 +79,7 @@ impl State {
line_height: None, line_height: None,
char_width: None, char_width: None,
resize_timer: None, resize_timer: None,
request_width: true, request_resize: false,
parent: Arc::downgrade(parent), parent: Arc::downgrade(parent),
} }
@ -130,8 +130,8 @@ impl State {
.report_err(&mut *nvim); .report_err(&mut *nvim);
} }
fn request_width(&mut self) { fn request_resize(&mut self) {
self.request_width = true; self.request_resize = true;
} }
fn close_popup_menu(&self) { fn close_popup_menu(&self) {
@ -299,7 +299,6 @@ impl Shell {
nvim::initialize(self.state.clone(), nvim_bin_path, external_popup).expect("Can't start nvim instance"); nvim::initialize(self.state.clone(), nvim_bin_path, external_popup).expect("Can't start nvim instance");
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
state.nvim = Some(Rc::new(RefCell::new(nvim))); state.nvim = Some(Rc::new(RefCell::new(nvim)));
state.request_width();
} }
pub fn open_file(&self, path: &str) { pub fn open_file(&self, path: &str) {
@ -423,7 +422,7 @@ fn gtk_draw(parent: &ui::Components, state: &mut State, ctx: &cairo::Context) ->
} }
draw(state, ctx); draw(state, ctx);
request_width(parent, state); request_window_resize(parent, state);
Inhibit(false) Inhibit(false)
@ -619,15 +618,15 @@ fn calc_char_bounds(shell: &State, ctx: &cairo::Context) -> (i32, i32) {
layout.get_pixel_size() layout.get_pixel_size()
} }
fn request_width(parent: &ui::Components, state: &mut State) { fn request_window_resize(parent: &ui::Components, state: &mut State) {
if !state.request_width { if !state.request_resize {
return; return;
} }
if state.resize_timer.is_some() { if state.resize_timer.is_some() {
return; return;
} }
state.request_width = false; state.request_resize = false;
let width = state.drawing_area.get_allocated_width(); let width = state.drawing_area.get_allocated_width();
let height = state.drawing_area.get_allocated_height(); let height = state.drawing_area.get_allocated_height();
@ -676,7 +675,6 @@ fn gtk_configure_event(state: &Arc<UiMutex<State>>, ev: &EventConfigure) -> bool
println!("Error trying resize nvim {}", err); println!("Error trying resize nvim {}", err);
} }
} }
state_ref.request_width();
Continue(false) Continue(false)
})); }));
} }
@ -704,6 +702,7 @@ impl RedrawEvents for State {
fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode { fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode {
self.model = UiModel::new(rows, columns); self.model = UiModel::new(rows, columns);
self.request_resize();
RepaintMode::All RepaintMode::All
} }