From d1e1ef3a825ed681522c8e05ad7a34ff50b389d9 Mon Sep 17 00:00:00 2001 From: deepend Date: Fri, 30 Jan 2026 19:37:29 -0700 Subject: [PATCH] Documented the GTK3 tray backend choice and added GTK3-safe tooltip property handling with a title fallback while keeping GTK2 APIs gated behind build flags. Guarded embedded notification handling by GTK version to avoid GTK2-only APIs on GTK3 builds. --- src/fe-gtk/plugin-tray.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/fe-gtk/plugin-tray.c b/src/fe-gtk/plugin-tray.c index 88fc11f3..ed9e5898 100644 --- a/src/fe-gtk/plugin-tray.c +++ b/src/fe-gtk/plugin-tray.c @@ -63,6 +63,7 @@ typedef enum } WinStatus; #if HAVE_GTK3 +/* GTK3: keep GtkStatusIcon and use tooltip/text properties for tray tooltips. */ typedef const char *TrayIcon; typedef char *TrayCustomIcon; #define tray_icon_from_file(f) g_strdup(f) @@ -192,7 +193,20 @@ static void tray_set_tooltip_text (GtkStatusIcon *icon, const char *text) { #if HAVE_GTK3 - g_object_set (G_OBJECT (icon), "tooltip-text", text, NULL); + GObjectClass *klass; + + if (!icon) + return; + + klass = G_OBJECT_GET_CLASS (icon); + if (klass && g_object_class_find_property (klass, "tooltip-text")) + { + g_object_set (G_OBJECT (icon), "tooltip-text", text, NULL); + } + else if (klass && g_object_class_find_property (klass, "title")) + { + g_object_set (G_OBJECT (icon), "title", text, NULL); + } #endif #if !HAVE_GTK3 gtk_status_icon_set_tooltip_text (icon, text); @@ -223,8 +237,14 @@ tray_is_embedded (GtkStatusIcon *icon) void fe_tray_set_tooltip (const char *text) { - if (sticon) - tray_set_tooltip_text (sticon, text); + if (!sticon) + return; +#if HAVE_GTK3 + tray_set_tooltip_text (sticon, text); +#endif +#if !HAVE_GTK3 + tray_set_tooltip_text (sticon, text); +#endif } static void @@ -464,6 +484,16 @@ tray_menu_notify_cb (GObject *tray, GParamSpec *pspec, gpointer user_data) { if (sticon) { +#if HAVE_GTK3 + if (!tray_is_embedded (sticon)) + tray_restore_timer = g_timeout_add(500, (GSourceFunc)tray_menu_try_restore, NULL); + else if (tray_restore_timer) + { + g_source_remove (tray_restore_timer); + tray_restore_timer = 0; + } +#endif +#if !HAVE_GTK3 if (!tray_is_embedded (sticon)) { tray_restore_timer = g_timeout_add(500, (GSourceFunc)tray_menu_try_restore, NULL); @@ -476,6 +506,7 @@ tray_menu_notify_cb (GObject *tray, GParamSpec *pspec, gpointer user_data) tray_restore_timer = 0; } } +#endif } }