From 6b9cbbaa3141db99228cf321e941220bb0701f95 Mon Sep 17 00:00:00 2001 From: mgalos999 Date: Sat, 24 Sep 2022 03:17:02 +1000 Subject: [PATCH] always_on_top for WindowBuilder --- CHANGELOG.md | 2 ++ druid-shell/src/backend/gtk/window.rs | 4 ++++ druid-shell/src/backend/mac/window.rs | 4 ++++ druid-shell/src/backend/wayland/window.rs | 6 ++++++ druid-shell/src/backend/web/window.rs | 4 ++++ druid-shell/src/backend/windows/window.rs | 10 ++++++++++ druid-shell/src/backend/x11/window.rs | 4 ++++ druid-shell/src/window.rs | 5 +++++ 8 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 536c8979ed..6acc046db6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ You can find its changes [documented below](#070---2021-01-01). ## Unreleased +- Always on top setting for WindowBuilder ([#2265] by [@mgalos999]) + ### Highlights - International text input support (IME) on macOS. diff --git a/druid-shell/src/backend/gtk/window.rs b/druid-shell/src/backend/gtk/window.rs index 1622c44328..5c5b5c9d4e 100644 --- a/druid-shell/src/backend/gtk/window.rs +++ b/druid-shell/src/backend/gtk/window.rs @@ -261,6 +261,10 @@ impl WindowBuilder { self.transparent = transparent; } + pub fn set_always_on_top(&mut self, _always_on_top: bool) { + tracing::warn!("set_always_on_top unimplemented for gtk"); + } + pub fn set_position(&mut self, position: Point) { self.position = Some(position); } diff --git a/druid-shell/src/backend/mac/window.rs b/druid-shell/src/backend/mac/window.rs index a3b18cf1a9..92fbfd40c6 100644 --- a/druid-shell/src/backend/mac/window.rs +++ b/druid-shell/src/backend/mac/window.rs @@ -225,6 +225,10 @@ impl WindowBuilder { self.transparent = transparent; } + pub fn set_always_on_top(&mut self, _always_on_top: bool) { + tracing::warn!("set_always_on_top unimplemented for mac"); + } + pub fn set_level(&mut self, level: WindowLevel) { self.level = Some(level); } diff --git a/druid-shell/src/backend/wayland/window.rs b/druid-shell/src/backend/wayland/window.rs index 7cf928d69c..76b69c756a 100644 --- a/druid-shell/src/backend/wayland/window.rs +++ b/druid-shell/src/backend/wayland/window.rs @@ -380,6 +380,12 @@ impl WindowBuilder { ); } + pub fn set_always_on_top(&mut self, _always_on_top: bool) { + tracing::warn!( + "set_always_on_top unimplemented for wayland" + ); + } + pub fn set_position(&mut self, position: Point) { self.position = Some(position); } diff --git a/druid-shell/src/backend/web/window.rs b/druid-shell/src/backend/web/window.rs index aac18117c3..f130940f10 100644 --- a/druid-shell/src/backend/web/window.rs +++ b/druid-shell/src/backend/web/window.rs @@ -392,6 +392,10 @@ impl WindowBuilder { // Ignored } + pub fn set_always_on_top(&mut self, _always_on_top: bool) { + // Ignored + } + pub fn set_position(&mut self, _position: Point) { // Ignored } diff --git a/druid-shell/src/backend/windows/window.rs b/druid-shell/src/backend/windows/window.rs index 5c87adbad9..9aae642109 100644 --- a/druid-shell/src/backend/windows/window.rs +++ b/druid-shell/src/backend/windows/window.rs @@ -96,6 +96,7 @@ pub(crate) struct WindowBuilder { show_titlebar: bool, size: Option, transparent: bool, + always_on_top: bool, min_size: Option, position: Option, level: Option, @@ -1281,6 +1282,7 @@ impl WindowBuilder { resizable: true, show_titlebar: true, transparent: false, + always_on_top: false, present_strategy: Default::default(), size: None, min_size: None, @@ -1324,6 +1326,10 @@ impl WindowBuilder { } } + pub fn set_always_on_top(&mut self, always_on_top: bool) { + self.always_on_top = always_on_top; + } + pub fn set_title>(&mut self, title: S) { self.title = title.into(); } @@ -1470,6 +1476,10 @@ impl WindowBuilder { dwExStyle |= WS_EX_NOREDIRECTIONBITMAP; } + if self.always_on_top { + dwExStyle |= WS_EX_TOPMOST; + } + match self.state { window::WindowState::Maximized => dwStyle |= WS_MAXIMIZE, window::WindowState::Minimized => dwStyle |= WS_MINIMIZE, diff --git a/druid-shell/src/backend/x11/window.rs b/druid-shell/src/backend/x11/window.rs index 2d4c0f87a3..bbb8fea4a4 100644 --- a/druid-shell/src/backend/x11/window.rs +++ b/druid-shell/src/backend/x11/window.rs @@ -169,6 +169,10 @@ impl WindowBuilder { self.transparent = transparent; } + pub fn set_always_on_top(&mut self, _always_on_top: bool) { + warn!("WindowBuilder::set_always_on_top is currently unimplemented for X11 backend."); + } + pub fn set_position(&mut self, position: Point) { self.position = Some(position); } diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index 7e0c2636c8..4f8b69773e 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -484,6 +484,11 @@ impl WindowBuilder { self.0.set_transparent(transparent) } + /// Set whether the window is always on top + pub fn set_always_on_top(&mut self, always_on_top: bool) { + self.0.set_always_on_top(always_on_top) + } + /// Sets the initial window position in display points. /// For windows with a parent, the position is relative to the parent. /// For windows without a parent, it is relative to the origin of the virtual screen.