Skip to content

Commit

Permalink
feat: add is_menu_visible (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jul 6, 2021
1 parent e297289 commit 308411c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/is_menu_visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add `is_menu_visilbe` 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 @@ -630,6 +630,11 @@ impl Window {

pub fn show_menu(&self) {}

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

pub fn set_cursor_icon(&self, _: window::CursorIcon) {}

pub fn set_cursor_position(&self, _: Position) -> Result<(), error::ExternalError> {
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 @@ -308,6 +308,11 @@ impl Inner {
warn!("`Window::show_menu` is ignored on iOS")
}

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

// Allow directly accessing the current monitor internally without unwrapping.
fn current_monitor_inner(&self) -> RootMonitorHandle {
unsafe {
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 @@ -587,6 +587,10 @@ impl Window {
self.menu_bar.show_all();
}

pub fn is_menu_visible(&self) -> bool {
self.menu_bar.get_visible()
}

pub fn set_cursor_icon(&self, cursor: CursorIcon) {
if let Err(e) = self
.window_requests_tx
Expand Down
6 changes: 6 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,12 @@ impl UnownedWindow {
#[inline]
pub fn show_menu(&self) {}

#[inline]
pub fn is_menu_visible(&self) -> bool {
warn!("`Window::is_menu_visible` always return true on macOS");
true
}

#[inline]
// Allow directly accessing the current monitor internally without unwrapping.
pub(crate) fn current_monitor_inner(&self) -> RootMonitorHandle {
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ impl Window {
}
}

#[inline]
pub fn is_menu_visible(&self) -> bool {
unsafe { winuser::GetMenu(self.hwnd()) != ptr::null_mut() }
}

#[inline]
pub fn reset_dead_keys(&self) {
// `ToUnicode` consumes the dead-key by default, so we are constructing a fake (but valid)
Expand Down
10 changes: 10 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ impl Window {
pub fn show_menu(&self) {
self.window.show_menu();
}

/// Gets the visibilty of the window menu.
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
/// - **macOS:** Always return true, as the menu is always visible.
pub fn is_menu_visible(&self) -> bool {
self.window.is_menu_visible()
}
}

/// Cursor functions.
Expand Down

0 comments on commit 308411c

Please sign in to comment.