Skip to content

Commit

Permalink
feat: Window::is_focused
Browse files Browse the repository at this point in the history
  • Loading branch information
henry40408 committed Aug 16, 2022
1 parent 6d8cc7e commit 8c7c0c3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@ impl Window {
warn!("set_focus not yet implemented on Android");
}

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

pub fn set_resizable(&self, _resizeable: bool) {}

pub fn set_minimized(&self, _minimized: bool) {}
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 @@ -72,6 +72,11 @@ impl Inner {
warn!("set_focus not yet implemented on iOS");
}

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

pub fn request_redraw(&self) {
unsafe {
if self.gl_or_metal_backed {
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ impl UnownedWindow {
}
}

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

pub fn request_redraw(&self) {
AppState::queue_redraw(RootWindowId(self.id()));
}
Expand Down
13 changes: 12 additions & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ impl Window {
self.window.set_focus()
}

/// Does window has focus?
///
/// ## Platform-specific
///
/// - **Linux / macOS:** is_focus() and is_visible() are identical.
/// - **iOS / Android:** Unsupported.
#[inline]
pub fn is_focused(&self) -> bool {
self.window.is_focused()
}

/// 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
Expand Down Expand Up @@ -697,7 +708,7 @@ impl Window {
self.window.is_minimized()
}

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

0 comments on commit 8c7c0c3

Please sign in to comment.