Skip to content

Commit

Permalink
feat: Add is_visible getter to Window (rust-windowing#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemarier authored May 27, 2021
1 parent 1d1ab5b commit c402a38
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/is-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add `is_visible` getter on `Window`
5 changes: 5 additions & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fullscreen> {
let window_state = self.window_state.lock();
Expand Down
10 changes: 10 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c402a38

Please sign in to comment.