From a08491c122981590f1d5fa2108953d6a86915b10 Mon Sep 17 00:00:00 2001 From: o9000 Date: Wed, 13 May 2015 21:17:02 +0200 Subject: [PATCH] Workaround for empty systray icon in Google Chrome (misbehaving) - fix sorting --- src/config.c | 8 +++---- src/systray/systraybar.c | 48 +++++++++++++++++++++++++--------------- src/systray/systraybar.h | 2 ++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/config.c b/src/config.c index 0a05b2d..f7c3771 100644 --- a/src/config.c +++ b/src/config.c @@ -613,13 +613,13 @@ void add_entry (char *key, char *value) } else if (strcmp(key, "systray_sort") == 0) { if (strcmp(value, "descending") == 0) - systray.sort = -1; + systray.sort = SYSTRAY_SORT_DESCENDING; else if (strcmp(value, "ascending") == 0) - systray.sort = 1; + systray.sort = SYSTRAY_SORT_ASCENDING; else if (strcmp(value, "left2right") == 0) - systray.sort = 2; + systray.sort = SYSTRAY_SORT_LEFT2RIGHT; else if (strcmp(value, "right2left") == 0) - systray.sort = 3; + systray.sort = SYSTRAY_SORT_RIGHT2LEFT; } else if (strcmp(key, "systray_icon_size") == 0) { systray_max_icon_size = atoi(value); diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 7a78270..d686978 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -52,7 +52,7 @@ int refresh_systray; int systray_enabled; int systray_max_icon_size; int systray_monitor; - +int chrono; // background pixmap if we render ourselves the icons static Pixmap render_background; @@ -61,8 +61,9 @@ void default_systray() { memset(&systray, 0, sizeof(Systraybar)); render_background = 0; + chrono = 0; systray.alpha = 100; - systray.sort = 3; + systray.sort = SYSTRAY_SORT_LEFT2RIGHT; systray.area._draw_foreground = draw_systray; systray.area._on_change_layout = on_change_systray; systray.area.size_mode = SIZE_BY_CONTENT; @@ -345,24 +346,33 @@ static gint compare_traywindows(gconstpointer a, gconstpointer b) if (!traywin_a->empty && traywin_b->empty) return -1; - if (systray.sort < 2) - return 0; + if (systray.sort == SYSTRAY_SORT_ASCENDING || + systray.sort == SYSTRAY_SORT_DESCENDING) { + XTextProperty name_a, name_b; - XTextProperty name_a, name_b; + if (XGetWMName(server.dsp, traywin_a->tray_id, &name_a) == 0) { + return -1; + } + else if (XGetWMName(server.dsp, traywin_b->tray_id, &name_b) == 0) { + XFree(name_a.value); + return 1; + } + else { + gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) * + (systray.sort == SYSTRAY_SORT_ASCENDING ? 1 : -1); + XFree(name_a.value); + XFree(name_b.value); + return retval; + } + } - if(XGetWMName(server.dsp, traywin_a->tray_id, &name_a) == 0) { - return -1; - } - else if(XGetWMName(server.dsp, traywin_b->tray_id, &name_b) == 0) { - XFree(name_a.value); - return 1; - } - else { - gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) * systray.sort; - XFree(name_a.value); - XFree(name_b.value); - return retval; + if (systray.sort == SYSTRAY_SORT_LEFT2RIGHT || + systray.sort == SYSTRAY_SORT_RIGHT2LEFT) { + return (traywin_a->chrono - traywin_b->chrono) * + (systray.sort == SYSTRAY_SORT_LEFT2RIGHT ? 1 : -1); } + + return 0; } @@ -489,11 +499,13 @@ gboolean add_icon(Window id) traywin->damage = 0; traywin->empty = 0; traywin->pid = pid; + traywin->chrono = chrono; + chrono++; if (systray.area.on_screen == 0) show(&systray.area); - if (systray.sort == 3) + if (systray.sort == SYSTRAY_SORT_RIGHT2LEFT) systray.list_icons = g_slist_prepend(systray.list_icons, traywin); else systray.list_icons = g_slist_append(systray.list_icons, traywin); diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index 222b604..915564a 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -20,6 +20,7 @@ // Flags for _XEMBED_INFO #define XEMBED_MAPPED (1 << 0) +enum { SYSTRAY_SORT_ASCENDING, SYSTRAY_SORT_DESCENDING, SYSTRAY_SORT_LEFT2RIGHT, SYSTRAY_SORT_RIGHT2LEFT }; typedef struct { // always start with area @@ -45,6 +46,7 @@ typedef struct timeout* render_timeout; int empty; int pid; + int chrono; } TrayWindow;