From e3bbb9366c8cf5a5474c5b134ae60e9641da3b7b Mon Sep 17 00:00:00 2001 From: Nikhil <7285903+niknbr@users.noreply.github.com> Date: Sun, 19 Nov 2023 21:05:03 +0000 Subject: [PATCH] Add window level (#116) * set window level * fmt fixes --- src/appkit/window/enums.rs | 44 ++++++++++++++++++++++++++++++++++++++ src/appkit/window/mod.rs | 15 +++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/appkit/window/enums.rs b/src/appkit/window/enums.rs index 3b1fa4c..3e0fca6 100644 --- a/src/appkit/window/enums.rs +++ b/src/appkit/window/enums.rs @@ -134,3 +134,47 @@ impl From for NSUInteger { } } } + +/// 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 c479c79..8e1d412 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) {