Improve detection of system tray support

Closes #2045
This commit is contained in:
Patrick Griffis 2017-08-31 09:52:45 -04:00
parent 281038e725
commit d99cd18fb9
8 changed files with 50 additions and 21 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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 */

View File

@ -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'
]

View File

@ -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 */

View File

@ -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));
}