From 86e42e1c58fdb9045f83e3fed12ca2d83bf16857 Mon Sep 17 00:00:00 2001 From: Federico Vitale Date: Tue, 28 Nov 2023 00:24:58 +0100 Subject: [PATCH] macos: refactor `set_window_level` --- wezterm-gui/src/termwindow/mod.rs | 1 - window/src/lib.rs | 7 ++++--- window/src/os/macos/window.rs | 22 +++++++++------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 9e9d0680d..919019aa4 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -2507,7 +2507,6 @@ impl TermWindow { ToggleFullScreen => { self.window.as_ref().unwrap().toggle_fullscreen(); } - #[cfg(target_os = "macos")] ToggleFloatingWindow => { let window = self.window.clone().unwrap(); diff --git a/window/src/lib.rs b/window/src/lib.rs index 21d1f10c0..fb35eea20 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -294,9 +294,10 @@ pub trait WindowOps { /// Set some text in the clipboard fn set_clipboard(&self, clipboard: Clipboard, text: String); - /// Set window level (macos only!) - fn set_level(&self, level: WindowLevel); - + /// Set window level. Depending on the environment and user preferences + fn set_window_level(&self, level: WindowLevel) { + // default implementation does nothing + } /// Set the icon for the window. /// Depending on the system this may be shown in its titlebar diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 841958dc5..13e977625 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -745,7 +745,7 @@ impl WindowOps for Window { }); } - fn set_level(&self, level: WindowLevel) { + fn set_window_level(&self, level: WindowLevel) { Connection::with_window_inner(self.id, move |inner| { inner.set_level(level as i64); Ok(()) @@ -1081,19 +1081,11 @@ impl WindowInner { #[derive(Debug)] pub enum WindowLevel { + AlwaysOnBottom = -1, Normal = 0, - Floating = 22, + AlwaysOnTop = 3, } -impl From for WindowLevel { - fn from(value: i64) -> Self { - match value { - int_value if int_value == Self::Floating as i64 => Self::Floating, - int_value if int_value == Self::Normal as i64 => Self::Normal, - _ => Self::Normal, - } - } -} impl WindowInner { fn show(&mut self) { @@ -1175,9 +1167,13 @@ impl WindowInner { } } - fn set_level(&mut self, level: i64) { + fn set_level(&mut self, level: WindowLevel) { unsafe { - NSWindow::setLevel_(*self.window, level); + NSWindow::setLevel_(*self.window, match level { + WindowLevel::AlwaysOnBottom => -1, + WindowLevel::Normal => 0, + WindowLevel::AlwaysOnTop => 3, + }); } }