From c402a38b1bbf240f4d2553c3f2b4edf86f03c270 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 27 May 2021 05:59:30 -0400 Subject: [PATCH] feat: Add `is_visible` getter to `Window` (#61) --- .changes/is-visible.md | 5 +++++ src/platform_impl/android/mod.rs | 5 +++++ src/platform_impl/ios/window.rs | 5 +++++ src/platform_impl/linux/window.rs | 5 +++++ src/platform_impl/macos/window.rs | 7 +++++++ src/platform_impl/windows/util.rs | 6 +++++- src/platform_impl/windows/window.rs | 6 ++++++ src/window.rs | 10 ++++++++++ 8 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 .changes/is-visible.md diff --git a/.changes/is-visible.md b/.changes/is-visible.md new file mode 100644 index 0000000000..2481442b75 --- /dev/null +++ b/.changes/is-visible.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Add `is_visible` getter on `Window` \ No newline at end of file diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 7de17d2b22..01622f1c73 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -517,6 +517,11 @@ impl Window { false } + pub fn is_visible(&self) -> bool { + log::warn!("`Window::is_visible` is ignored on android"); + false + } + pub fn is_resizable(&self) -> bool { warn!("`Window::is_resizable` is ignored on android"); false diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 0bb965e7b2..47905ccf6b 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -210,6 +210,11 @@ impl Inner { false } + pub fn is_visible(&self) -> bool { + log::warn!("`Window::is_visible` is ignored on iOS"); + false + } + pub fn is_resizable(&self) -> bool { warn!("`Window::is_resizable` is ignored on iOS"); false diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index 88cdf56ab5..7e954858d1 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -483,6 +483,11 @@ impl Window { self.window.get_decorated() } + #[inline] + pub fn is_visible(&self) -> bool { + self.window.is_visible() + } + pub fn drag_window(&self) -> Result<(), ExternalError> { if let Err(e) = self .window_requests_tx diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 5a032c53ed..617b19190b 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -749,12 +749,19 @@ impl UnownedWindow { self.is_zoomed() } + #[inline] + pub fn is_visible(&self) -> bool { + let is_visible: BOOL = unsafe { msg_send![*self.ns_window, isVisible] }; + is_visible == YES + } + #[inline] pub fn is_resizable(&self) -> bool { let is_resizable: BOOL = unsafe { msg_send![*self.ns_window, isResizable] }; is_resizable == YES } + #[inline] pub fn is_decorated(&self) -> bool { let current_mask = unsafe { self.ns_window.styleMask() }; if current_mask diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index f65110fad0..c67b66c597 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -13,7 +13,7 @@ use crate::{dpi::PhysicalSize, window::CursorIcon}; use winapi::{ ctypes::wchar_t, shared::{ - minwindef::{BOOL, DWORD, UINT}, + minwindef::{BOOL, DWORD, TRUE, UINT}, windef::{DPI_AWARENESS_CONTEXT, HMONITOR, HWND, LPRECT, RECT}, }, um::{ @@ -199,6 +199,10 @@ pub fn is_focused(window: HWND) -> bool { window == unsafe { winuser::GetActiveWindow() } } +pub fn is_visible(window: HWND) -> bool { + unsafe { winuser::IsWindowVisible(window) == TRUE } +} + impl CursorIcon { pub(crate) fn to_windows_cursor(self) -> *const wchar_t { match self { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 43954e2ea8..4da3a21d11 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -442,11 +442,17 @@ impl Window { window_state.window_flags.contains(WindowFlags::RESIZABLE) } + #[inline] pub fn is_decorated(&self) -> bool { let window_state = self.window_state.lock(); window_state.window_flags.contains(WindowFlags::DECORATIONS) } + #[inline] + pub fn is_visible(&self) -> bool { + util::is_visible(self.window.0) + } + #[inline] pub fn fullscreen(&self) -> Option { let window_state = self.window_state.lock(); diff --git a/src/window.rs b/src/window.rs index 1a504ef7a5..eed8d12c52 100644 --- a/src/window.rs +++ b/src/window.rs @@ -688,6 +688,16 @@ impl Window { self.window.is_maximized() } + /// Gets the window's current vibility state. + /// + /// ## Platform-specific + /// + /// - **iOS / Android:** Unsupported. + #[inline] + pub fn is_visible(&self) -> bool { + self.window.is_visible() + } + /// Gets the window's current resizable state. /// /// ## Platform-specific