Skip to content

Commit

Permalink
Merge pull request #2243 from ids1024/show_window_menu
Browse files Browse the repository at this point in the history
Add `show_window_menu` action
  • Loading branch information
hecrj authored Feb 13, 2024
2 parents 7a1e105 + a64cda6 commit 52e207b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ pub fn change_level<Message>(id: Id, level: Level) -> Command<Message> {
Command::single(command::Action::Window(Action::ChangeLevel(id, level)))
}

/// 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<Message>(id: Id) -> Command<Message> {
Command::single(command::Action::Window(Action::ShowSystemMenu(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>(
Expand Down
9 changes: 9 additions & 0 deletions runtime/src/window/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub enum Action<T> {
GainFocus(Id),
/// Change the window [`Level`].
ChangeLevel(Id, Level),
/// Show the system menu at cursor position.
///
/// ## Platform-specific
/// Android / iOS / macOS / Orbital / Web / X11: Unsupported.
ShowSystemMenu(Id),
/// Fetch the raw identifier unique to the window.
FetchId(Id, Box<dyn FnOnce(u64) -> T + 'static>),
/// Change the window [`Icon`].
Expand Down Expand Up @@ -141,6 +146,7 @@ impl<T> Action<T> {
}
Self::GainFocus(id) => Action::GainFocus(id),
Self::ChangeLevel(id, level) => Action::ChangeLevel(id, level),
Self::ShowSystemMenu(id) => Action::ShowSystemMenu(id),
Self::FetchId(id, o) => {
Action::FetchId(id, Box::new(move |s| f(o(s))))
}
Expand Down Expand Up @@ -200,6 +206,9 @@ impl<T> fmt::Debug for Action<T> {
Self::ChangeLevel(id, level) => {
write!(f, "Action::ChangeLevel({id:?}, {level:?})")
}
Self::ShowSystemMenu(id) => {
write!(f, "Action::ShowSystemMenu({id:?})")
}
Self::FetchId(id, _) => write!(f, "Action::FetchId({id:?})"),
Self::ChangeIcon(id, _icon) => {
write!(f, "Action::ChangeIcon({id:?})")
Expand Down
8 changes: 8 additions & 0 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::ShowSystemMenu(_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()))
Expand Down
15 changes: 15 additions & 0 deletions winit/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1058,6 +1059,20 @@ fn run_command<A, C, E>(
.set_window_level(conversion::window_level(level));
}
}
window::Action::ShowSystemMenu(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
Expand Down

0 comments on commit 52e207b

Please sign in to comment.