From 9f6ad8ebaf417046cb07e176aa7aa4e446de01a5 Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 00:50:36 +0100 Subject: [PATCH 1/6] Add SDL_GetWindowBordersSize() --- src/sdl2/video.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 2f849e4e..9104d42f 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1159,6 +1159,16 @@ impl Window { unsafe { sys::SDL_GetWindowPosition(self.context.raw, &mut x, &mut y) }; (x as i32, y as i32) } + + /// Use this function to get the size of a window's borders (decorations) around the client area. + pub fn border_size(&self) -> (i32, i32, i32, i32) { + let mut top: c_int = 0; + let mut left: c_int = 0; + let mut bottom: c_int = 0; + let mut right: c_int = 0; + unsafe { sys::SDL_GetWindowBordersSize(self.context.raw, &mut top, &mut left, &mut bottom, &mut right) }; + (top as i32, left as i32, bottom as i32, right as i32) + } pub fn set_size(&mut self, width: u32, height: u32) -> Result<(), IntegerOrSdlError> { From 68ad612a69a4be79843d17aa32861d8b62a5fbaa Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 10:56:18 +0100 Subject: [PATCH 2/6] Change return type of `border_size` to u16 --- 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 9104d42f..6dc17ba1 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1161,13 +1161,13 @@ impl Window { } /// Use this function to get the size of a window's borders (decorations) around the client area. - pub fn border_size(&self) -> (i32, i32, i32, i32) { + pub fn border_size(&self) -> (u16, u16, u16, u16) { let mut top: c_int = 0; let mut left: c_int = 0; let mut bottom: c_int = 0; let mut right: c_int = 0; unsafe { sys::SDL_GetWindowBordersSize(self.context.raw, &mut top, &mut left, &mut bottom, &mut right) }; - (top as i32, left as i32, bottom as i32, right as i32) + (top as u16, left as u16, bottom as u16, right as u16) } pub fn set_size(&mut self, width: u32, height: u32) From c555f55f58164b0acda6479e059ab6b33a1d4f4d Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 11:13:35 +0100 Subject: [PATCH 3/6] Update border_size documentation --- src/sdl2/video.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 6dc17ba1..8937b088 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1161,6 +1161,13 @@ impl Window { } /// Use this function to get the size of a window's borders (decorations) around the client area. + /// + /// # Remarks + /// This function is only supported on X11. + /// + /// #Notes + /// + /// If this function fails, (0, 0, 0, 0) will be returned pub fn border_size(&self) -> (u16, u16, u16, u16) { let mut top: c_int = 0; let mut left: c_int = 0; From fe23e512e0257173a12ee000ca2d640daa12daef Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 11:15:00 +0100 Subject: [PATCH 4/6] Update border_size documentation --- src/sdl2/video.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 8937b088..8aabb212 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1163,10 +1163,9 @@ impl Window { /// Use this function to get the size of a window's borders (decorations) around the client area. /// /// # Remarks - /// This function is only supported on X11. + /// This function is only supported on X11, otherwise (0, 0, 0, 0) is returned. /// /// #Notes - /// /// If this function fails, (0, 0, 0, 0) will be returned pub fn border_size(&self) -> (u16, u16, u16, u16) { let mut top: c_int = 0; From 0a668e7f7f3a7d255e6f675649636e5aede515fc Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 18:13:28 +0100 Subject: [PATCH 5/6] Change return type of border_size to Result --- src/sdl2/video.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 8aabb212..6ce83d33 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1167,13 +1167,17 @@ impl Window { /// /// #Notes /// If this function fails, (0, 0, 0, 0) will be returned - pub fn border_size(&self) -> (u16, u16, u16, u16) { + pub fn border_size(&self) -> Result<(u16, u16, u16, u16), String> { let mut top: c_int = 0; let mut left: c_int = 0; let mut bottom: c_int = 0; let mut right: c_int = 0; - unsafe { sys::SDL_GetWindowBordersSize(self.context.raw, &mut top, &mut left, &mut bottom, &mut right) }; - (top as u16, left as u16, bottom as u16, right as u16) + let result = unsafe { sys::SDL_GetWindowBordersSize(self.context.raw, &mut top, &mut left, &mut bottom, &mut right) }; + if result < 0 { + Err(get_error()) + } else { + Ok((top as u16, left as u16, bottom as u16, right as u16)) + } } pub fn set_size(&mut self, width: u32, height: u32) From 9b419fecb1eb2b1b72572c5c79292fee8f378955 Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 30 Nov 2017 18:18:38 +0100 Subject: [PATCH 6/6] Update documentation for border_size --- src/sdl2/video.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 6ce83d33..c92f700b 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1163,10 +1163,7 @@ impl Window { /// Use this function to get the size of a window's borders (decorations) around the client area. /// /// # Remarks - /// This function is only supported on X11, otherwise (0, 0, 0, 0) is returned. - /// - /// #Notes - /// If this function fails, (0, 0, 0, 0) will be returned + /// This function is only supported on X11, otherwise an error is returned. pub fn border_size(&self) -> Result<(u16, u16, u16, u16), String> { let mut top: c_int = 0; let mut left: c_int = 0;