From daf0d6b9a7d4c396bb43dc87b2035128ff1a122f Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 17 Feb 2022 17:03:17 +0200 Subject: [PATCH] feat: add `Window::is_resizable` (#2171) * feat: add `Window::is_resizable` * move it right after `set_resizable` --- CHANGELOG.md | 1 + src/platform_impl/android/mod.rs | 4 ++++ src/platform_impl/ios/window.rs | 5 +++++ src/platform_impl/linux/mod.rs | 5 +++++ src/platform_impl/linux/wayland/window/mod.rs | 5 +++++ src/platform_impl/linux/x11/window.rs | 5 +++++ src/platform_impl/macos/window.rs | 6 ++++++ src/platform_impl/web/window.rs | 4 ++++ src/platform_impl/windows/window.rs | 6 ++++++ src/window.rs | 11 +++++++++++ 10 files changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f86d1f31..5836034a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- Added `Window::is_resizable`. - Added `Window::is_decorated`. - On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait` - On Wayland, report unaccelerated mouse deltas in `DeviceEvent::MouseMotion`. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 300d5c32..270fc386 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -543,6 +543,10 @@ impl Window { pub fn set_resizable(&self, _resizeable: bool) {} + pub fn is_resizable(&self) -> bool { + false + } + pub fn set_minimized(&self, _minimized: bool) {} pub fn set_maximized(&self, _maximized: bool) {} diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index e1d3e150..c892f2cd 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -159,6 +159,11 @@ impl Inner { warn!("`Window::set_resizable` is ignored on iOS") } + pub fn is_resizable(&self) -> bool { + warn!("`Window::is_resizable` is ignored on iOS"); + false + } + pub fn scale_factor(&self) -> f64 { unsafe { let hidpi: CGFloat = msg_send![self.view, contentScaleFactor]; diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 2ca74bda..256db173 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -366,6 +366,11 @@ impl Window { x11_or_wayland!(match self; Window(w) => w.set_resizable(resizable)) } + #[inline] + pub fn is_resizable(&self) -> bool { + x11_or_wayland!(match self; Window(w) => w.is_resizable()) + } + #[inline] pub fn set_cursor_icon(&self, cursor: CursorIcon) { x11_or_wayland!(match self; Window(w) => w.set_cursor_icon(cursor)) diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 0a81e2db..9db99c6f 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -336,6 +336,11 @@ impl Window { self.send_request(WindowRequest::Resizeable(resizable)); } + #[inline] + pub fn is_resizable(&self) -> bool { + true + } + #[inline] pub fn scale_factor(&self) -> u32 { // The scale factor from `get_surface_scale_factor` is always greater than zero, so diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index ebb69e93..9f725533 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -1211,6 +1211,11 @@ impl UnownedWindow { .expect("Failed to call `XSetWMNormalHints`"); } + #[inline] + pub fn is_resizable(&self) -> bool { + true + } + #[inline] pub fn xlib_display(&self) -> *mut c_void { self.xconn.display as _ diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 08eb0e46..1adb3127 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -602,6 +602,12 @@ impl UnownedWindow { } // Otherwise, we don't change the mask until we exit fullscreen. } + #[inline] + pub fn is_resizable(&self) -> bool { + let is_resizable: BOOL = unsafe { msg_send![*self.ns_window, isResizable] }; + is_resizable == YES + } + pub fn set_cursor_icon(&self, cursor: CursorIcon) { let cursor = util::Cursor::from(cursor); if let Some(cursor_access) = self.cursor_state.upgrade() { diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 02c6c07b..78b75781 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -151,6 +151,10 @@ impl Window { // Intentionally a no-op: users can't resize canvas elements } + pub fn is_resizable(&self) -> bool { + true + } + #[inline] pub fn scale_factor(&self) -> f64 { super::backend::scale_factor() diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index b4e776c1..e9c28dc3 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -225,6 +225,12 @@ impl Window { }); } + #[inline] + pub fn is_resizable(&self) -> bool { + let window_state = self.window_state.lock(); + window_state.window_flags.contains(WindowFlags::RESIZABLE) + } + /// Returns the `hwnd` of this window. #[inline] pub fn hwnd(&self) -> HWND { diff --git a/src/window.rs b/src/window.rs index f5806036..d7f4c130 100644 --- a/src/window.rs +++ b/src/window.rs @@ -669,6 +669,17 @@ impl Window { self.window.set_resizable(resizable) } + /// Gets the window's current resizable state. + /// + /// ## Platform-specific + /// + /// - **Wayland / X11:** Not implemented. + /// - **iOS / Android / Web:** Unsupported. + #[inline] + pub fn is_resizable(&self) -> bool { + self.window.is_resizable() + } + /// Sets the window to minimized or back /// /// ## Platform-specific