From cc8da887e6249afad10cb8ffb2bc1018b035209e Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 9 Sep 2021 07:38:18 -0700 Subject: [PATCH] WIP show notification --- src/notifications.rs | 12 ++++++------ src/time_button.rs | 24 ++++++++++++++++++++++-- src/window.rs | 18 +++++++----------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/notifications.rs b/src/notifications.rs index a55c1a8e..2022a5b9 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -214,12 +214,12 @@ impl NotificationId { #[derive(Debug)] #[allow(dead_code)] pub struct Notification { - id: NotificationId, - app_name: String, - app_icon: String, // decode? - summary: String, - body: String, - actions: Vec, // enum? + pub id: NotificationId, + pub app_name: String, + pub app_icon: String, // decode? + pub summary: String, + pub body: String, + pub actions: Vec, // enum? hints: Hints, } diff --git a/src/time_button.rs b/src/time_button.rs index dbacdfad..9474e7ff 100644 --- a/src/time_button.rs +++ b/src/time_button.rs @@ -6,9 +6,11 @@ use gtk4::{ subclass::prelude::*, }; +use crate::application::PanelApp; use crate::deref_cell::DerefCell; use crate::mpris::MprisControls; use crate::notification_popover::NotificationPopover; +use crate::notifications::Notification; use crate::popover_container::PopoverContainer; #[derive(Default)] @@ -97,8 +99,18 @@ glib::wrapper! { } impl TimeButton { - pub fn new() -> Self { - glib::Object::new(&[]).unwrap() + pub fn new(app: &PanelApp) -> Self { + let obj = glib::Object::new::(&[]).unwrap(); + + let notifications = app.notifications().clone(); + app.notifications() + .connect_notification_recieved(clone!(@weak obj => move |id| { + if let Some(notification) = notifications.get(id) { + obj.handle_notification(¬ification); + } + })); + + obj } fn inner(&self) -> &TimeButtonInner { @@ -119,4 +131,12 @@ impl TimeButton { .set_label(&time.format("%b %-d %-I:%M %p").to_string()); // time.format("%B %-d %Y") } + + fn handle_notification(&self, notification: &Notification) { + println!("{:?}", notification); + + let popover = &self.inner().notification_popover; + popover.set_body(¬ification.body); + popover.popup(); + } } diff --git a/src/window.rs b/src/window.rs index 25f03867..950dc9a0 100644 --- a/src/window.rs +++ b/src/window.rs @@ -31,6 +31,7 @@ fn button(text: &str) -> gtk4::Button { pub struct PanelWindowInner { size: Cell>, monitor: DerefCell, + box_: DerefCell, } #[glib::object_subclass] @@ -49,7 +50,6 @@ impl ObjectImpl for PanelWindowInner { ..append(&button("Workspaces")); ..append(&button("Applications")); })); - ..set_center_widget(Some(&TimeButton::new())); ..set_end_widget(Some(&StatusArea::new())); }; @@ -58,6 +58,8 @@ impl ObjectImpl for PanelWindowInner { ..set_decorated(false); ..set_child(Some(&box_)); }; + + self.box_.set(box_); } } @@ -130,17 +132,11 @@ impl PanelWindow { obj.set_size_request(monitor.geometry().width, 0); obj.inner().monitor.set(monitor); - app.add_window(&obj); + obj.inner() + .box_ + .set_center_widget(Some(&TimeButton::new(app))); - let notifications = app.notifications().clone(); - app.notifications() - .connect_notification_recieved(clone!(@weak obj => move |id| { - let notification = notifications.get(id); - println!( - "{:?}", - notification - ); - })); + app.add_window(&obj); obj }