Try to keep window size on font change
This commit is contained in:
parent
d0ca58d7be
commit
2106b69c15
29
src/shell.rs
29
src/shell.rs
@ -8,7 +8,7 @@ use cairo;
|
|||||||
use pangocairo::CairoContextExt;
|
use pangocairo::CairoContextExt;
|
||||||
use pango;
|
use pango;
|
||||||
use pango::FontDescription;
|
use pango::FontDescription;
|
||||||
use gdk::{ModifierType, EventConfigure, EventButton, EventMotion, EventType, EventScroll};
|
use gdk::{ModifierType, EventButton, EventMotion, EventType, EventScroll};
|
||||||
use gdk_sys;
|
use gdk_sys;
|
||||||
use glib;
|
use glib;
|
||||||
use gtk;
|
use gtk;
|
||||||
@ -68,6 +68,7 @@ pub struct State {
|
|||||||
line_height: Option<f64>,
|
line_height: Option<f64>,
|
||||||
char_width: Option<f64>,
|
char_width: Option<f64>,
|
||||||
request_resize: bool,
|
request_resize: bool,
|
||||||
|
request_nvim_resize: bool,
|
||||||
resize_timer: Option<glib::SourceId>,
|
resize_timer: Option<glib::SourceId>,
|
||||||
|
|
||||||
options: ShellOptions,
|
options: ShellOptions,
|
||||||
@ -105,6 +106,7 @@ impl State {
|
|||||||
char_width: None,
|
char_width: None,
|
||||||
resize_timer: None,
|
resize_timer: None,
|
||||||
request_resize: false,
|
request_resize: false,
|
||||||
|
request_nvim_resize: false,
|
||||||
|
|
||||||
options,
|
options,
|
||||||
|
|
||||||
@ -185,6 +187,10 @@ impl State {
|
|||||||
self.request_resize = true;
|
self.request_resize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn request_nvim_resize(&mut self) {
|
||||||
|
self.request_nvim_resize = true;
|
||||||
|
}
|
||||||
|
|
||||||
fn close_popup_menu(&self) {
|
fn close_popup_menu(&self) {
|
||||||
if self.popup_menu.borrow().is_open() {
|
if self.popup_menu.borrow().is_open() {
|
||||||
let mut nvim = self.nvim();
|
let mut nvim = self.nvim();
|
||||||
@ -385,7 +391,10 @@ impl Shell {
|
|||||||
let ref_state = self.state.clone();
|
let ref_state = self.state.clone();
|
||||||
state
|
state
|
||||||
.drawing_area
|
.drawing_area
|
||||||
.connect_configure_event(move |_, ev| gtk_configure_event(&ref_state, ev));
|
.connect_configure_event(move |_, _| {
|
||||||
|
try_nvim_resize(&ref_state);
|
||||||
|
false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -540,6 +549,11 @@ fn update_line_metrics(state_arc: &Arc<UiMutex<State>>, ctx: &cairo::Context) {
|
|||||||
|
|
||||||
fn gtk_draw(state_arc: &Arc<UiMutex<State>>, ctx: &cairo::Context) -> Inhibit {
|
fn gtk_draw(state_arc: &Arc<UiMutex<State>>, ctx: &cairo::Context) -> Inhibit {
|
||||||
update_line_metrics(state_arc, ctx);
|
update_line_metrics(state_arc, ctx);
|
||||||
|
|
||||||
|
if state_arc.borrow_mut().request_nvim_resize {
|
||||||
|
try_nvim_resize(state_arc);
|
||||||
|
}
|
||||||
|
|
||||||
init_nvim(state_arc);
|
init_nvim(state_arc);
|
||||||
|
|
||||||
let mut state = state_arc.borrow_mut();
|
let mut state = state_arc.borrow_mut();
|
||||||
@ -895,15 +909,17 @@ fn split_color(indexed_color: u64) -> Color {
|
|||||||
Color(r / 255.0, g / 255.0, b / 255.0)
|
Color(r / 255.0, g / 255.0, b / 255.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtk_configure_event(state: &Arc<UiMutex<State>>, _: &EventConfigure) -> bool {
|
fn try_nvim_resize(state: &Arc<UiMutex<State>>) {
|
||||||
let mut state_ref = state.borrow_mut();
|
let mut state_ref = state.borrow_mut();
|
||||||
|
|
||||||
|
state_ref.request_nvim_resize = false;
|
||||||
|
|
||||||
if let Some(timer) = state_ref.resize_timer {
|
if let Some(timer) = state_ref.resize_timer {
|
||||||
glib::source_remove(timer);
|
glib::source_remove(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !state_ref.nvim.borrow().is_initialized() {
|
if !state_ref.nvim.borrow().is_initialized() {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((columns, rows)) = state_ref.calc_nvim_size() {
|
if let Some((columns, rows)) = state_ref.calc_nvim_size() {
|
||||||
@ -915,13 +931,12 @@ fn gtk_configure_event(state: &Arc<UiMutex<State>>, _: &EventConfigure) -> bool
|
|||||||
|
|
||||||
if state_ref.model.rows != rows || state_ref.model.columns != columns {
|
if state_ref.model.rows != rows || state_ref.model.columns != columns {
|
||||||
if let Err(err) = state_ref.nvim().ui_try_resize(columns as u64, rows as u64) {
|
if let Err(err) = state_ref.nvim().ui_try_resize(columns as u64, rows as u64) {
|
||||||
println!("Error trying resize nvim {}", err);
|
error!("Error trying resize nvim {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Continue(false)
|
Continue(false)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedrawEvents for State {
|
impl RedrawEvents for State {
|
||||||
@ -1103,7 +1118,7 @@ impl RedrawEvents for State {
|
|||||||
impl GuiApi for State {
|
impl GuiApi for State {
|
||||||
fn set_font(&mut self, font_desc: &str) {
|
fn set_font(&mut self, font_desc: &str) {
|
||||||
self.set_font_desc(font_desc);
|
self.set_font_desc(font_desc);
|
||||||
self.request_resize();
|
self.request_nvim_resize();
|
||||||
|
|
||||||
let mut settings = self.settings.borrow_mut();
|
let mut settings = self.settings.borrow_mut();
|
||||||
settings.set_font_source(FontSource::Rpc);
|
settings.set_font_source(FontSource::Rpc);
|
||||||
|
Loading…
Reference in New Issue
Block a user