Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window::is_minimized() #486

Merged
merged 4 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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