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@ --- xutil.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'xutil.c') 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 From 85a53083cbe06c33cdea95b6a9fcb953bcc3afa2 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 22 May 2010 22:32:08 +0000 Subject: initialize nitems ok oga@ --- xutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xutil.c') diff --git a/xutil.c b/xutil.c index 2308173..c57bea7 100644 --- a/xutil.c +++ b/xutil.c @@ -155,7 +155,7 @@ int xu_getstrprop(Window win, Atom atm, char **text) { XTextProperty prop; char **list; - int nitems; + int nitems = 0; *text = NULL; -- cgit 1.4.1