summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/common/util.c12
-rw-r--r--src/common/util.h1
-rw-r--r--src/fe-gtk/gtkutil.c30
-rw-r--r--src/fe-gtk/gtkutil.h1
-rw-r--r--src/fe-gtk/maingui.c8
-rw-r--r--src/fe-gtk/meson.build7
-rw-r--r--src/fe-gtk/plugin-tray.c7
-rw-r--r--src/fe-gtk/setup.c5
8 files changed, 50 insertions, 21 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 8f4c3abe..6c665dbc 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1363,18 +1363,6 @@ portable_mode (void)
 #endif
 }
 
-int
-unity_mode (void)
-{
-#ifdef G_OS_UNIX
-	const char *env = g_getenv("XDG_CURRENT_DESKTOP");
-	if (env && (strcmp (env, "Unity") == 0
-			|| strcmp (env, "Pantheon") == 0))
-		return 1;
-#endif
-	return 0;
-}
-
 char *
 encode_sasl_pass_plain (char *user, char *pass)
 {
diff --git a/src/common/util.h b/src/common/util.h
index 2ec1fa92..fcb23834 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -76,7 +76,6 @@ guint32 str_ihash (const unsigned char *key);
 void safe_strcpy (char *dest, const char *src, int bytes_left);
 void canonalize_key (char *key);
 int portable_mode (void);
-int unity_mode (void);
 char *encode_sasl_pass_plain (char *user, char *pass);
 char *challengeauth_response (const char *username, const char *password, const char *challenge);
 size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time);
diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c
index 878f5c6e..674ad4fc 100644
--- a/src/fe-gtk/gtkutil.c
+++ b/src/fe-gtk/gtkutil.c
@@ -31,6 +31,10 @@
 #include <pango/pangocairo.h>
 #endif
 
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
+
 #include "../common/hexchat.h"
 #include "../common/fe.h"
 #include "../common/util.h"
@@ -735,6 +739,32 @@ gtkutil_treeview_get_selected (GtkTreeView *view, GtkTreeIter *iter_ret, ...)
 	return has_selected;
 }
 
+gboolean
+gtkutil_tray_icon_supported (GtkWindow *window)
+{
+#ifndef GDK_WINDOWING_X11
+	return TRUE;
+#else
+	GdkScreen *screen = gtk_window_get_screen (window);
+	GdkDisplay *display = gdk_screen_get_display (screen);
+	int screen_number = gdk_screen_get_number (screen);
+	Display *xdisplay = gdk_x11_display_get_xdisplay (display);
+	char *selection_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d", screen_number);
+	Atom selection_atom = XInternAtom (xdisplay, selection_name, False);
+	Window tray_window = None;
+
+	XGrabServer (xdisplay);
+
+	tray_window = XGetSelectionOwner (xdisplay, selection_atom);
+
+	XUngrabServer (xdisplay);
+	XFlush (xdisplay);
+	g_free (selection_name);
+
+	return (tray_window != None);
+#endif
+}
+
 #if defined (WIN32) || defined (__APPLE__)
 gboolean
 gtkutil_find_font (const char *fontname)
diff --git a/src/fe-gtk/gtkutil.h b/src/fe-gtk/gtkutil.h
index 9547cb3b..0aa36439 100644
--- a/src/fe-gtk/gtkutil.h
+++ b/src/fe-gtk/gtkutil.h
@@ -43,6 +43,7 @@ GtkWidget *gtkutil_treeview_new (GtkWidget *box, GtkTreeModel *model,
 gboolean gtkutil_treemodel_string_to_iter (GtkTreeModel *model, gchar *pathstr, GtkTreeIter *iter_ret);
 gboolean gtkutil_treeview_get_selected_iter (GtkTreeView *view, GtkTreeIter *iter_ret);
 gboolean gtkutil_treeview_get_selected (GtkTreeView *view, GtkTreeIter *iter_ret, ...);
+gboolean gtkutil_tray_icon_supported (GtkWindow *window);
 
 #if defined (WIN32) || defined (__APPLE__)
 gboolean gtkutil_find_font (const char *fontname);
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c
index 20edf1ba..145f4096 100644
--- a/src/fe-gtk/maingui.c
+++ b/src/fe-gtk/maingui.c
@@ -51,6 +51,7 @@
 #include "plugin-tray.h"
 #include "xtext.h"
 #include "sexy-spell-entry.h"
+#include "gtkutil.h"
 
 #define GUI_SPACING (3)
 #define GUI_BORDER (0)
@@ -430,7 +431,7 @@ mg_windowstate_cb (GtkWindow *wid, GdkEventWindowState *event, gpointer userdata
 	if ((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) &&
 		 (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) &&
 		 prefs.hex_gui_tray_minimize && prefs.hex_gui_tray &&
-		 !unity_mode ())
+		 gtkutil_tray_icon_supported (wid))
 	{
 		tray_toggle_visibility (TRUE);
 		gtk_window_deiconify (wid);
@@ -1215,7 +1216,7 @@ mg_open_quit_dialog (gboolean minimize_button)
 	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1),
 										GTK_BUTTONBOX_END);
 
