From ae1f1d7b6fb76b2285cab2274af170641549d5cc Mon Sep 17 00:00:00 2001 From: alvaro-sch Date: Tue, 27 Jun 2023 23:09:12 -0300 Subject: [PATCH 1/2] Added WindowBuilder::always_on_top() Window::{is,set}_always_on_top() --- src/sdl2/video.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index fdc304fd48..c7723e6be1 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -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. @@ -1512,6 +1518,11 @@ impl Window { 0 != self.window_flags() & sys::SDL_WindowFlags::SDL_WINDOW_MINIMIZED as u32 } + /// Is the windows 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)?; @@ -1954,6 +1965,21 @@ impl Window { Err(get_error()) } } + + /// Makes window appear on top 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)] From a8c859802f80c53fb68d81776ac9a9d66af36fca Mon Sep 17 00:00:00 2001 From: alvaro-sch Date: Wed, 28 Jun 2023 00:02:15 -0300 Subject: [PATCH 2/2] Fixed typos --- src/sdl2/video.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index c7723e6be1..f600333f66 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1518,7 +1518,7 @@ impl Window { 0 != self.window_flags() & sys::SDL_WindowFlags::SDL_WINDOW_MINIMIZED as u32 } - /// Is the windows always on top? + /// 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 } @@ -1966,7 +1966,7 @@ impl Window { } } - /// Makes window appear on top others + /// Makes window appear on top of others #[doc(alias = "SDL_SetWindowAlwaysOnTop")] pub fn set_always_on_top(&mut self, on_top: bool) { unsafe {