refactor: Remove first_render_pass flag

macos-click-through
Serg Tereshchenko 3 years ago committed by Keith Simmons
parent a8c6e1707b
commit 725f12cafd

@ -3,16 +3,22 @@ use crate::window::WindowSettings;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; 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 struct WindowGeometry {
pub width: u64, pub width: u64,
pub height: u64, pub height: u64,
} }
#[cfg(unix)] impl From<(u64, u64)> for WindowGeometry {
const SETTINGS_PATH: &str = ".local/share/nvim/neovide-settings.json"; fn from((width, height): (u64, u64)) -> Self {
#[cfg(windows)] WindowGeometry { width, height }
const SETTINGS_PATH: &str = "AppData/Local/nvim-data/neovide-settings.json"; }
}
fn neovim_std_datapath() -> PathBuf { fn neovim_std_datapath() -> PathBuf {
let mut settings_path = dirs::home_dir().unwrap(); let mut settings_path = dirs::home_dir().unwrap();
@ -34,10 +40,10 @@ pub const DEFAULT_WINDOW_GEOMETRY: WindowGeometry = WindowGeometry {
height: 50, height: 50,
}; };
pub fn maybe_save_window_size(grid_size: (u64, u64)) { pub fn maybe_save_window_size(grid_size: Option<WindowGeometry>) {
let saved_window_size = if SETTINGS.get::<WindowSettings>().remember_window_size { let settings = SETTINGS.get::<WindowSettings>();
let (width, height) = grid_size; let saved_window_size = if settings.remember_window_size && grid_size.is_some() {
WindowGeometry { width, height } grid_size.unwrap()
} else { } else {
WindowGeometry { WindowGeometry {
width: DEFAULT_WINDOW_GEOMETRY.width as u64, width: DEFAULT_WINDOW_GEOMETRY.width as u64,

@ -52,9 +52,8 @@ pub struct GlutinWindowWrapper {
mouse_manager: MouseManager, mouse_manager: MouseManager,
title: String, title: String,
fullscreen: bool, fullscreen: bool,
first_render_pass: bool,
saved_inner_size: PhysicalSize<u32>, saved_inner_size: PhysicalSize<u32>,
saved_grid_size: (u64, u64), saved_grid_size: Option<WindowGeometry>,
ui_command_sender: LoggingTx<UiCommand>, ui_command_sender: LoggingTx<UiCommand>,
window_command_receiver: Receiver<WindowCommand>, window_command_receiver: Receiver<WindowCommand>,
} }
@ -176,11 +175,10 @@ impl GlutinWindowWrapper {
return; return;
} }
if self.first_render_pass { if self.saved_grid_size.is_none() && !window.is_maximized() {
self.first_render_pass = false; let size = SETTINGS.get::<CmdLineSettings>().geometry;
if !window.is_maximized() { window.set_inner_size(self.renderer.to_physical_size((size.width, size.height)));
window.set_inner_size(self.renderer.to_physical_size(self.saved_grid_size)); self.saved_grid_size = Some(size);
}
} }
let new_size = window.inner_size(); let new_size = window.inner_size();
@ -193,14 +191,17 @@ impl GlutinWindowWrapper {
} }
fn handle_new_grid_size(&mut self, new_size: PhysicalSize<u32>) { fn handle_new_grid_size(&mut self, new_size: PhysicalSize<u32>) {
let (width, height) = self.renderer.to_grid_size(new_size); let grid_size: WindowGeometry = self.renderer.to_grid_size(new_size).into();
if self.saved_grid_size == (width, height) { if self.saved_grid_size == Some(grid_size) {
trace!("Grid matched saved size, skip update."); trace!("Grid matched saved size, skip update.");
return; return;
} }
self.saved_grid_size = (width, height); self.saved_grid_size = Some(grid_size);
self.ui_command_sender self.ui_command_sender
.send(UiCommand::Resize { width, height }) .send(UiCommand::Resize {
width: grid_size.width,
height: grid_size.height,
})
.ok(); .ok();
} }
@ -268,8 +269,6 @@ pub fn create_window(
renderer.font_height, renderer.font_height,
); );
let WindowGeometry { width, height } = SETTINGS.get::<CmdLineSettings>().geometry;
let mut window_wrapper = GlutinWindowWrapper { let mut window_wrapper = GlutinWindowWrapper {
windowed_context, windowed_context,
skia_renderer, skia_renderer,
@ -278,9 +277,8 @@ pub fn create_window(
mouse_manager: MouseManager::new(ui_command_sender.clone()), mouse_manager: MouseManager::new(ui_command_sender.clone()),
title: String::from("Neovide"), title: String::from("Neovide"),
fullscreen: false, fullscreen: false,
first_render_pass: true,
saved_inner_size, saved_inner_size,
saved_grid_size: (width, height), saved_grid_size: None,
ui_command_sender, ui_command_sender,
window_command_receiver, window_command_receiver,
}; };

Loading…
Cancel
Save