From 51ac4bdb73f41400aac8154e8185c89c8b55c600 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 9 Feb 2024 10:25:45 -0800 Subject: [PATCH] header_bar: Show window menu on right click With this, apps like cosmic-term require no changes to show the compositor window menu when the header is right clicked. --- iced | 2 +- src/app/cosmic.rs | 5 +++++ src/app/mod.rs | 3 ++- src/widget/header_bar.rs | 9 +++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/iced b/iced index 8b7b0bf5..268e2107 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 8b7b0bf54516c4b28cc38d328a01946b3800eec7 +Subproject commit 268e21076e1cb06af9142aa193dcc8647bf0eb60 diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index 8deb160e..7119acc6 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -69,6 +69,7 @@ pub enum Message { SurfaceClosed(window::Id), /// Activate the application Activate(String), + ShowWindowMenu, } #[derive(Default)] @@ -408,6 +409,10 @@ impl Cosmic { return self.app.update(msg); } } + Message::ShowWindowMenu => { + #[cfg(not(feature = "wayland"))] + return window::show_window_menu(window::Id::MAIN); + } } iced::Command::none() diff --git a/src/app/mod.rs b/src/app/mod.rs index baffac84..568e81fc 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -661,7 +661,8 @@ impl ApplicationExt for App { .window_id(window::Id::MAIN) .title(&core.window.header_title) .on_drag(Message::Cosmic(cosmic::Message::Drag)) - .on_close(Message::Cosmic(cosmic::Message::Close)); + .on_close(Message::Cosmic(cosmic::Message::Close)) + .on_right_click(Message::Cosmic(cosmic::Message::ShowWindowMenu)); if self.nav_model().is_some() { let toggle = crate::widget::nav_bar_toggle() diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index 80c43694..6bed9828 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -16,6 +16,7 @@ pub fn header_bar<'a, Message>() -> HeaderBar<'a, Message> { on_drag: None, on_maximize: None, on_minimize: None, + on_right_click: None, start: Vec::new(), center: Vec::new(), end: Vec::new(), @@ -45,6 +46,10 @@ pub struct HeaderBar<'a, Message> { #[setters(strip_option)] on_minimize: Option, + /// A message emitted when the header is right clicked. + #[setters(strip_option)] + on_right_click: Option, + /// The window id for the headerbar. #[setters(strip_option)] window_id: Option, @@ -337,6 +342,10 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { widget = widget.on_release(message); } + if let Some(message) = self.on_right_click.clone() { + widget = widget.on_right_press(message); + } + widget.into() }