Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: minimize native window in `toggle_window_state`

Lars Berger64504edbd649
diff --git a/packages/wm/src/common/events/handle_window_minimize_ended.rs b/packages/wm/src/common/events/handle_window_minimize_ended.rs
index 7afabe6d..3479fe35 100644
--- a/packages/wm/src/common/events/handle_window_minimize_ended.rs
+++ b/packages/wm/src/common/events/handle_window_minimize_ended.rs
@@ -21,6 +21,7 @@ pub fn handle_window_minimize_ended(
if window.state() == WindowState::Minimized {
// TODO: Log window details.
info!("Window minimize ended");
+ // TODO: Should use previous state here.
toggle_window_state(window, WindowState::Minimized, state, config)?;
}
}
diff --git a/packages/wm/src/windows/commands/toggle_window_state.rs b/packages/wm/src/windows/commands/toggle_window_state.rs
index 13faae7e..bfb89350 100644
--- a/packages/wm/src/windows/commands/toggle_window_state.rs
+++ b/packages/wm/src/windows/commands/toggle_window_state.rs
@@ -10,39 +10,34 @@ use super::update_window_state;
/// Toggles the state of a window between its previous state if the window
/// has one, or tiling if it does not.
///
-/// Always adds the window for redraw.
+/// Unlike `update_window_state`, this will always add the window for
+/// redraw.
pub fn toggle_window_state(
window: WindowContainer,
- window_state: WindowState,
+ target_window_state: WindowState,
state: &mut WmState,
config: &UserConfig,
) -> anyhow::Result<()> {
- // If the window is not currently in the given state, then update it to
- // the given state. Otherwise, revert to the window's previous state. If
- // the window doesn't have a previous state, it's updated to be tiling.
- if window.state() != window_state {
- update_window_state(window.clone(), window_state, state, config)?;
- } else {
- match window.prev_state() {
- Some(prev_state) => {
- update_window_state(window.clone(), prev_state, state, config)
- }
- None if window.state() != WindowState::Tiling => {
- update_window_state(
- window.clone(),
- WindowState::Tiling,
- state,
- config,
- )
- }
- None => Ok(()),
- }?;
- }
+ let toggled_window_state = match window.state() == target_window_state {
+ true => window.prev_state().unwrap_or(WindowState::Tiling),
+ false => target_window_state,
+ };
- // The `update_window_state` call will already add the window for redraw
- // on tiling <-> non-tiling state changes. However, on toggle, we always
- // want to add the window for redraw.
- state.pending_sync.containers_to_redraw.push(window.into());
+ match toggled_window_state {
+ WindowState::Minimized => window.native().minimize(),
+ _ => {
+ update_window_state(
+ window.clone(),
+ toggled_window_state,
+ state,
+ config,
+ )?;
- Ok(())
+ // The `update_window_state` call will already add the window for redraw
+ // on tiling <-> non-tiling state changes. However, on toggle, we always
+ // want to add the window for redraw.
+ state.pending_sync.containers_to_redraw.push(window.into());
+ Ok(())
+ }
+ }
}