From 725f12cafd4a26babd0d6bbcbca9a99c181991ac Mon Sep 17 00:00:00 2001 From: Serg Tereshchenko Date: Sun, 8 Aug 2021 09:23:29 +0300 Subject: [PATCH] refactor: Remove first_render_pass flag --- src/settings/window_geometry.rs | 24 +++++++++++++++--------- src/window/window_wrapper/mod.rs | 28 +++++++++++++--------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/settings/window_geometry.rs b/src/settings/window_geometry.rs index 8f11037..2166afc 100644 --- a/src/settings/window_geometry.rs +++ b/src/settings/window_geometry.rs @@ -3,16 +3,22 @@ use crate::window::WindowSettings; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[cfg(unix)] +const SETTINGS_PATH: &str = ".local/share/nvim/neovide-settings.json"; +#[cfg(windows)] +const SETTINGS_PATH: &str = "AppData/Local/nvim-data/neovide-settings.json"; + +#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] pub struct WindowGeometry { pub width: u64, pub height: u64, } -#[cfg(unix)] -const SETTINGS_PATH: &str = ".local/share/nvim/neovide-settings.json"; -#[cfg(windows)] -const SETTINGS_PATH: &str = "AppData/Local/nvim-data/neovide-settings.json"; +impl From<(u64, u64)> for WindowGeometry { + fn from((width, height): (u64, u64)) -> Self { + WindowGeometry { width, height } + } +} fn neovim_std_datapath() -> PathBuf { let mut settings_path = dirs::home_dir().unwrap(); @@ -34,10 +40,10 @@ pub const DEFAULT_WINDOW_GEOMETRY: WindowGeometry = WindowGeometry { height: 50, }; -pub fn maybe_save_window_size(grid_size: (u64, u64)) { - let saved_window_size = if SETTINGS.get::().remember_window_size { - let (width, height) = grid_size; - WindowGeometry { width, height } +pub fn maybe_save_window_size(grid_size: Option) { + let settings = SETTINGS.get::(); + let saved_window_size = if settings.remember_window_size && grid_size.is_some() { + grid_size.unwrap() } else { WindowGeometry { width: DEFAULT_WINDOW_GEOMETRY.width as u64, diff --git a/src/window/window_wrapper/mod.rs b/src/window/window_wrapper/mod.rs index f23c7fa..d96c4ec 100644 --- a/src/window/window_wrapper/mod.rs +++ b/src/window/window_wrapper/mod.rs @@ -52,9 +52,8 @@ pub struct GlutinWindowWrapper { mouse_manager: MouseManager, title: String, fullscreen: bool, - first_render_pass: bool, saved_inner_size: PhysicalSize, - saved_grid_size: (u64, u64), + saved_grid_size: Option, ui_command_sender: LoggingTx, window_command_receiver: Receiver, } @@ -176,11 +175,10 @@ impl GlutinWindowWrapper { return; } - if self.first_render_pass { - self.first_render_pass = false; - if !window.is_maximized() { - window.set_inner_size(self.renderer.to_physical_size(self.saved_grid_size)); - } + if self.saved_grid_size.is_none() && !window.is_maximized() { + let size = SETTINGS.get::().geometry; + window.set_inner_size(self.renderer.to_physical_size((size.width, size.height))); + self.saved_grid_size = Some(size); } let new_size = window.inner_size(); @@ -193,14 +191,17 @@ impl GlutinWindowWrapper { } fn handle_new_grid_size(&mut self, new_size: PhysicalSize) { - let (width, height) = self.renderer.to_grid_size(new_size); - if self.saved_grid_size == (width, height) { + let grid_size: WindowGeometry = self.renderer.to_grid_size(new_size).into(); + if self.saved_grid_size == Some(grid_size) { trace!("Grid matched saved size, skip update."); return; } - self.saved_grid_size = (width, height); + self.saved_grid_size = Some(grid_size); self.ui_command_sender - .send(UiCommand::Resize { width, height }) + .send(UiCommand::Resize { + width: grid_size.width, + height: grid_size.height, + }) .ok(); } @@ -268,8 +269,6 @@ pub fn create_window( renderer.font_height, ); - let WindowGeometry { width, height } = SETTINGS.get::().geometry; - let mut window_wrapper = GlutinWindowWrapper { windowed_context, skia_renderer, @@ -278,9 +277,8 @@ pub fn create_window( mouse_manager: MouseManager::new(ui_command_sender.clone()), title: String::from("Neovide"), fullscreen: false, - first_render_pass: true, saved_inner_size, - saved_grid_size: (width, height), + saved_grid_size: None, ui_command_sender, window_command_receiver, };