Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

header_bar: Show window menu on right click #302

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/cosmic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub enum Message {
SurfaceClosed(window::Id),
/// Activate the application
Activate(String),
ShowWindowMenu,
}

#[derive(Default)]
Expand Down Expand Up @@ -408,6 +409,10 @@ impl<T: Application> Cosmic<T> {
return self.app.update(msg);
}
}
Message::ShowWindowMenu => {
#[cfg(not(feature = "wayland"))]
return window::show_window_menu(window::Id::MAIN);
}
}

iced::Command::none()
Expand Down
3 changes: 2 additions & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ impl<App: Application> 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()
Expand Down
9 changes: 9 additions & 0 deletions src/widget/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -45,6 +46,10 @@ pub struct HeaderBar<'a, Message> {
#[setters(strip_option)]
on_minimize: Option<Message>,

/// A message emitted when the header is right clicked.
#[setters(strip_option)]
on_right_click: Option<Message>,

/// The window id for the headerbar.
#[setters(strip_option)]
window_id: Option<iced::window::Id>,
Expand Down Expand Up @@ -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()
}

Expand Down
Loading