diff options
-rw-r--r-- | runtime/src/window.rs | 5 | ||||
-rw-r--r-- | runtime/src/window/action.rs | 9 | ||||
-rw-r--r-- | winit/src/application.rs | 8 | ||||
-rw-r--r-- | winit/src/multi_window.rs | 15 |
4 files changed, 37 insertions, 0 deletions
diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 4d97d5ee..44b707b2 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -160,6 +160,11 @@ pub fn change_level<Message>(id: Id, level: Level) -> Command<Message> { Command::single(command::Action::Window(Action::ChangeLevel(id, level))) } +/// Show window menu at cursor position. +pub fn show_window_menu<Message>(id: Id) -> Command<Message> { + Command::single(command::Action::Window(Action::ShowWindowMenu(id))) +} + /// Fetches an identifier unique to the window, provided by the underlying windowing system. This is /// not to be confused with [`Id`]. pub fn fetch_id<Message>( diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 86d58528..d5c8c370 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -81,6 +81,11 @@ pub enum Action<T> { GainFocus(Id), /// Change the window [`Level`]. ChangeLevel(Id, Level), + /// Show window menu at cursor position. + /// + /// ## Platform-specific + /// Android / iOS / macOS / Orbital / Web / X11: Unsupported. + ShowWindowMenu(Id), /// Fetch the raw identifier unique to the window. FetchId(Id, Box<dyn FnOnce(u64) -> T + 'static>), /// Change the window [`Icon`]. @@ -141,6 +146,7 @@ impl<T> Action<T> { } Self::GainFocus(id) => Action::GainFocus(id), Self::ChangeLevel(id, level) => Action::ChangeLevel(id, level), + Self::ShowWindowMenu(id) => Action::ShowWindowMenu(id), Self::FetchId(id, o) => { Action::FetchId(id, Box::new(move |s| f(o(s)))) } @@ -200,6 +206,9 @@ impl<T> fmt::Debug for Action<T> { Self::ChangeLevel(id, level) => { write!(f, "Action::ChangeLevel({id:?}, {level:?})") } + Self::ShowWindowMenu(id) => { + write!(f, "Action::ShowWindowMenu({id:?})") + } Self::FetchId(id, _) => write!(f, "Action::FetchId({id:?})"), Self::ChangeIcon(id, _icon) => { write!(f, "Action::ChangeIcon({id:?})") diff --git a/winit/src/application.rs b/winit/src/application.rs index ad461738..c2bd11e2 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -807,6 +807,14 @@ pub fn run_command<A, C, E>( window::Action::ChangeLevel(_id, level) => { window.set_window_level(conversion::window_level(level)); } + window::Action::ShowWindowMenu(_id) => { + if let mouse::Cursor::Available(point) = state.cursor() { + window.show_window_menu(winit::dpi::LogicalPosition { + x: point.x, + y: point.y, + }); + } + } window::Action::FetchId(_id, tag) => { proxy .send_event(tag(window.id().into())) diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 72cd939f..64ecb362 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -6,6 +6,7 @@ pub use state::State; use crate::conversion; use crate::core; +use crate::core::mouse; use crate::core::renderer; use crate::core::widget::operation; use crate::core::window; @@ -1058,6 +1059,20 @@ fn run_command<A, C, E>( .set_window_level(conversion::window_level(level)); } } + window::Action::ShowWindowMenu(id) => { + if let Some(window) = window_manager.get_mut(id) { + if let mouse::Cursor::Available(point) = + window.state.cursor() + { + window.raw.show_window_menu( + winit::dpi::LogicalPosition { + x: point.x, + y: point.y, + }, + ); + } + } + } window::Action::FetchId(id, tag) => { if let Some(window) = window_manager.get_mut(id) { proxy |