Skip to content

Commit

Permalink
Merge pull request #1314 from alvaro-sch/master
Browse files Browse the repository at this point in the history
Exposing window always on top functionality
  • Loading branch information
Cobrand authored Jul 3, 2023
2 parents 27cd1fd + a8c8598 commit 8613c50
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit 8613c50

Please sign in to comment.