diff --git a/src/main.rs b/src/main.rs index 127007ba..994069e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use gtk4::{gdk, glib, prelude::*}; mod deref_cell; mod mpris; mod mpris_player; +mod notification_popover; mod notifications; mod popover_container; mod status_area; diff --git a/src/notification_popover.rs b/src/notification_popover.rs new file mode 100644 index 00000000..8b46319d --- /dev/null +++ b/src/notification_popover.rs @@ -0,0 +1,57 @@ +use cascade::cascade; +use gtk4::{ + glib::{self, clone}, + prelude::*, + subclass::prelude::*, +}; + +use crate::deref_cell::DerefCell; + +#[derive(Default)] +pub struct NotificationPopoverInner { + label: DerefCell, +} + +#[glib::object_subclass] +impl ObjectSubclass for NotificationPopoverInner { + const NAME: &'static str = "S76NotificationPopover"; + type ParentType = gtk4::Popover; + type Type = NotificationPopover; +} + +impl ObjectImpl for NotificationPopoverInner { + fn constructed(&self, obj: &NotificationPopover) { + let label = cascade! { + gtk4::Label::new(None); + }; + + cascade! { + obj; + ..set_autohide(false); + ..set_has_arrow(false); + ..set_offset(0, 12); + ..set_child(Some(&label)); + }; + + self.label.set(label); + } +} + +impl WidgetImpl for NotificationPopoverInner {} +impl PopoverImpl for NotificationPopoverInner {} + +glib::wrapper! { + pub struct NotificationPopover(ObjectSubclass) + @extends gtk4::Popover, gtk4::Widget; +} + +impl NotificationPopover { + pub fn new() -> Self { + let obj = glib::Object::new::(&[]).unwrap(); + obj + } + + fn inner(&self) -> &NotificationPopoverInner { + NotificationPopoverInner::from_instance(self) + } +} diff --git a/src/time_button.rs b/src/time_button.rs index a74215f9..dbacdfad 100644 --- a/src/time_button.rs +++ b/src/time_button.rs @@ -8,6 +8,7 @@ use gtk4::{ use crate::deref_cell::DerefCell; use crate::mpris::MprisControls; +use crate::notification_popover::NotificationPopover; use crate::popover_container::PopoverContainer; #[derive(Default)] @@ -15,6 +16,7 @@ pub struct TimeButtonInner { calendar: DerefCell, button: DerefCell, label: DerefCell, + notification_popover: DerefCell, } #[glib::object_subclass] @@ -60,9 +62,15 @@ impl ObjectImpl for TimeButtonInner { ..popover().bind_property("visible", &button, "active").flags(glib::BindingFlags::BIDIRECTIONAL).build(); }; + let notification_popover = cascade! { + NotificationPopover::new(); + ..set_parent(obj); + }; + self.calendar.set(calendar); self.button.set(button); self.label.set(label); + self.notification_popover.set(notification_popover); // TODO: better way to do this? glib::timeout_add_seconds_local( @@ -77,6 +85,7 @@ impl ObjectImpl for TimeButtonInner { fn dispose(&self, _obj: &TimeButton) { self.button.unparent(); + self.notification_popover.unparent(); } }