Skip to content

Exposing window always on top functionality #1314

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

Merged
merged 2 commits into from
Jul 3, 2023
Merged
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
26 changes: 26 additions & 0 deletions src/sdl2/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,12 @@ impl WindowBuilder {
self
}

/// Window should always above others (>= SDL 2.0.5)
pub fn always_on_top(&mut self) -> &mut WindowBuilder {
self.window_flags |= sys::SDL_WindowFlags::SDL_WINDOW_ALWAYS_ON_TOP as u32;
self
}

/// Create a SDL_MetalView when constructing the window.
/// This is required when using the raw_window_handle feature on MacOS.
/// Has no effect no other platforms.
Expand Down Expand Up @@ -1512,6 +1518,11 @@ impl Window {
0 != self.window_flags() & sys::SDL_WindowFlags::SDL_WINDOW_MINIMIZED as u32
}

/// Is the window always on top?
pub fn is_always_on_top(&self) -> bool {
0 != self.window_flags() & sys::SDL_WindowFlags::SDL_WINDOW_ALWAYS_ON_TOP as u32
}

#[doc(alias = "SDL_SetWindowTitle")]
pub fn set_title(&mut self, title: &str) -> Result<(), NulError> {
let title = CString::new(title)?;
Expand Down Expand Up @@ -1954,6 +1965,21 @@ impl Window {
Err(get_error())
}
}

/// Makes window appear on top of others
#[doc(alias = "SDL_SetWindowAlwaysOnTop")]
pub fn set_always_on_top(&mut self, on_top: bool) {
unsafe {
sys::SDL_SetWindowAlwaysOnTop(
self.context.raw,
if on_top {
sys::SDL_bool::SDL_TRUE
} else {
sys::SDL_bool::SDL_FALSE
},
)
};
}
}

#[derive(Copy, Clone)]
Expand Down