From 163606afec423c33a118d59086de58b9bad896a6 Mon Sep 17 00:00:00 2001 From: rawnly Date: Sat, 2 Dec 2023 08:30:29 +0100 Subject: [PATCH] fix: moved window level state update --- config/src/window.rs | 17 ++++++++++++ wezterm-gui/src/termwindow/mod.rs | 45 +++---------------------------- window/src/os/macos/window.rs | 25 ++++++++++++----- 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/config/src/window.rs b/config/src/window.rs index 121b76d0c..031e5c42c 100644 --- a/config/src/window.rs +++ b/config/src/window.rs @@ -7,3 +7,20 @@ pub enum WindowLevel { Normal = 0, AlwaysOnTop = 3, } + +impl Default for WindowLevel { + fn default() -> Self { + WindowLevel::Normal + } +} + +impl From for WindowLevel { + fn from(level: i64) -> Self { + match level { + -1 => WindowLevel::AlwaysOnBottom, + 0 => WindowLevel::Normal, + 3 => WindowLevel::AlwaysOnTop, + _ => panic!("Invalid window level: {}", level), + } + } +} diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 648f76eda..fa9913331 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -2514,16 +2514,9 @@ impl TermWindow { match current_level { WindowLevel::AlwaysOnTop => { - self.window_state -= WindowState::ALWAYS_ON_TOP; window.set_window_level(WindowLevel::Normal); } - WindowLevel::AlwaysOnBottom => { - self.window_state -= WindowState::ALWAYS_ON_BOTTOM; - self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP; - window.set_window_level(WindowLevel::AlwaysOnTop); - } - WindowLevel::Normal => { - self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP; + WindowLevel::AlwaysOnBottom | WindowLevel::Normal => { window.set_window_level(WindowLevel::AlwaysOnTop); } } @@ -2533,49 +2526,17 @@ impl TermWindow { let current_level = self.window_state.as_window_level(); match current_level { - WindowLevel::AlwaysOnTop => { - self.window_state -= WindowState::ALWAYS_ON_TOP; - self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM; - window.set_window_level(WindowLevel::AlwaysOnBottom); - } WindowLevel::AlwaysOnBottom => { - self.window_state -= WindowState::ALWAYS_ON_BOTTOM; window.set_window_level(WindowLevel::Normal); } - WindowLevel::Normal => { - self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM; + WindowLevel::AlwaysOnTop | WindowLevel::Normal => { window.set_window_level(WindowLevel::AlwaysOnBottom); } } } SetWindowLevel(level) => { let window = self.window.clone().unwrap(); - let current_level = self.window_state.as_window_level(); - - // reset level state if needed - match current_level { - WindowLevel::AlwaysOnTop => { - self.window_state -= WindowState::ALWAYS_ON_TOP; - } - WindowLevel::AlwaysOnBottom => { - self.window_state -= WindowState::ALWAYS_ON_BOTTOM; - } - _ => {} - } - - match level { - WindowLevel::AlwaysOnTop => { - window.set_window_level(WindowLevel::AlwaysOnTop); - self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP; - } - WindowLevel::AlwaysOnBottom => { - window.set_window_level(WindowLevel::AlwaysOnBottom); - self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM; - } - WindowLevel::Normal => { - window.set_window_level(WindowLevel::Normal); - } - } + window.set_window_level(level.clone()); }, CopyTo(dest) => { let text = self.selection_text(pane); diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 459e8ccc2..0cf551342 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1160,12 +1160,15 @@ impl WindowInner { } fn set_window_level(&mut self, level: WindowLevel) { + unsafe { NSWindow::setLevel_(*self.window, match level { WindowLevel::AlwaysOnBottom => -1, WindowLevel::Normal => 0, WindowLevel::AlwaysOnTop => 3, }); + + WindowView::did_resize(&mut** self.view, sel!(windowDidResize:), nil); } } @@ -2772,6 +2775,20 @@ impl WindowView { unsafe { msg_send![*window, isZoomed] } }); + let window_level = inner.window.as_ref().map_or(WindowLevel::Normal, |w| unsafe { w.load().level().into() }); + + let level_state = match window_level { + WindowLevel::AlwaysOnBottom => WindowState::ALWAYS_ON_BOTTOM, + WindowLevel::AlwaysOnTop => WindowState::ALWAYS_ON_TOP, + WindowLevel::Normal => WindowState::default(), + }; + + let screen_state = match (is_full_screen, is_zoomed) { + (true, _) => WindowState::FULL_SCREEN, + (_, true) => WindowState::MAXIMIZED, + _ => WindowState::default(), + }; + let dpi = inner .window .as_ref() @@ -2788,13 +2805,7 @@ impl WindowView { pixel_height: height as usize, dpi, }, - window_state: if is_full_screen { - WindowState::FULL_SCREEN - } else if is_zoomed { - WindowState::MAXIMIZED - } else { - WindowState::default() - }, + window_state: screen_state | level_state, live_resizing, }); }