From 7042901712153f46ed3403c855086c087d7aca6a Mon Sep 17 00:00:00 2001 From: Nikhil <7285903+niknbr@users.noreply.github.com> Date: Sat, 18 Nov 2023 14:59:20 +0000 Subject: [PATCH 1/2] set window level --- src/appkit/window/enums.rs | 46 +++++++++++++++++++++++++++++++++++++- src/appkit/window/mod.rs | 15 +++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/appkit/window/enums.rs b/src/appkit/window/enums.rs index 3b1fa4ce..79ea1897 100644 --- a/src/appkit/window/enums.rs +++ b/src/appkit/window/enums.rs @@ -130,7 +130,51 @@ impl From for NSUInteger { WindowToolbarStyle::Expanded => 1, WindowToolbarStyle::Preferences => 2, WindowToolbarStyle::Unified => 3, - WindowToolbarStyle::UnifiedCompact => 4 + WindowToolbarStyle::UnifiedCompact => 4, + } + } +} + +/// Describe the level of the window. Stacking of window levels take precedence over stacking +/// of windows withing each level. +#[derive(Clone, Copy, Debug)] +pub enum WindowLevel { + /// The default level for NSWindow objects. + Normal, + + /// Useful for floating palettes. + Floating, + + /// The level for a modal panel. + ModalPanel, + + /// Reserved for the application’s main menu. + MainMenu, + + /// The level for a status window. + Status, + + /// The level for the dock. + DockWindow, + + /// The level for a pop-up menu. + PopUpMenu, + + /// The level for a screen saver. + ScreenSaver, +} + +impl From for NSInteger { + fn from(mode: WindowLevel) -> Self { + match mode { + WindowLevel::Normal => 0, + WindowLevel::Floating => 3, + WindowLevel::ModalPanel => 8, + WindowLevel::MainMenu => 24, + WindowLevel::Status => 25, + WindowLevel::DockWindow => 100, + WindowLevel::PopUpMenu => 101, + WindowLevel::ScreenSaver => 1000, } } } diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index c479c79b..8e1d412a 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -312,6 +312,21 @@ impl Window { } } + /// Sets the window level, which determines the stacking order of windows on the screen. + pub fn set_level(&self, value: WindowLevel) { + let value: NSInteger = value.into(); + unsafe { + let _: () = msg_send![&*self.objc, setLevel: value]; + } + } + + /// Removes window from the screen making it effectively hidden. + pub fn order_out(&self) { + unsafe { + let _: () = msg_send![&*self.objc, orderOut: nil]; + } + } + /// Set whether the toolbar toggle button is shown. Has no effect if no toolbar exists on this /// window. pub fn set_shows_toolbar_button(&self, shows: bool) { From d5e46eb37071d2ca65c8746b82f2371985603ba1 Mon Sep 17 00:00:00 2001 From: Nikhil <7285903+niknbr@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:46:25 +0000 Subject: [PATCH 2/2] fmt fixes --- src/appkit/window/enums.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/appkit/window/enums.rs b/src/appkit/window/enums.rs index 79ea1897..3e0fca6c 100644 --- a/src/appkit/window/enums.rs +++ b/src/appkit/window/enums.rs @@ -130,7 +130,7 @@ impl From for NSUInteger { WindowToolbarStyle::Expanded => 1, WindowToolbarStyle::Preferences => 2, WindowToolbarStyle::Unified => 3, - WindowToolbarStyle::UnifiedCompact => 4, + WindowToolbarStyle::UnifiedCompact => 4 } } } @@ -161,7 +161,7 @@ pub enum WindowLevel { PopUpMenu, /// The level for a screen saver. - ScreenSaver, + ScreenSaver } impl From for NSInteger { @@ -174,7 +174,7 @@ impl From for NSInteger { WindowLevel::Status => 25, WindowLevel::DockWindow => 100, WindowLevel::PopUpMenu => 101, - WindowLevel::ScreenSaver => 1000, + WindowLevel::ScreenSaver => 1000 } } }