diff --git a/src/notification_list.rs b/src/notification_list.rs index b8f8eff9..9397ddad 100644 --- a/src/notification_list.rs +++ b/src/notification_list.rs @@ -35,7 +35,7 @@ impl ObjectImpl for NotificationListInner { ..set_parent(obj); ..connect_row_activated(clone!(@weak obj => move |_, row| { if let Some(id) = obj.id_for_row(row) { - // TODO + obj.inner().notifications.invoke_action(id, "default"); } })); }; diff --git a/src/notification_popover.rs b/src/notification_popover.rs index 8736a9e0..a51fafc7 100644 --- a/src/notification_popover.rs +++ b/src/notification_popover.rs @@ -7,7 +7,7 @@ use gtk4::{ use crate::deref_cell::DerefCell; use crate::notification_widget::NotificationWidget; -use crate::notifications::{Notification, Notifications}; +use crate::notifications::{Notification, NotificationId, Notifications}; #[derive(Default)] pub struct NotificationPopoverInner { @@ -27,6 +27,9 @@ impl ObjectImpl for NotificationPopoverInner { obj.add_controller(&cascade! { gtk4::GestureClick::new(); ..connect_pressed(clone!(@weak obj => move |_, _, _, _| { + if let Some(id) = obj.id() { + obj.inner().notifications.invoke_action(id, "default"); + } obj.popdown(); })); }); @@ -64,7 +67,7 @@ impl NotificationPopover { obj.handle_notification(¬ification); })); notifications.connect_notification_closed(clone!(@weak obj => move |id| { - if obj.inner().notification_widget.id() == Some(id) { + if obj.id() == Some(id) { obj.popdown(); } })); @@ -76,6 +79,10 @@ impl NotificationPopover { NotificationPopoverInner::from_instance(self) } + fn id(&self) -> Option { + self.inner().notification_widget.id() + } + fn handle_notification(&self, notification: &Notification) { self.inner() .notification_widget diff --git a/src/notifications.rs b/src/notifications.rs index 5a0a2000..e58a4cea 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -207,6 +207,12 @@ impl From for u32 { } } +impl ToVariant for NotificationId { + fn to_variant(&self) -> glib::Variant { + self.0.get().to_variant() + } +} + impl NotificationId { fn new(value: u32) -> Option { NonZeroU32::new(value).map(Self) @@ -308,7 +314,7 @@ impl Notifications { PATH, INTERFACE, "CloseNotification", - Some(&(&(reason as u32),).to_variant()), + Some(&(id, &(reason as u32)).to_variant()), ) .unwrap(); } @@ -318,6 +324,20 @@ impl Notifications { self.close_notification(id, CloseReason::Dismiss); } + pub fn invoke_action(&self, id: NotificationId, action_key: &str) { + if let Some(connection) = self.inner().connection.borrow().as_ref() { + connection + .emit_signal( + None, + PATH, + INTERFACE, + "ActionInvoked", + Some(&(&(id, action_key),).to_variant()), + ) + .unwrap(); + } + } + fn bus_acquired(&self, connection: gio::DBusConnection, _name: &str) { *self.inner().connection.borrow_mut() = Some(connection); }