From e77fb436ed8e7064ca7dc63e8ab714996d817ba7 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Thu, 8 Aug 2024 20:01:57 +0859 Subject: [PATCH] fix: try to support a mini notification widget --- src/main.rs | 1 + src/notifications.rs | 103 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/notifications.rs diff --git a/src/main.rs b/src/main.rs index 414be1d..6efbac4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use iced_runtime::window::Action as WindowAction; mod aximer; mod launcher; mod zbus_mpirs; +mod notifications; type LaLaShellIdAction = LayershellCustomActionsWithIdAndInfo; type LalaShellAction = LayershellCustomActionsWithInfo; diff --git a/src/notifications.rs b/src/notifications.rs new file mode 100644 index 0000000..6a2cc3c --- /dev/null +++ b/src/notifications.rs @@ -0,0 +1,103 @@ +//! # D-Bus interface proxy for: `org.freedesktop.Notifications` +//! +//! This code was generated by `zbus-xmlgen` `4.1.0` from D-Bus introspection data. +//! Source: `Interface '/org/freedesktop/Notifications' from service 'org.freedesktop.Notifications' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the [Writing a client proxy] section of the zbus +//! documentation. +//! +//! This type implements the [D-Bus standard interfaces], (`org.freedesktop.DBus.*`) for which the +//! following zbus API can be used: +//! +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! +//! Consequently `zbus-xmlgen` did not generate code for the above interfaces. +//! +//! [Writing a client proxy]: https://dbus2.github.io/zbus/client.html +//! [D-Bus standard interfaces]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces, +use zbus::{interface, object_server::SignalContext, zvariant::OwnedValue}; + +const NOTIFICATION_DELTED_BY_EXPIRED: u32 = 1; +const NOTIFICATION_DELTED_BY_USER: u32 = 2; +const NOTIFICATION_CLOSED_BY_DBUS: u32 = 3; +const NOTIFICATION_COLSED_BY_UNKNOWN_REASON: u32 = 4; + +pub struct NotifyUnit { + app_name: String, + id: u32, + icon: String, + summery: String, + actions: Vec, + timeout: i32, +} + +pub struct LaLaMako { + units: Vec +} + +#[interface(name = "org.freedesktop.Notifications")] +impl LaLaMako { + // CloseNotification method + async fn close_notification(&mut self, id: u32) -> zbus::fdo::Result<()> { + Ok(()) + } + + /// GetCapabilities method + fn get_capabilities(&self) -> Vec { + vec![ + "body".to_owned(), + "body-markup".to_owned(), + "actions".to_owned(), + "icon-static".to_owned(), + "x-canonical-private-synchronous".to_owned(), + "x-dunst-stack-tag".to_owned(), + ] + } + + /// GetServerInformation method + fn get_server_information(&self) -> (String, String, String, String) { + ( + "LaLaMako".to_owned(), + "waycrate".to_owned(), + env!("CARGO_PKG_VERSION").to_owned(), + env!("CARGO_PKG_VERSION_PATCH").to_owned(), + ) + } + + // Notify method + #[allow(clippy::too_many_arguments)] + fn notify( + &mut self, + app_name: &str, + id: u32, + icon: &str, + summery: &str, + body: &str, + actions: Vec<&str>, + hints: std::collections::HashMap<&str, OwnedValue>, + timeout: i32, + ) -> zbus::fdo::Result { + Ok(0) + } + + #[zbus(signal)] + async fn action_invoked( + &self, + ctx: &SignalContext<'_>, + id: u32, + action_key: &str, + ) -> zbus::Result<()>; + + // NotificationClosed signal + #[zbus(signal)] + async fn notification_closed( + &self, + ctx: &SignalContext<'_>, + id: u32, + reason: u32, + ) -> zbus::Result<()>; +}