Skip to content

Commit

Permalink
feat: add Window::is_minimized(), closes #257 (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
henry40408 committed Aug 6, 2022
1 parent 9c6a543 commit 9c34815
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changes/is-minimized.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add `Window::is_minimized()`.
12 changes: 4 additions & 8 deletions examples/window_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn main() {
eprintln!(" (V) Toggle visibility");
eprintln!(" (X) Toggle maximized");

let mut minimized = false;
let mut visible = true;

event_loop.run(move |event, _, control_flow| {
Expand All @@ -51,9 +50,8 @@ fn main() {
..
} => match physical_key {
KeyCode::KeyM => {
if minimized {
minimized = !minimized;
window.set_minimized(minimized);
if window.is_minimized() {
window.set_minimized(false);
}
}
KeyCode::KeyV => {
Expand Down Expand Up @@ -110,8 +108,7 @@ fn main() {
}
}
"m" => {
minimized = !minimized;
window.set_minimized(minimized);
window.set_minimized(!window.is_minimized());
}
"q" => {
*control_flow = ControlFlow::Exit;
Expand All @@ -121,8 +118,7 @@ fn main() {
window.set_visible(visible);
}
"x" => {
let is_maximized = window.is_maximized();
window.set_maximized(!is_maximized);
window.set_maximized(!window.is_maximized());
}
_ => (),
},
Expand Down
4 changes: 4 additions & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ impl Window {
false
}

pub fn is_minimized(&self) -> bool {
false
}

pub fn is_visible(&self) -> bool {
log::warn!("`Window::is_visible` 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 @@ -215,6 +215,11 @@ impl Inner {
false
}

pub fn is_minimized(&self) -> bool {
warn!("`Window::is_minimized` is ignored on iOS");
false
}

pub fn is_visible(&self) -> bool {
log::warn!("`Window::is_visible` is ignored on iOS");
false
Expand Down
4 changes: 4 additions & 0 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ impl Window {
self.maximized.load(Ordering::Acquire)
}

pub fn is_minimized(&self) -> bool {
self.minimized.load(Ordering::Acquire)
}

pub fn is_resizable(&self) -> bool {
self.window.is_resizable()
}
Expand Down
9 changes: 1 addition & 8 deletions src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
pub struct Window {
window: Arc<UnownedWindow>,
// We keep this around so that it doesn't get dropped until the window does.
#[allow(dead_code)]
delegate: util::IdRef,
}

Expand Down Expand Up @@ -90,14 +91,6 @@ impl Window {
let (window, delegate) = UnownedWindow::new(attributes, pl_attribs)?;
Ok(Window { window, delegate })
}

#[inline]
pub fn is_maximized(&self) -> bool {
let () = unsafe { msg_send![*self.delegate, markIsCheckingZoomedIn] };
let f = self.window.is_zoomed();
let () = unsafe { msg_send![*self.delegate, clearIsCheckingZoomedIn] };
f
}
}

impl fmt::Display for OsError {
Expand Down
11 changes: 11 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,17 @@ impl UnownedWindow {
is_visible == YES
}

#[inline]
pub fn is_maximized(&self) -> bool {
self.is_zoomed()
}

#[inline]
pub fn is_minimized(&self) -> bool {
let is_minimized: BOOL = unsafe { msg_send![*self.ns_window, isMiniaturized] };
is_minimized == YES
}

#[inline]
pub fn is_resizable(&self) -> bool {
let is_resizable: BOOL = unsafe { msg_send![*self.ns_window, isResizable] };
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 @@ -460,6 +460,12 @@ impl Window {
window_state.window_flags.contains(WindowFlags::MAXIMIZED)
}

#[inline]
pub fn is_minimized(&self) -> bool {
let window_state = self.window_state.lock();
window_state.window_flags.contains(WindowFlags::MINIMIZED)
}

#[inline]
pub fn is_resizable(&self) -> bool {
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 @@ -687,6 +687,16 @@ impl Window {
self.window.is_maximized()
}

/// Gets the window's current minimized state.
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
#[inline]
pub fn is_minimized(&self) -> bool {
self.window.is_minimized()
}

/// Gets the window's current vibility state.
///
/// ## Platform-specific
Expand Down

0 comments on commit 9c34815

Please sign in to comment.