notifications: initial logic for sending action signal
This commit is contained in:
parent
94def67e85
commit
13aa62cef8
3 changed files with 31 additions and 4 deletions
|
|
@ -35,7 +35,7 @@ impl ObjectImpl for NotificationListInner {
|
||||||
..set_parent(obj);
|
..set_parent(obj);
|
||||||
..connect_row_activated(clone!(@weak obj => move |_, row| {
|
..connect_row_activated(clone!(@weak obj => move |_, row| {
|
||||||
if let Some(id) = obj.id_for_row(row) {
|
if let Some(id) = obj.id_for_row(row) {
|
||||||
// TODO
|
obj.inner().notifications.invoke_action(id, "default");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use gtk4::{
|
||||||
|
|
||||||
use crate::deref_cell::DerefCell;
|
use crate::deref_cell::DerefCell;
|
||||||
use crate::notification_widget::NotificationWidget;
|
use crate::notification_widget::NotificationWidget;
|
||||||
use crate::notifications::{Notification, Notifications};
|
use crate::notifications::{Notification, NotificationId, Notifications};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct NotificationPopoverInner {
|
pub struct NotificationPopoverInner {
|
||||||
|
|
@ -27,6 +27,9 @@ impl ObjectImpl for NotificationPopoverInner {
|
||||||
obj.add_controller(&cascade! {
|
obj.add_controller(&cascade! {
|
||||||
gtk4::GestureClick::new();
|
gtk4::GestureClick::new();
|
||||||
..connect_pressed(clone!(@weak obj => move |_, _, _, _| {
|
..connect_pressed(clone!(@weak obj => move |_, _, _, _| {
|
||||||
|
if let Some(id) = obj.id() {
|
||||||
|
obj.inner().notifications.invoke_action(id, "default");
|
||||||
|
}
|
||||||
obj.popdown();
|
obj.popdown();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
@ -64,7 +67,7 @@ impl NotificationPopover {
|
||||||
obj.handle_notification(¬ification);
|
obj.handle_notification(¬ification);
|
||||||
}));
|
}));
|
||||||
notifications.connect_notification_closed(clone!(@weak obj => move |id| {
|
notifications.connect_notification_closed(clone!(@weak obj => move |id| {
|
||||||
if obj.inner().notification_widget.id() == Some(id) {
|
if obj.id() == Some(id) {
|
||||||
obj.popdown();
|
obj.popdown();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
@ -76,6 +79,10 @@ impl NotificationPopover {
|
||||||
NotificationPopoverInner::from_instance(self)
|
NotificationPopoverInner::from_instance(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> Option<NotificationId> {
|
||||||
|
self.inner().notification_widget.id()
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_notification(&self, notification: &Notification) {
|
fn handle_notification(&self, notification: &Notification) {
|
||||||
self.inner()
|
self.inner()
|
||||||
.notification_widget
|
.notification_widget
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,12 @@ impl From<NotificationId> for u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToVariant for NotificationId {
|
||||||
|
fn to_variant(&self) -> glib::Variant {
|
||||||
|
self.0.get().to_variant()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl NotificationId {
|
impl NotificationId {
|
||||||
fn new(value: u32) -> Option<Self> {
|
fn new(value: u32) -> Option<Self> {
|
||||||
NonZeroU32::new(value).map(Self)
|
NonZeroU32::new(value).map(Self)
|
||||||
|
|
@ -308,7 +314,7 @@ impl Notifications {
|
||||||
PATH,
|
PATH,
|
||||||
INTERFACE,
|
INTERFACE,
|
||||||
"CloseNotification",
|
"CloseNotification",
|
||||||
Some(&(&(reason as u32),).to_variant()),
|
Some(&(id, &(reason as u32)).to_variant()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -318,6 +324,20 @@ impl Notifications {
|
||||||
self.close_notification(id, CloseReason::Dismiss);
|
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) {
|
fn bus_acquired(&self, connection: gio::DBusConnection, _name: &str) {
|
||||||
*self.inner().connection.borrow_mut() = Some(connection);
|
*self.inner().connection.borrow_mut() = Some(connection);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue