From f93a6d740ac4cb09720bcb502b04e9a3d993bdba Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 12 Jan 2024 22:57:52 -0800 Subject: [PATCH 1/3] Add `show_window_menu` action Winit currently supports this only on Windows and Wayland. This requests that a context menu is shown at the cursor position, like the menu normally triggered by right clicking the title bar. This is important for implementing client side decorations with Iced widgets. --- runtime/src/window.rs | 5 +++++ runtime/src/window/action.rs | 9 +++++++++ winit/src/application.rs | 8 ++++++++ winit/src/multi_window.rs | 15 +++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 4d97d5eec9..44b707b251 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -160,6 +160,11 @@ pub fn change_level(id: Id, level: Level) -> Command { Command::single(command::Action::Window(Action::ChangeLevel(id, level))) } +/// Show window menu at cursor position. +pub fn show_window_menu(id: Id) -> Command { + 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( diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 86d5852880..d5c8c370ae 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -81,6 +81,11 @@ pub enum Action { 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 T + 'static>), /// Change the window [`Icon`]. @@ -141,6 +146,7 @@ impl Action { } 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 fmt::Debug for Action { 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 ad461738fd..c2bd11e2dc 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -807,6 +807,14 @@ pub fn run_command( 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 72cd939f62..64ecb3620c 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( .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 From f1c5186e79cdcc8730df7e557ef8480a10a8330d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 13 Feb 2024 04:49:27 +0100 Subject: [PATCH 2/3] Rename `show_window_menu` to `show_system_menu` --- runtime/src/window.rs | 8 +++++--- runtime/src/window/action.rs | 10 +++++----- winit/src/application.rs | 2 +- winit/src/multi_window.rs | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 44b707b251..04bcfcd8b3 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -160,9 +160,11 @@ pub fn change_level(id: Id, level: Level) -> Command { Command::single(command::Action::Window(Action::ChangeLevel(id, level))) } -/// Show window menu at cursor position. -pub fn show_window_menu(id: Id) -> Command { - Command::single(command::Action::Window(Action::ShowWindowMenu(id))) +/// Show the [system menu] at cursor position. +/// +/// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu +pub fn show_system_menu(id: Id) -> Command { + Command::single(command::Action::Window(Action::ShowSystemMenu(id))) } /// Fetches an identifier unique to the window, provided by the underlying windowing system. This is diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index d5c8c370ae..9bfc2b6203 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -81,11 +81,11 @@ pub enum Action { GainFocus(Id), /// Change the window [`Level`]. ChangeLevel(Id, Level), - /// Show window menu at cursor position. + /// Show the system menu at cursor position. /// /// ## Platform-specific /// Android / iOS / macOS / Orbital / Web / X11: Unsupported. - ShowWindowMenu(Id), + ShowSystemMenu(Id), /// Fetch the raw identifier unique to the window. FetchId(Id, Box T + 'static>), /// Change the window [`Icon`]. @@ -146,7 +146,7 @@ impl Action { } Self::GainFocus(id) => Action::GainFocus(id), Self::ChangeLevel(id, level) => Action::ChangeLevel(id, level), - Self::ShowWindowMenu(id) => Action::ShowWindowMenu(id), + Self::ShowSystemMenu(id) => Action::ShowSystemMenu(id), Self::FetchId(id, o) => { Action::FetchId(id, Box::new(move |s| f(o(s)))) } @@ -206,8 +206,8 @@ impl fmt::Debug for Action { Self::ChangeLevel(id, level) => { write!(f, "Action::ChangeLevel({id:?}, {level:?})") } - Self::ShowWindowMenu(id) => { - write!(f, "Action::ShowWindowMenu({id:?})") + Self::ShowSystemMenu(id) => { + write!(f, "Action::ShowSystemMenu({id:?})") } Self::FetchId(id, _) => write!(f, "Action::FetchId({id:?})"), Self::ChangeIcon(id, _icon) => { diff --git a/winit/src/application.rs b/winit/src/application.rs index c2bd11e2dc..0c596b3f6e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -807,7 +807,7 @@ pub fn run_command( window::Action::ChangeLevel(_id, level) => { window.set_window_level(conversion::window_level(level)); } - window::Action::ShowWindowMenu(_id) => { + window::Action::ShowSystemMenu(_id) => { if let mouse::Cursor::Available(point) = state.cursor() { window.show_window_menu(winit::dpi::LogicalPosition { x: point.x, diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 64ecb3620c..c63dd43332 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -1059,7 +1059,7 @@ fn run_command( .set_window_level(conversion::window_level(level)); } } - window::Action::ShowWindowMenu(id) => { + window::Action::ShowSystemMenu(id) => { if let Some(window) = window_manager.get_mut(id) { if let mouse::Cursor::Available(point) = window.state.cursor() From a64cda6e3ed98fc805cb6331c3619e59840d4f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 13 Feb 2024 04:50:23 +0100 Subject: [PATCH 3/3] Update `CHANGELOG` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 816ea89a52..af3006f49a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `skip_taskbar` window setting for Windows. [#2211](https://github.com/iced-rs/iced/pull/2211) - `fetch_maximized` and `fetch_minimized` commands in `window`. [#2189](https://github.com/iced-rs/iced/pull/2189) - `run_with_handle` command in `window`. [#2200](https://github.com/iced-rs/iced/pull/2200) +- `show_system_menu` command in `window`. [#2243](https://github.com/iced-rs/iced/pull/2243) - `text_shaping` method for `Tooltip`. [#2172](https://github.com/iced-rs/iced/pull/2172) - `interaction` method for `MouseArea`. [#2207](https://github.com/iced-rs/iced/pull/2207) - `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163)