GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix: simplify and improve fullscreen detection (#1298)
Lars Bergercbc7f6aa885d
diff --git a/packages/wm/src/events/handle_window_moved_or_resized.rs b/packages/wm/src/events/handle_window_moved_or_resized.rsindex dd36f966..18239deb 100644--- a/packages/wm/src/events/handle_window_moved_or_resized.rs+++ b/packages/wm/src/events/handle_window_moved_or_resized.rs@@ -225,14 +225,71 @@ pub fn handle_window_moved_or_resized(}}- let should_fullscreen = window.should_fullscreen(- &nearest_monitor+ let should_fullscreen = {+ let workspace = nearest_monitor.displayed_workspace()- .context("No workspace.")?,- )?;+ .context("No workspace.")?;++ let should_fullscreen = window.should_fullscreen(&workspace)?;++ match window.state() {+ // Override the fullscreen check for when an app self-exits+ // fullscreen (e.g. Chrome via F11) and restores its window to+ // a position that exactly covers the workspace rect.+ WindowState::Fullscreen(fullscreen)+ if !fullscreen.maximized && should_fullscreen =>+ {+ let workspace_rect = workspace.max_workspace_rect()?;++ let old_frame = old_frame_position+ .apply_delta(&window.border_delta().inverse(), None);+ let new_frame = frame_position+ .apply_delta(&window.border_delta().inverse(), None);++ let old_exceeded =+ old_frame.inset(1).contains_rect(&workspace_rect);+ let new_exceeds =+ new_frame.inset(1).contains_rect(&workspace_rect);++ // The window should no longer be fullscreen if the old frame+ // exceeded the workspace bounds (app was in OS fullscreen), but+ // the new frame no longer does. Configs with 0px outer gaps+ // always use the `should_fullscreen` check, since the old frame+ // will never exceed the workspace bounds.+ if old_exceeded && !new_exceeds {+ false+ } else {+ should_fullscreen+ }+ }+ _ => should_fullscreen,+ }+ };// Handle a window being maximized or entering fullscreen.if is_maximized || should_fullscreen {+ let is_same_state = is_maximized+ && matches!(+ window.state(),+ WindowState::Fullscreen(FullscreenStateConfig {+ maximized: true,+ ..+ })+ )+ || should_fullscreen+ && matches!(+ window.state(),+ WindowState::Fullscreen(FullscreenStateConfig {+ maximized: false,+ ..+ })+ );++ // Ignore if there's no state change.+ if is_same_state {+ return Ok(());+ }+let fullscreen_state = if let WindowState::Fullscreen(fullscreen_state,) = window.state()@@ -247,7 +304,7 @@ pub fn handle_window_moved_or_resized(.clone()};- update_window_state(+ let window = update_window_state(window.clone(),WindowState::Fullscreen(FullscreenStateConfig {maximized: is_maximized,@@ -263,10 +320,6 @@ pub fn handle_window_moved_or_resized(state.pending_sync.dequeue_container_from_redraw(window.clone());- } else {- // Force a redraw to snap the window to the monitor edges.- // TODO: Skip redraw if it's already matches fullscreen frame.- state.pending_sync.queue_container_to_redraw(window.clone());}// TODO: Handle a fullscreen window being moved from one monitor todiff --git a/packages/wm/src/traits/window_getters.rs b/packages/wm/src/traits/window_getters.rsindex e08c6d80..dc7db886 100644--- a/packages/wm/src/traits/window_getters.rs+++ b/packages/wm/src/traits/window_getters.rs@@ -103,25 +103,25 @@ pub trait WindowGetters: CommonGetters {&self,workspace: &Workspace,) -> anyhow::Result<bool> {- let frame = self.native_properties().frame;let workspace_rect = workspace.max_workspace_rect()?;+ let frame = self+ .native_properties()+ .frame+ .apply_delta(&self.border_delta().inverse(), None);++ let should_fullscreen = match self.state() {+ // Keep as fullscreen if the frame covers the workspace bounds.+ WindowState::Fullscreen(fullscreen) if !fullscreen.maximized => {+ frame.contains_rect(&workspace_rect.inset(1))+ }++ // Change to fullscreen if the frame *exceeds* the workspace bounds.+ // NOTE: This is never possible with 0px outer gaps; the window has+ // to be made fullscreen via the `set-fullscreen` command.+ _ => frame.inset(1).contains_rect(&workspace_rect),+ };- // Check if the window frame covers the workspace bounds (with 1px of- // leeway).- let is_covering = frame.contains_rect(&workspace_rect.inset(1));-- // A workspace with one tiling window will have that window cover the- // workspace bounds, but it should not be considered fullscreen. This- // check is also valid for fullscreen windows that have just been- // restored.- let is_single_window_occupying_workspace =- matches!(- self.state(),- WindowState::Tiling | WindowState::Fullscreen(_)- ) && self.tiling_siblings().count() == 0- && workspace_rect.inset(-1).contains_rect(&frame);-- Ok(is_covering && !is_single_window_occupying_workspace)+ Ok(should_fullscreen)}fn display_state(&self) -> DisplayState;