mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-18 19:50:18 +00:00
Merge pull request #109 from ZoiteChat/fix-tray-icon-restore-hide
fix: keep tray hide/restore label synced to real window state
This commit is contained in:
@@ -122,6 +122,9 @@ static void tray_init (void);
|
|||||||
static void tray_set_icon_state (TrayIcon icon, TrayIconState state);
|
static void tray_set_icon_state (TrayIcon icon, TrayIconState state);
|
||||||
static void tray_menu_restore_cb (GtkWidget *item, gpointer userdata);
|
static void tray_menu_restore_cb (GtkWidget *item, gpointer userdata);
|
||||||
static void tray_menu_notify_cb (GObject *tray, GParamSpec *pspec, gpointer user_data);
|
static void tray_menu_notify_cb (GObject *tray, GParamSpec *pspec, gpointer user_data);
|
||||||
|
static void tray_update_toggle_item_label (void);
|
||||||
|
static gboolean tray_window_state_cb (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata);
|
||||||
|
static void tray_window_visibility_cb (GtkWidget *widget, gpointer userdata);
|
||||||
#if HAVE_APPINDICATOR_BACKEND
|
#if HAVE_APPINDICATOR_BACKEND
|
||||||
static void tray_menu_show_cb (GtkWidget *menu, gpointer userdata) G_GNUC_UNUSED;
|
static void tray_menu_show_cb (GtkWidget *menu, gpointer userdata) G_GNUC_UNUSED;
|
||||||
#endif
|
#endif
|
||||||
@@ -165,6 +168,7 @@ static int tray_pub_count = 0;
|
|||||||
static int tray_hilight_count = 0;
|
static int tray_hilight_count = 0;
|
||||||
static int tray_file_count = 0;
|
static int tray_file_count = 0;
|
||||||
static int tray_restore_timer = 0;
|
static int tray_restore_timer = 0;
|
||||||
|
static GtkWidget *tray_toggle_item = NULL;
|
||||||
|
|
||||||
#if HAVE_APPINDICATOR_BACKEND
|
#if HAVE_APPINDICATOR_BACKEND
|
||||||
static TrayCustomIcon
|
static TrayCustomIcon
|
||||||
@@ -890,6 +894,8 @@ tray_toggle_visibility (gboolean force_hide)
|
|||||||
gtk_window_present (win);
|
gtk_window_present (win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tray_update_toggle_item_label ();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1083,10 +1089,8 @@ tray_menu_populate (GtkWidget *menu)
|
|||||||
/* ph may have an invalid context now */
|
/* ph may have an invalid context now */
|
||||||
zoitechat_set_context (ph, zoitechat_find_context (ph, NULL, NULL));
|
zoitechat_set_context (ph, zoitechat_find_context (ph, NULL, NULL));
|
||||||
|
|
||||||
if (tray_get_window_status () == WS_HIDDEN)
|
tray_toggle_item = tray_make_item (menu, _("_Hide Window"), tray_menu_restore_cb, NULL);
|
||||||
tray_make_item (menu, _("_Restore Window"), tray_menu_restore_cb, NULL);
|
tray_update_toggle_item_label ();
|
||||||
else
|
|
||||||
tray_make_item (menu, _("_Hide Window"), tray_menu_restore_cb, NULL);
|
|
||||||
tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);
|
tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);
|
||||||
|
|
||||||
#ifndef WIN32 /* submenus are buggy on win32 */
|
#ifndef WIN32 /* submenus are buggy on win32 */
|
||||||
@@ -1128,8 +1132,28 @@ tray_menu_clear (GtkWidget *menu)
|
|||||||
for (iter = children; iter; iter = iter->next)
|
for (iter = children; iter; iter = iter->next)
|
||||||
gtk_widget_destroy (GTK_WIDGET (iter->data));
|
gtk_widget_destroy (GTK_WIDGET (iter->data));
|
||||||
g_list_free (children);
|
g_list_free (children);
|
||||||
|
tray_toggle_item = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
tray_update_toggle_item_label (void)
|
||||||
|
{
|
||||||
|
const char *label;
|
||||||
|
|
||||||
|
if (!tray_toggle_item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tray_get_window_status () == WS_HIDDEN)
|
||||||
|
label = _("_Restore Window");
|
||||||
|
else
|
||||||
|
label = _("_Hide Window");
|
||||||
|
|
||||||
|
gtk_menu_item_set_label (GTK_MENU_ITEM (tray_toggle_item), label);
|
||||||
|
gtk_menu_item_set_use_underline (GTK_MENU_ITEM (tray_toggle_item), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(WIN32)
|
||||||
static void G_GNUC_UNUSED
|
static void G_GNUC_UNUSED
|
||||||
tray_menu_show_cb (GtkWidget *menu, gpointer userdata)
|
tray_menu_show_cb (GtkWidget *menu, gpointer userdata)
|
||||||
{
|
{
|
||||||
@@ -1140,6 +1164,27 @@ tray_menu_show_cb (GtkWidget *menu, gpointer userdata)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
tray_window_state_cb (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
|
||||||
|
{
|
||||||
|
(void)widget;
|
||||||
|
(void)event;
|
||||||
|
(void)userdata;
|
||||||
|
|
||||||
|
tray_update_toggle_item_label ();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tray_window_visibility_cb (GtkWidget *widget, gpointer userdata)
|
||||||
|
{
|
||||||
|
(void)widget;
|
||||||
|
(void)userdata;
|
||||||
|
|
||||||
|
tray_update_toggle_item_label ();
|
||||||
|
}
|
||||||
|
|
||||||
#if !HAVE_APPINDICATOR_BACKEND
|
#if !HAVE_APPINDICATOR_BACKEND
|
||||||
static void
|
static void
|
||||||
tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata)
|
tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata)
|
||||||
@@ -1381,6 +1426,19 @@ tray_plugin_init (zoitechat_plugin *plugin_handle, char **plugin_name,
|
|||||||
zoitechat_hook_print (ph, "Focus Window", -1, tray_focus_cb, NULL);
|
zoitechat_hook_print (ph, "Focus Window", -1, tray_focus_cb, NULL);
|
||||||
|
|
||||||
GtkWindow *window = GTK_WINDOW(zoitechat_get_info (ph, "gtkwin_ptr"));
|
GtkWindow *window = GTK_WINDOW(zoitechat_get_info (ph, "gtkwin_ptr"));
|
||||||
|
GtkWidget *window_widget;
|
||||||
|
|
||||||
|
if (window)
|
||||||
|
{
|
||||||
|
window_widget = GTK_WIDGET (window);
|
||||||
|
g_signal_connect (G_OBJECT (window_widget), "window-state-event",
|
||||||
|
G_CALLBACK (tray_window_state_cb), NULL);
|
||||||
|
g_signal_connect (G_OBJECT (window_widget), "show",
|
||||||
|
G_CALLBACK (tray_window_visibility_cb), NULL);
|
||||||
|
g_signal_connect (G_OBJECT (window_widget), "hide",
|
||||||
|
G_CALLBACK (tray_window_visibility_cb), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (prefs.hex_gui_tray && gtkutil_tray_icon_supported (window))
|
if (prefs.hex_gui_tray && gtkutil_tray_icon_supported (window))
|
||||||
tray_init ();
|
tray_init ();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user