diff --git a/CHANGELOG.md b/CHANGELOG.md index 5836034a..54f5a13b 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_visible`. - Added `Window::is_resizable`. - Added `Window::is_decorated`. - On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait` diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index f9884a98..c9e1220e 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -543,6 +543,10 @@ impl Window { pub fn set_visible(&self, _visibility: bool) {} + pub fn is_visible(&self) -> Option { + None + } + pub fn set_resizable(&self, _resizeable: bool) {} pub fn is_resizable(&self) -> bool { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index c892f2cd..f007bcaa 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -60,6 +60,11 @@ impl Inner { } } + pub fn is_visible(&self) -> Option { + warn!("`Window::is_visible` is ignored on iOS"); + None + } + pub fn request_redraw(&self) { unsafe { if self.gl_or_metal_backed { diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 256db173..16f66e34 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -321,6 +321,11 @@ impl Window { x11_or_wayland!(match self; Window(w) => w.set_visible(visible)) } + #[inline] + pub fn is_visible(&self) -> Option { + x11_or_wayland!(match self; Window(w) => w.is_visible()) + } + #[inline] pub fn outer_position(&self) -> Result, NotSupportedError> { x11_or_wayland!(match self; Window(w) => w.outer_position()) diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 9db99c6f..3dc8bc58 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -270,6 +270,11 @@ impl Window { // Not possible on Wayland. } + #[inline] + pub fn is_visible(&self) -> Option { + None + } + #[inline] pub fn outer_position(&self) -> Result, NotSupportedError> { Err(NotSupportedError::new()) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 9f725533..cee419af 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -984,6 +984,11 @@ impl UnownedWindow { } } + #[inline] + pub fn is_visible(&self) -> Option { + None + } + fn update_cached_frame_extents(&self) { let extents = self .xconn diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 1adb3127..516eb60c 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -502,6 +502,12 @@ impl UnownedWindow { } } + #[inline] + pub fn is_visible(&self) -> Option { + let is_visible: BOOL = unsafe { msg_send![*self.ns_window, isVisible] }; + Some(is_visible == YES) + } + pub fn request_redraw(&self) { AppState::queue_redraw(RootWindowId(self.id())); } diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 78b75781..2850439a 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -89,6 +89,11 @@ impl Window { // Intentionally a no-op } + #[inline] + pub fn is_visible(&self) -> Option { + None + } + pub fn request_redraw(&self) { (self.register_redraw_request)(); } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index e9c28dc3..6703d6e5 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -97,6 +97,11 @@ impl Window { }); } + #[inline] + pub fn is_visible(&self) -> Option { + Some(unsafe { winuser::IsWindowVisible(self.window.0) == 1 }) + } + #[inline] pub fn request_redraw(&self) { unsafe { diff --git a/src/window.rs b/src/window.rs index d7f4c130..d330e79a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -650,6 +650,19 @@ impl Window { self.window.set_visible(visible) } + /// Gets the window's current vibility state. + /// + /// If `None` means it couldn't be determined so it is not recommended to use this to drive your rendering backend. + /// + /// ## Platform-specific + /// + /// - **X11:** Not implemented. + /// - **Wayland / iOS / Android / Web:** Unsupported. + #[inline] + pub fn is_visible(&self) -> Option { + self.window.is_visible() + } + /// Sets whether the window is resizable or not. /// /// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that event can still be