Skip to content

Commit

Permalink
Don't save the window size if the window is minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Nov 29, 2023
1 parent a6a6c60 commit 7211dc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
21 changes: 14 additions & 7 deletions src/settings/window_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use winit::dpi::{PhysicalPosition, PhysicalSize};

use crate::{dimensions::Dimensions, settings::SETTINGS, window::WindowSettings};
use crate::{
dimensions::Dimensions, settings::SETTINGS, window::WindowSettings, window::WinitWindowWrapper,
};

const SETTINGS_FILE: &str = "neovide-settings.json";

Expand Down Expand Up @@ -64,12 +66,17 @@ pub fn load_last_window_settings() -> Result<PersistentWindowSettings, String> {
Ok(loaded_settings)
}

pub fn save_window_size(
maximized: bool,
pixel_size: PhysicalSize<u32>,
grid_size: Dimensions,
position: Option<PhysicalPosition<i32>>,
) {
pub fn save_window_size(window_wrapper: &WinitWindowWrapper) {
let window = window_wrapper.windowed_context.window();
// Don't save the window size when the window is minimized, since the size can be 0
// Note wayland can't determine this
if matches!(window.is_minimized(), Some(true)) {
return;
}
let maximized = window.is_maximized();
let pixel_size = window.inner_size();
let grid_size = window_wrapper.get_grid_size();
let position = window.outer_position().ok();
let window_settings = SETTINGS.get::<WindowSettings>();

let settings = PersistentSettings {
Expand Down
18 changes: 3 additions & 15 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use keyboard_manager::KeyboardManager;
use mouse_manager::MouseManager;
use renderer::SkiaRenderer;
use update_loop::UpdateLoop;
use window_wrapper::WinitWindowWrapper;

use crate::{
cmd_line::{CmdLineSettings, GeometryArgs},
Expand All @@ -56,6 +55,7 @@ use crate::{
};
pub use error_window::show_error_window;
pub use settings::{WindowSettings, WindowSettingsChanged};
pub use window_wrapper::WinitWindowWrapper;

static ICON: &[u8] = include_bytes!("../../assets/neovide.ico");

Expand Down Expand Up @@ -275,13 +275,7 @@ pub fn main_loop(
}
}

let window = window_wrapper.windowed_context.window();
save_window_size(
window.is_maximized(),
window.inner_size(),
window_wrapper.get_grid_size(),
window.outer_position().ok(),
);
save_window_size(&window_wrapper);
});

let result = event_loop.run(|e, window_target| {
Expand Down Expand Up @@ -331,13 +325,7 @@ pub fn main_loop(
}

if !RUNNING_TRACKER.is_running() {
let window = window_wrapper.windowed_context.window();
save_window_size(
window.is_maximized(),
window.inner_size(),
window_wrapper.get_grid_size(),
window.outer_position().ok(),
);
save_window_size(&window_wrapper);
window_target.exit();
} else {
window_target.set_control_flow(update_loop.step(&mut window_wrapper, Ok(e)).unwrap());
Expand Down

0 comments on commit 7211dc3

Please sign in to comment.