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 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::<WindowSettings>().remember_window_size {
let (width, height) = grid_size;
WindowGeometry { width, height }
pub fn maybe_save_window_size(grid_size: Option<WindowGeometry>) {
let settings = SETTINGS.get::<WindowSettings>();
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,

@ -52,9 +52,8 @@ pub struct GlutinWindowWrapper {
mouse_manager: MouseManager,
title: String,
fullscreen: bool,
first_render_pass: bool,
saved_inner_size: PhysicalSize<u32>,
saved_grid_size: (u64, u64),
saved_grid_size: Option<WindowGeometry>,
ui_command_sender: LoggingTx<UiCommand>,
window_command_receiver: Receiver<WindowCommand>,
}
@ -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::<CmdLineSettings>().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<u32>) {
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::<CmdLineSettings>().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,
};

Loading…
Cancel
Save