diff --git a/awesome.c b/awesome.c index 5d1b8d2eb..7297593e7 100644 --- a/awesome.c +++ b/awesome.c @@ -45,40 +45,7 @@ DC dc; /* static */ static int (*xerrorxlib) (Display *, XErrorEvent *); -static Bool readin = True; -static Bool running = True; - - -Bool -gettextprop(Display *disp, Window w, Atom atom, char *text, unsigned int size) -{ - char **list = NULL; - int n; - - XTextProperty name; - - if(!text || size == 0) - return False; - - text[0] = '\0'; - XGetTextProperty(disp, w, &name, atom); - - if(!name.nitems) - return False; - - if(name.encoding == XA_STRING) - strncpy(text, (char *) name.value, size - 1); - else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list) - { - strncpy(text, *list, size - 1); - XFreeStringList(list); - } - - text[size - 1] = '\0'; - XFree(name.value); - - return True; -} +static Bool readin = True, running = True; static void cleanup(Display *disp, awesome_config *awesomeconf) diff --git a/client.c b/client.c index 2cb294be8..ba83f8700 100644 --- a/client.c +++ b/client.c @@ -194,8 +194,8 @@ attach(Client * c) inline void updatetitle(Client * c) { - if(!gettextprop(c->display, c->win, XInternAtom(c->display, "_NET_WM_NAME", False), c->name, sizeof c->name)) - gettextprop(c->display, c->win, XInternAtom(c->display, "WM_NAME", False), c->name, sizeof c->name); + if(!xgettextprop(c->display, c->win, XInternAtom(c->display, "_NET_WM_NAME", False), c->name, sizeof c->name)) + xgettextprop(c->display, c->win, XInternAtom(c->display, "WM_NAME", False), c->name, sizeof c->name); } /** Ban client @@ -328,7 +328,7 @@ loadprops(Client * c, int ntags) prop = p_new(char, ntags + 2); - if(gettextprop(c->display, c->win, AWESOMEPROPS_ATOM(c->display), prop, ntags + 2)) + if(xgettextprop(c->display, c->win, AWESOMEPROPS_ATOM(c->display), prop, ntags + 2)) { for(i = 0; i < ntags && prop[i]; i++) if((c->tags[i] = prop[i] == '1')) diff --git a/layout.c b/layout.c index db5adaab7..bb8e7f407 100644 --- a/layout.c +++ b/layout.c @@ -96,7 +96,7 @@ loadawesomeprops(Display *disp, awesome_config * awesomeconf) prop = p_new(char, awesomeconf->ntags + 1); - if(gettextprop(disp, DefaultRootWindow(disp), AWESOMEPROPS_ATOM(disp), prop, awesomeconf->ntags + 1)) + if(xgettextprop(disp, DefaultRootWindow(disp), AWESOMEPROPS_ATOM(disp), prop, awesomeconf->ntags + 1)) for(i = 0; i < awesomeconf->ntags && prop[i]; i++) awesomeconf->selected_tags[i] = prop[i] == '1'; diff --git a/util.c b/util.c index d63b71af6..c385046f4 100644 --- a/util.c +++ b/util.c @@ -25,6 +25,9 @@ #include #include +#include +#include + #include "util.h" void @@ -66,3 +69,35 @@ spawn(Display * disp, } wait(0); } + +Bool +xgettextprop(Display *disp, Window w, Atom atom, char *text, unsigned int size) +{ + char **list = NULL; + int n; + + XTextProperty name; + + if(!text || size == 0) + return False; + + text[0] = '\0'; + XGetTextProperty(disp, w, &name, atom); + + if(!name.nitems) + return False; + + if(name.encoding == XA_STRING) + strncpy(text, (char *) name.value, size - 1); + + else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list) + { + strncpy(text, *list, size - 1); + XFreeStringList(list); + } + + text[size - 1] = '\0'; + XFree(name.value); + + return True; +} diff --git a/util.h b/util.h index 856512bdd..70843b445 100644 --- a/util.h +++ b/util.h @@ -83,9 +83,6 @@ xrealloc(void **ptr, ssize_t newsize) } } -void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); -void spawn(Display *, awesome_config *, const char *); - static inline void *xmemdup(const void *src, ssize_t size) { return memcpy(xmalloc(size), src, size); @@ -121,5 +118,8 @@ static inline char *a_strdup(const char *s) return len ? p_dup(s, len + 1) : NULL; } +void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); +void spawn(Display *, awesome_config *, const char *); +Bool xgettextprop(Display *, Window, Atom, char *, unsigned int); #endif