Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Ignore window size when minimized #2153

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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
42 changes: 25 additions & 17 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod draw_background;
use std::env;

use winit::{
dpi::PhysicalSize,
dpi::{PhysicalSize, Size},
error::EventLoopError,
event::Event,
event_loop::{EventLoop, EventLoopBuilder},
Expand Down 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,13 +55,22 @@ 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");

const DEFAULT_WINDOW_SIZE: PhysicalSize<u32> = PhysicalSize {
width: 500,
height: 500,
};
const MIN_PERSISTEN_WINDOW_SIZE: PhysicalSize<u32> = PhysicalSize {
width: 300,
height: 150,
};
const MAX_PERSISTENT_WINDOW_SIZE: PhysicalSize<u32> = PhysicalSize {
width: 8192,
height: 8192,
};

#[derive(Clone, Debug)]
pub enum WindowCommand {
Expand Down Expand Up @@ -219,7 +227,19 @@ pub fn determine_window_size(window_settings: Option<&PersistentWindowSettings>)
Some(PersistentWindowSettings::Windowed {
pixel_size: Some(pixel_size),
..
}) => WindowSize::Size(*pixel_size),
}) => {
let size = Size::new(*pixel_size);
let scale = 1.0;
WindowSize::Size(
Size::clamp(
size,
MIN_PERSISTEN_WINDOW_SIZE.into(),
MAX_PERSISTENT_WINDOW_SIZE.into(),
scale,
)
.to_physical(scale),
)
}
_ => WindowSize::Size(DEFAULT_WINDOW_SIZE),
},
}
Expand Down Expand Up @@ -255,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 @@ -311,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
4 changes: 3 additions & 1 deletion src/window/window_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ impl WinitWindowWrapper {

// Make the window Visible only after the size is adjusted
self.windowed_context.window().set_visible(true);
} else {
} else if self.windowed_context.window().is_minimized() != Some(true) {
// NOTE: Only actually resize the grid when the window is not minimized
// Some platforms return a zero size when that is the case, so we should not try to resize to that.
let new_size = self.windowed_context.window().inner_size();
if self.saved_inner_size != new_size || self.font_changed_last_frame || padding_changed
{
Expand Down