WIP send signal on notify
This commit is contained in:
parent
069e1a24f9
commit
e62824a4fc
1 changed files with 25 additions and 6 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
use gtk4::{
|
use gtk4::{
|
||||||
gio,
|
gio,
|
||||||
glib::{self, clone},
|
glib::{self, clone, subclass::Signal, SignalHandlerId},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
subclass::prelude::*,
|
subclass::prelude::*,
|
||||||
};
|
};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use std::{borrow::Cow, cell::Cell, collections::HashMap, fmt, num::NonZeroU32};
|
use std::{borrow::Cow, cell::Cell, collections::HashMap, fmt, num::NonZeroU32};
|
||||||
|
|
||||||
static NOTIFICATIONS_XML: &str = "
|
static NOTIFICATIONS_XML: &str = "
|
||||||
|
|
@ -66,7 +67,14 @@ impl ObjectSubclass for NotificationsInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for NotificationsInner {}
|
impl ObjectImpl for NotificationsInner {
|
||||||
|
fn signals() -> &'static [Signal] {
|
||||||
|
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
|
||||||
|
vec![Signal::builder("notification-received", &[], glib::Type::UNIT.into()).build()]
|
||||||
|
});
|
||||||
|
SIGNALS.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct Notifications(ObjectSubclass<NotificationsInner>);
|
pub struct Notifications(ObjectSubclass<NotificationsInner>);
|
||||||
|
|
@ -192,7 +200,7 @@ impl Notifications {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn notify(
|
fn handle_notify(
|
||||||
&self,
|
&self,
|
||||||
app_name: String,
|
app_name: String,
|
||||||
replaces_id: Option<NonZeroU32>,
|
replaces_id: Option<NonZeroU32>,
|
||||||
|
|
@ -221,10 +229,13 @@ impl Notifications {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
self.emit_by_name("notification-received", &[]).unwrap();
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_notification(&self, _id: u32) {}
|
fn handle_close_notification(&self, _id: u32) {}
|
||||||
|
|
||||||
fn bus_acquired(&self, _connection: gio::DBusConnection, _name: &str) {}
|
fn bus_acquired(&self, _connection: gio::DBusConnection, _name: &str) {}
|
||||||
|
|
||||||
|
|
@ -244,13 +255,13 @@ impl Notifications {
|
||||||
"Notify" => {
|
"Notify" => {
|
||||||
let (app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout) = args.get().unwrap();
|
let (app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout) = args.get().unwrap();
|
||||||
let replaces_id = NonZeroU32::new(replaces_id);
|
let replaces_id = NonZeroU32::new(replaces_id);
|
||||||
let res = self_.notify(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout);
|
let res = self_.handle_notify(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout);
|
||||||
invocation.return_value(Some(&(u32::from(res),).to_variant()));
|
invocation.return_value(Some(&(u32::from(res),).to_variant()));
|
||||||
// TODO error?
|
// TODO error?
|
||||||
}
|
}
|
||||||
"CloseNotification" => {
|
"CloseNotification" => {
|
||||||
let (id,) = args.get::<(u32,)>().unwrap();
|
let (id,) = args.get::<(u32,)>().unwrap();
|
||||||
self_.close_notification(id);
|
self_.handle_close_notification(id);
|
||||||
invocation.return_value(None);
|
invocation.return_value(None);
|
||||||
// TODO error?
|
// TODO error?
|
||||||
}
|
}
|
||||||
|
|
@ -289,4 +300,12 @@ impl Notifications {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name_lost(&self, _connection: Option<gio::DBusConnection>, _name: &str) {}
|
fn name_lost(&self, _connection: Option<gio::DBusConnection>, _name: &str) {}
|
||||||
|
|
||||||
|
pub fn connect_notification_recieved<F: Fn() + 'static>(&self, cb: F) -> SignalHandlerId {
|
||||||
|
self.connect_local("notification-received", false, move |_values| {
|
||||||
|
cb();
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue