Skip to content

Commit

Permalink
Clean up the fullscreen toggling code
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Jul 7, 2024
1 parent c604854 commit 3186c46
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/window/window_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pub struct WinitWindowWrapper {
keyboard_manager: KeyboardManager,
mouse_manager: MouseManager,
title: String,
fullscreen: bool,
font_changed_last_frame: bool,
saved_inner_size: dpi::PhysicalSize<u32>,
saved_grid_size: Option<GridSize<u32>>,
Expand Down Expand Up @@ -99,7 +98,6 @@ impl WinitWindowWrapper {
keyboard_manager: KeyboardManager::new(),
mouse_manager: MouseManager::new(),
title: String::from("Neovide"),
fullscreen: false,
font_changed_last_frame: false,
saved_inner_size,
saved_grid_size: None,
Expand All @@ -122,18 +120,16 @@ impl WinitWindowWrapper {
}
}

pub fn toggle_fullscreen(&mut self) {
pub fn set_fullscreen(&mut self, fullscreen: bool) {
if let Some(skia_renderer) = &self.skia_renderer {
let window = skia_renderer.window();
if self.fullscreen {
window.set_fullscreen(None);
} else {
if fullscreen {
let handle = window.current_monitor();
window.set_fullscreen(Some(Fullscreen::Borderless(handle)));
} else {
window.set_fullscreen(None);
}
}

self.fullscreen = !self.fullscreen;
}

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -206,9 +202,7 @@ impl WinitWindowWrapper {
self.requested_lines = lines.map(|v| v.try_into().unwrap());
}
WindowSettingsChanged::Fullscreen(fullscreen) => {
if self.fullscreen != fullscreen {
self.toggle_fullscreen();
}
self.set_fullscreen(fullscreen);
}
WindowSettingsChanged::InputIme(ime_enabled) => {
self.set_ime(ime_enabled);
Expand Down Expand Up @@ -573,7 +567,6 @@ impl WinitWindowWrapper {
if fullscreen {
let handle = window.current_monitor();
window.set_fullscreen(Some(Fullscreen::Borderless(handle)));
self.fullscreen = true;
}

match theme.as_str() {
Expand Down

0 comments on commit 3186c46

Please sign in to comment.