status-area: Send opened/closed dbus menu events

This commit is contained in:
Ian Douglas Scott 2024-06-22 19:49:51 -07:00 • committed by Jeremy Soller
parent a5dfc883b8
commit 1eaccc0f24
2 changed files with 16 additions and 6 deletions

View file

@ -150,11 +150,11 @@ impl cosmic::Application for App {
None None
}; };
if self.open_menu.is_some() { if self.open_menu.is_some() {
self.menus[&id].about_to_show(); self.menus[&id].opened();
let mut cmds = Vec::new(); let mut cmds = Vec::new();
if let Some(id) = self.popup.take() { if let Some(popup_id) = self.popup.take() {
cmds.push(destroy_popup(id)); cmds.push(destroy_popup(popup_id));
} }
let popup_id = self.next_popup_id(); let popup_id = self.next_popup_id();
let mut popup_settings = self.core.applet.get_popup_settings( let mut popup_settings = self.core.applet.get_popup_settings(
@ -180,8 +180,10 @@ impl cosmic::Application for App {
} }
cmds.push(get_popup(popup_settings)); cmds.push(get_popup(popup_settings));
return Command::batch(cmds); return Command::batch(cmds);
} else if let Some(id) = self.popup { } else if let Some(popup_id) = self.popup {
return destroy_popup(id); self.menus[&id].closed();
return destroy_popup(popup_id);
} }
Command::none() Command::none()
} }

View file

@ -84,12 +84,20 @@ impl State {
self.item.layout_subscription().map(Msg::Layout) self.item.layout_subscription().map(Msg::Layout)
} }
pub fn about_to_show(&self) { pub fn opened(&self) {
let menu_proxy = self.item.menu_proxy().clone(); let menu_proxy = self.item.menu_proxy().clone();
tokio::spawn(async move { tokio::spawn(async move {
let _ = menu_proxy.event(0, "opened", &0i32.into(), 0).await;
let _ = menu_proxy.about_to_show(0).await; let _ = menu_proxy.about_to_show(0).await;
}); });
} }
pub fn closed(&self) {
let menu_proxy = self.item.menu_proxy().clone();
tokio::spawn(async move {
let _ = menu_proxy.event(0, "closed", &0i32.into(), 0).await;
});
}
} }
fn layout_view(layout: &Layout, expanded: Option<i32>) -> cosmic::Element<Msg> { fn layout_view(layout: &Layout, expanded: Option<i32>) -> cosmic::Element<Msg> {