@@ -58,15 +58,24 @@ namespace tray_linux {
5858 * @brief Acknowledge/click current notification
5959 * @param run_callback - Run notification callback when acknowledging
6060 */
61- void acknowledge_notification (const bool run_callback = false ) {
61+ void acknowledge_notification (const bool run_callback = false , const bool async = true ) {
6262 if (notify_is_initted ()) {
6363 std::scoped_lock lock (notification_mutex);
6464 if (notification_current != nullptr && NOTIFY_IS_NOTIFICATION (notification_current)) {
6565 if (run_callback && notification_current_callback != nullptr ) {
6666 notification_current_callback ();
6767 }
68- notify_notification_close (notification_current, nullptr );
69- g_object_unref (G_OBJECT (notification_current));
68+ GSourceFunc f = [](gpointer data) -> gboolean {
69+ auto n = static_cast <NotifyNotification *>(data);
70+ notify_notification_close (n, nullptr );
71+ g_object_unref (G_OBJECT (n));
72+ return false ; // Run once then remove from queue
73+ };
74+ if (async) {
75+ g_idle_add (f, notification_current);
76+ } else {
77+ f (notification_current);
78+ }
7079 notification_current = nullptr ;
7180 notification_current_callback = nullptr ;
7281 }
@@ -75,6 +84,36 @@ namespace tray_linux {
7584 }
7685 }
7786
87+ /* *
88+ * @brief Show tray notification via desktop-independent interface async via g_idle_add
89+ * @param data Tray structure containing notification information as a gpointer
90+ * @return false to run just once
91+ */
92+ gboolean async_notify_ (const gpointer data) {
93+ auto tray = static_cast <struct tray *>(data);
94+ if (notification_current != nullptr ) {
95+ acknowledge_notification (false , false );
96+ }
97+ std::scoped_lock lock (notification_mutex);
98+ std::filesystem::path notification_icon = tray->notification_icon != nullptr ? tray->notification_icon : tray->icon ;
99+ if (std::filesystem::exists (notification_icon)) {
100+ // Use absolute path for filesystem icon files, not a relative one
101+ notification_icon = std::filesystem::absolute (notification_icon);
102+ }
103+ notification_current = notify_notification_new (tray->notification_title , tray->notification_text , notification_icon.c_str ());
104+ if (notification_current != nullptr && NOTIFY_IS_NOTIFICATION (notification_current)) {
105+ if (tray->notification_cb != nullptr ) {
106+ notification_current_callback = tray->notification_cb ;
107+ notify_notification_add_action (notification_current, " default" , " Default" , NOTIFY_ACTION_CALLBACK (tray->notification_cb ), nullptr , nullptr );
108+ }
109+ // Fallback to QtTrayMenu notification if notificaton_show fails
110+ if (!notify_notification_show (notification_current, nullptr ) && qt_tray_menu != nullptr && QtTrayMenu::supportsMessages ()) {
111+ qt_tray_menu->showMessage (tray->notification_title , tray->notification_text , tray->notification_icon , tray->notification_cb );
112+ }
113+ }
114+ return false ; // Run once then remove from queue
115+ }
116+
78117 /* *
79118 * @brief Show tray notification via desktop-independent interface
80119 * @param tray Tray structure containing notification information
@@ -85,25 +124,7 @@ namespace tray_linux {
85124 }
86125 // Try to notify using libnotify
87126 if (notify_is_initted ()) {
88- if (notification_current != nullptr ) {
89- acknowledge_notification ();
90- }
91- std::scoped_lock lock (notification_mutex);
92- std::filesystem::path notification_icon = tray->notification_icon != nullptr ? tray->notification_icon : tray->icon ;
93- if (std::filesystem::exists (notification_icon)) {
94- // Use absolute path for filesystem icon files, not a relative one
95- notification_icon = std::filesystem::absolute (notification_icon);
96- }
97- notification_current = notify_notification_new (tray->notification_title , tray->notification_text , notification_icon.c_str ());
98- if (notification_current != nullptr && NOTIFY_IS_NOTIFICATION (notification_current)) {
99- if (tray->notification_cb != nullptr ) {
100- notification_current_callback = tray->notification_cb ;
101- notify_notification_add_action (notification_current, " default" , " Default" , NOTIFY_ACTION_CALLBACK (tray->notification_cb ), nullptr , nullptr );
102- }
103- if (notify_notification_show (notification_current, nullptr )) {
104- return ;
105- }
106- }
127+ g_idle_add (async_notify_, tray);
107128 }
108129 // Fallback to QtTrayMenu notification
109130 if (qt_tray_menu != nullptr && QtTrayMenu::supportsMessages ()) {
0 commit comments