Skip to content

Commit 52e207b

Browse files
authored
Merge pull request #2243 from ids1024/show_window_menu
Add `show_window_menu` action
2 parents 7a1e105 + a64cda6 commit 52e207b

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- `skip_taskbar` window setting for Windows. [#2211](https://github.com/iced-rs/iced/pull/2211)
2323
- `fetch_maximized` and `fetch_minimized` commands in `window`. [#2189](https://github.com/iced-rs/iced/pull/2189)
2424
- `run_with_handle` command in `window`. [#2200](https://github.com/iced-rs/iced/pull/2200)
25+
- `show_system_menu` command in `window`. [#2243](https://github.com/iced-rs/iced/pull/2243)
2526
- `text_shaping` method for `Tooltip`. [#2172](https://github.com/iced-rs/iced/pull/2172)
2627
- `interaction` method for `MouseArea`. [#2207](https://github.com/iced-rs/iced/pull/2207)
2728
- `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163)

runtime/src/window.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ pub fn change_level<Message>(id: Id, level: Level) -> Command<Message> {
160160
Command::single(command::Action::Window(Action::ChangeLevel(id, level)))
161161
}
162162

163+
/// Show the [system menu] at cursor position.
164+
///
165+
/// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu
166+
pub fn show_system_menu<Message>(id: Id) -> Command<Message> {
167+
Command::single(command::Action::Window(Action::ShowSystemMenu(id)))
168+
}
169+
163170
/// Fetches an identifier unique to the window, provided by the underlying windowing system. This is
164171
/// not to be confused with [`Id`].
165172
pub fn fetch_id<Message>(

runtime/src/window/action.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ pub enum Action<T> {
8181
GainFocus(Id),
8282
/// Change the window [`Level`].
8383
ChangeLevel(Id, Level),
84+
/// Show the system menu at cursor position.
85+
///
86+
/// ## Platform-specific
87+
/// Android / iOS / macOS / Orbital / Web / X11: Unsupported.
88+
ShowSystemMenu(Id),
8489
/// Fetch the raw identifier unique to the window.
8590
FetchId(Id, Box<dyn FnOnce(u64) -> T + 'static>),
8691
/// Change the window [`Icon`].
@@ -141,6 +146,7 @@ impl<T> Action<T> {
141146
}
142147
Self::GainFocus(id) => Action::GainFocus(id),
143148
Self::ChangeLevel(id, level) => Action::ChangeLevel(id, level),
149+
Self::ShowSystemMenu(id) => Action::ShowSystemMenu(id),
144150
Self::FetchId(id, o) => {
145151
Action::FetchId(id, Box::new(move |s| f(o(s))))
146152
}
@@ -200,6 +206,9 @@ impl<T> fmt::Debug for Action<T> {
200206
Self::ChangeLevel(id, level) => {
201207
write!(f, "Action::ChangeLevel({id:?}, {level:?})")
202208
}
209+
Self::ShowSystemMenu(id) => {
210+
write!(f, "Action::ShowSystemMenu({id:?})")
211+
}
203212
Self::FetchId(id, _) => write!(f, "Action::FetchId({id:?})"),
204213
Self::ChangeIcon(id, _icon) => {
205214
write!(f, "Action::ChangeIcon({id:?})")

winit/src/application.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,14 @@ pub fn run_command<A, C, E>(
807807
window::Action::ChangeLevel(_id, level) => {
808808
window.set_window_level(conversion::window_level(level));
809809
}
810+
window::Action::ShowSystemMenu(_id) => {
811+
if let mouse::Cursor::Available(point) = state.cursor() {
812+
window.show_window_menu(winit::dpi::LogicalPosition {
813+
x: point.x,
814+
y: point.y,
815+
});
816+
}
817+
}
810818
window::Action::FetchId(_id, tag) => {
811819
proxy
812820
.send_event(tag(window.id().into()))

winit/src/multi_window.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub use state::State;
66

77
use crate::conversion;
88
use crate::core;
9+
use crate::core::mouse;
910
use crate::core::renderer;
1011
use crate::core::widget::operation;
1112
use crate::core::window;
@@ -1058,6 +1059,20 @@ fn run_command<A, C, E>(
10581059
.set_window_level(conversion::window_level(level));
10591060
}
10601061
}
1062+
window::Action::ShowSystemMenu(id) => {
1063+
if let Some(window) = window_manager.get_mut(id) {
1064+
if let mouse::Cursor::Available(point) =
1065+
window.state.cursor()
1066+
{
1067+
window.raw.show_window_menu(
1068+
winit::dpi::LogicalPosition {
1069+
x: point.x,
1070+
y: point.y,
1071+
},
1072+
);
1073+
}
1074+
}
1075+
}
10611076
window::Action::FetchId(id, tag) => {
10621077
if let Some(window) = window_manager.get_mut(id) {
10631078
proxy

0 commit comments

Comments
 (0)