From 72e6d2d0a9e3f1ac1c2fc52e03648c625b07a49c Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 22 May 2010 22:10:31 +0000 Subject: replace XFetchName() with something more intelligent which attempts to use the appropriate netwm Atom first, as well as deal with utf8. slightly different incarnation tested by sthen@ and ajacoutot@ - thanks! ok oga@ --- calmwm.h | 2 +- client.c | 7 ++++--- xutil.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 173c7cb..abde06e 100644 --- a/calmwm.h +++ b/calmwm.h @@ -401,7 +401,7 @@ void xu_key_grab(Window, int, int); void xu_key_ungrab(Window, int, int); void xu_sendmsg(Window, Atom, long); int xu_getprop(Window, Atom, Atom, long, u_char **); -char *xu_getstrprop(struct client_ctx *, Atom atm); +int xu_getstrprop(Window, Atom, char **); void xu_setstate(struct client_ctx *, int); int xu_getstate(struct client_ctx *, int *); unsigned long xu_getcolor(struct screen_ctx *, char *); diff --git a/client.c b/client.c index d2c89c9..95d9d75 100644 --- a/client.c +++ b/client.c @@ -183,7 +183,7 @@ client_delete(struct client_ctx *cc) while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) { TAILQ_REMOVE(&cc->nameq, wn, entry); if (wn->name != emptystring) - XFree(wn->name); + xfree(wn->name); xfree(wn); } @@ -523,7 +523,8 @@ client_setname(struct client_ctx *cc) struct winname *wn; char *newname; - XFetchName(X_Dpy, cc->win, &newname); + if (!xu_getstrprop(cc->win, _NET_WM_NAME, &newname)) + xu_getstrprop(cc->win, XA_WM_NAME, &newname); if (newname == NULL) newname = emptystring; @@ -549,7 +550,7 @@ match: assert(wn != NULL); TAILQ_REMOVE(&cc->nameq, wn, entry); if (wn->name != emptystring) - XFree(wn->name); + xfree(wn->name); xfree(wn); cc->nameqlen--; } diff --git a/xutil.c b/xutil.c index cbe7562..2308173 100644 --- a/xutil.c +++ b/xutil.c @@ -151,6 +151,38 @@ xu_getprop(Window win, Atom atm, Atom type, long len, u_char **p) return (n); } +int +xu_getstrprop(Window win, Atom atm, char **text) { + XTextProperty prop; + char **list; + int nitems; + + *text = NULL; + + XGetTextProperty(X_Dpy, win, &prop, atm); + if (!prop.nitems) + return (0); + + if (Xutf8TextPropertyToTextList(X_Dpy, &prop, &list, + &nitems) == Success && nitems > 0 && *list) { + if (nitems > 1) { + XTextProperty prop2; + if (Xutf8TextListToTextProperty(X_Dpy, list, nitems, + XUTF8StringStyle, &prop2) == Success) { + *text = xstrdup(prop2.value); + XFree(prop2.value); + } + } else { + *text = xstrdup(*list); + } + XFreeStringList(list); + } + + XFree(prop.value); + + return (nitems); +} + int xu_getstate(struct client_ctx *cc, int *state) { -- cgit 1.4.1