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.
This commit is contained in:
Ian Douglas Scott 2024-01-12 22:57:52 -08:00 committed by Héctor Ramón Jiménez
parent 7a1e105036
commit f93a6d740a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 37 additions and 0 deletions

View file

@ -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>(

View file

@ -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:?})")