-	if (minimize_button && !unity_mode ())
+	if (minimize_button && gtkutil_tray_icon_supported (GTK_WINDOW(dialog)))
 	{
 		button = gtk_button_new_with_mnemonic (_("_Minimize to Tray"));
 		gtk_widget_show (button);
@@ -3176,8 +3177,9 @@ mg_tabwindow_de_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
 {
 	GSList *list;
 	session *sess;
+	GtkWindow *win = GTK_WINDOW(gtk_widget_get_toplevel (widget));
 
-	if (prefs.hex_gui_tray_close && !unity_mode () && tray_toggle_visibility (FALSE))
+	if (prefs.hex_gui_tray_close && gtkutil_tray_icon_supported (win) && tray_toggle_visibility (FALSE))
 		return TRUE;
 
 	/* check for remaining toplevel windows */
diff --git a/src/fe-gtk/meson.build b/src/fe-gtk/meson.build
index 731709b1..ba5b2779 100644
--- a/src/fe-gtk/meson.build
+++ b/src/fe-gtk/meson.build
@@ -28,12 +28,17 @@ hexchat_gtk_sources = [
   'xtext.c'
 ]
 
+gtk_dep = dependency('gtk+-2.0', version: '>= 2.24.0')
 hexchat_gtk_deps = [
   hexchat_common_dep,
   libgmodule_dep, # used by libsexy
-  dependency('gtk+-2.0', version: '>= 2.24.0')
+  gtk_dep
 ]
 
+if gtk_dep.get_pkgconfig_variable('target') == 'x11'
+  hexchat_gtk_deps += dependency('x11')
+endif
+
 hexchat_gtk_cflags = [
   '-fPIE'
 ]
diff --git a/src/fe-gtk/plugin-tray.c b/src/fe-gtk/plugin-tray.c
index 48defb1f..b5f1624a 100644
--- a/src/fe-gtk/plugin-tray.c
+++ b/src/fe-gtk/plugin-tray.c
@@ -29,6 +29,7 @@
 #include "pixmaps.h"
 #include "maingui.h"
 #include "menu.h"
+#include "gtkutil.h"
 
 #ifndef WIN32
 #include <unistd.h>
@@ -759,7 +760,8 @@ tray_apply_setup (void)
 	}
 	else
 	{
-		if (prefs.hex_gui_tray && !unity_mode ())
+		GtkWindow *window = GTK_WINDOW(hexchat_get_info (ph, "gtkwin_ptr"));
+		if (prefs.hex_gui_tray && gtkutil_tray_icon_supported (window))
 			tray_init ();
 	}
 }
@@ -793,7 +795,8 @@ tray_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name,
 
 	hexchat_hook_print (ph, "Focus Window", -1, tray_focus_cb, NULL);
 
-	if (prefs.hex_gui_tray && !unity_mode ())
+	GtkWindow *window = GTK_WINDOW(hexchat_get_info (ph, "gtkwin_ptr"));
+	if (prefs.hex_gui_tray && gtkutil_tray_icon_supported (window))
 		tray_init ();
 
 	return 1;       /* return 1 for success */
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index 95e938c9..309db53a 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -1895,6 +1895,7 @@ static GtkWidget *
 setup_create_pages (GtkWidget *box)
 {
 	GtkWidget *book;
+	GtkWindow *win = GTK_WINDOW(gtk_widget_get_toplevel (box));
 
 	book = gtk_notebook_new ();
 
@@ -1906,11 +1907,11 @@ setup_create_pages (GtkWidget *box)
 
 	setup_add_page (cata[8], book, setup_create_page (general_settings));
 
-	if (unity_mode () && !notification_backend_supported ())
+	if (!gtkutil_tray_icon_supported (win) && !notification_backend_supported ())
 	{
 		setup_add_page (cata[9], book, setup_create_page (alert_settings_unityandnonotifications));
 	}
-	else if (unity_mode ())
+	else if (!gtkutil_tray_icon_supported (win))
 	{
 		setup_add_page (cata[9], book, setup_create_page (alert_settings_unity));
 	}