diff --git a/ChangeLog b/ChangeLog index 764ad16..51e690f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-05-07 master +- Fixes: + - Fixed crash in systray with non-Latin languagess (thanks zcodes) + - Invalidate cached pixmaps on resize/move (issue #576) + - Battery: do not show negative durations when the sensors return garbage + - Proper workaround for issue #555 + 2016-04-02 0.12.9 - Fixes: - Regression: Do not detect empty areas as clickable (issue #572) diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 52a60b5..0e37dde 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -33,6 +33,7 @@ #include "systraybar.h" #include "server.h" #include "panel.h" +#include "window.h" GSList *icons; @@ -534,15 +535,7 @@ gboolean add_icon(Window win) XSelectInput(server.display, win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); - XTextProperty xname; - char *name; - if (XGetWMName(server.display, win, &xname)) { - name = strdup((char *)xname.value); - XFree(xname.value); - } else { - name = strdup(""); - } - + char *name = get_window_name(win); if (systray_profile) fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, win, name); Panel *panel = systray.area.panel; @@ -1068,15 +1061,7 @@ void systray_property_notify(TrayWindow *traywin, XEvent *e) Atom at = e->xproperty.atom; if (at == server.atom.WM_NAME) { free(traywin->name); - - XTextProperty xname; - if (XGetWMName(server.display, traywin->win, &xname)) { - traywin->name = strdup((char *)xname.value); - XFree(xname.value); - } else { - traywin->name = strdup(""); - } - + traywin->name = get_window_name(traywin->win); if (systray.sort == SYSTRAY_SORT_ASCENDING || systray.sort == SYSTRAY_SORT_DESCENDING) { systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows); // print_icons(); diff --git a/src/util/window.c b/src/util/window.c index e3c1176..176b7c8 100644 --- a/src/util/window.c +++ b/src/util/window.c @@ -320,3 +320,32 @@ gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, i *ih = height[icon_num]; return icon_data[icon_num]; } + +// Thanks zcodes! +char *get_window_name(Window win) +{ + XTextProperty text_property; + Status status = XGetWMName(server.display, win, &text_property); + if (!status || !text_property.value || !text_property.nitems) { + return strdup(""); + } + + char **name_list; + int count; + status = Xutf8TextPropertyToTextList(server.display, &text_property, &name_list, &count); + if (status < Success || !count) { + XFree(text_property.value); + return strdup(""); + } + + if (!name_list[0]) { + XFreeStringList(name_list); + XFree(text_property.value); + return strdup(""); + } + + char *result = strdup(name_list[0]); + XFreeStringList(name_list); + XFree(text_property.value); + return result; +} diff --git a/src/util/window.h b/src/util/window.h index 88cd3c8..8df2e77 100644 --- a/src/util/window.h +++ b/src/util/window.h @@ -33,4 +33,6 @@ void change_window_desktop(Window win, int desktop); int get_icon_count(gulong *data, int num); gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size); +char *get_window_name(Window win); + #endif