Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an AlwaysOnTop window level #1818

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,14 @@ impl WindowHandle {
WindowLevel::Tooltip => WindowTypeHint::Tooltip,
WindowLevel::DropDown => WindowTypeHint::DropdownMenu,
WindowLevel::Modal => WindowTypeHint::Dialog,
WindowLevel::AlwaysOnTop => WindowTypeHint::Normal,
};

state.window.set_type_hint(hint);
}

self.set_override_redirect(level);
self.set_keep_above(level);
}

/// The override-redirect flag tells the window manager not to mess with the window; it should
Expand All @@ -930,6 +932,19 @@ impl WindowHandle {
}
}

fn set_keep_above(&self, level: WindowLevel) {
let keep_above = match level {
WindowLevel::AlwaysOnTop => true,
_ => false
};

if let Some(state) = self.state.upgrade() {
if let Some(window) = state.window.get_window() {
window.set_keep_above(keep_above);
}
}
}

pub fn set_size(&self, size: Size) {
if let Some(state) = self.state.upgrade() {
let px = size.to_px(state.scale.get());
Expand Down
1 change: 1 addition & 0 deletions druid-shell/src/platform/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod levels {
Tooltip => NSFloatingWindowLevel,
DropDown => NSFloatingWindowLevel,
Modal => NSModalPanelWindowLevel,
AlwaysOnTop => NSFloatingWindowLevel,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ impl WindowBuilder {

pub fn set_level(&mut self, level: WindowLevel) {
match level {
WindowLevel::AppWindow | WindowLevel::Tooltip => self.level = Some(level),
WindowLevel::AppWindow | WindowLevel::Tooltip | WindowLevel::AlwaysOnTop => self.level = Some(level),
_ => {
warn!("WindowBuilder::set_level({:?}) is currently unimplemented for Windows platforms.", level);
}
Expand Down Expand Up @@ -1372,6 +1372,9 @@ impl WindowBuilder {
dwStyle = WS_OVERLAPPED;
dwExStyle = WS_EX_TOPMOST;
}
WindowLevel::AlwaysOnTop => {
dwExStyle = WS_EX_TOPMOST;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions druid-shell/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub enum WindowLevel {
DropDown,
/// A modal dialog
Modal,
/// A top level app window that will stay above other windows
AlwaysOnTop
}

/// Contains the different states a Window can be in.
Expand Down