Fixed crash in systray with non-Latin languagess (thanks zcodes)
o9000 mrovi9000@gmail.com
4 files changed,
41 insertions(+),
18 deletions(-)
M
ChangeLog
→
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)
M
src/systray/systraybar.c
→
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 @@ XErrorHandler old = XSetErrorHandler(window_error_handler);
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 @@ {
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();
M
src/util/window.c
→
src/util/window.c
@@ -320,3 +320,32 @@ *iw = width[icon_num];
*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; +}
M
src/util/window.h
→
src/util/window.h
@@ -33,4 +33,6 @@
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