Add Window::set_window_level API
This adds `Window::set_window_level` to control the preferred z level of the window. Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com> Co-authored-by: Kirill Chibisov <contact@kchibisov.com> Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
ba4bf03675
commit
101ac8908c
12 changed files with 142 additions and 82 deletions
|
|
@ -296,6 +296,8 @@ pub struct NSWindowLevel(pub NSInteger);
|
|||
|
||||
#[allow(dead_code)]
|
||||
impl NSWindowLevel {
|
||||
#[doc(alias = "BelowNormalWindowLevel")]
|
||||
pub const BELOW_NORMAL: Self = Self((kCGNormalWindowLevel - 1) as _);
|
||||
#[doc(alias = "NSNormalWindowLevel")]
|
||||
pub const Normal: Self = Self(kCGNormalWindowLevel as _);
|
||||
#[doc(alias = "NSFloatingWindowLevel")]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use crate::{
|
|||
},
|
||||
window::{
|
||||
CursorGrabMode, CursorIcon, Theme, UserAttentionType, WindowAttributes,
|
||||
WindowId as RootWindowId,
|
||||
WindowId as RootWindowId, WindowLevel,
|
||||
},
|
||||
};
|
||||
use core_graphics::display::{CGDisplay, CGPoint};
|
||||
|
|
@ -333,10 +333,6 @@ impl WinitWindow {
|
|||
this.setMovableByWindowBackground(true);
|
||||
}
|
||||
|
||||
if attrs.always_on_top {
|
||||
this.setLevel(NSWindowLevel::Floating);
|
||||
}
|
||||
|
||||
if let Some(increments) = attrs.resize_increments {
|
||||
let increments = increments.to_logical(this.scale_factor());
|
||||
let (w, h) = (increments.width, increments.height);
|
||||
|
|
@ -394,6 +390,8 @@ impl WinitWindow {
|
|||
this.set_max_inner_size(Some(dim));
|
||||
}
|
||||
|
||||
this.set_window_level(attrs.window_level);
|
||||
|
||||
// register for drag and drop operations.
|
||||
this.registerForDraggedTypes(&NSArray::from_slice(&[
|
||||
unsafe { NSFilenamesPboardType }.copy()
|
||||
|
|
@ -1019,11 +1017,11 @@ impl WinitWindow {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_always_on_top(&self, always_on_top: bool) {
|
||||
let level = if always_on_top {
|
||||
NSWindowLevel::Floating
|
||||
} else {
|
||||
NSWindowLevel::Normal
|
||||
pub fn set_window_level(&self, level: WindowLevel) {
|
||||
let level = match level {
|
||||
WindowLevel::AlwaysOnTop => NSWindowLevel::Floating,
|
||||
WindowLevel::AlwaysOnBottom => NSWindowLevel::BELOW_NORMAL,
|
||||
WindowLevel::Normal => NSWindowLevel::Normal,
|
||||
};
|
||||
util::set_level_async(self, level);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue