aboutsummaryrefslogtreecommitdiffstats
path: root/xutil.c
diff options
context:
space:
mode:
authorokan2014-09-06 16:08:58 +0000
committerokan2014-09-06 16:08:58 +0000
commite829ebdfb7b6c439829f9be1473e94d9e0724294 (patch)
tree18ab6acfa2ee70ed2b0bd67c13f31b1e2f2c4d54 /xutil.c
parentf8d684d6fbeb9cd2b4af04ce87ac3b5b9b8f9da8 (diff)
downloadcwm-e829ebdfb7b6c439829f9be1473e94d9e0724294.tar.gz
Rework group names: stash the group name inside the group_ctx as opposed
to having to manage an array outside in screen_ctx for group names and shortcuts. Simplifies (and moves bits for) reading, and constructing data for, EWMH's _NET_DESKTOP_NAMES.
Diffstat (limited to '')
-rw-r--r--xutil.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/xutil.c b/xutil.c
index 525c231..b19c0f5 100644
--- a/xutil.c
+++ b/xutil.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: xutil.c,v 1.89 2014/08/25 14:31:22 okan Exp $
+ * $OpenBSD: xutil.c,v 1.90 2014/09/06 16:08:58 okan Exp $
*/
#include <sys/param.h>
@@ -283,18 +283,46 @@ xu_ewmh_net_current_desktop(struct screen_ctx *sc, long idx)
void
xu_ewmh_net_desktop_names(struct screen_ctx *sc)
{
- char *p, *q;
- size_t len = 0, tlen, slen;
- int i;
+ struct group_ctx *gc;
+ char *p, *q;
+ unsigned char *prop_ret;
+ int i = 0, j = 0, nstrings = 0, n = 0;
+ size_t len = 0, tlen, slen;
+
+ /* Let group names be overwritten if _NET_DESKTOP_NAMES is set. */
+
+ if ((j = xu_getprop(sc->rootwin, ewmh[_NET_DESKTOP_NAMES],
+ cwmh[UTF8_STRING], 0xffffff, (unsigned char **)&prop_ret)) > 0) {
+ prop_ret[j - 1] = '\0'; /* paranoia */
+ while (i < j) {
+ if (prop_ret[i++] == '\0')
+ nstrings++;
+ }
+ }
+
+ p = (char *)prop_ret;
+ while (n < nstrings) {
+ TAILQ_FOREACH(gc, &sc->groupq, entry) {
+ if (gc->num == n) {
+ free(gc->name);
+ gc->name = xstrdup(p);
+ p += strlen(p) + 1;
+ break;
+ }
+ }
+ n++;
+ }
+ if (prop_ret != NULL)
+ XFree(prop_ret);
- for (i = 0; i < sc->group_nonames; i++)
- len += strlen(sc->group_names[i]) + 1;
+ TAILQ_FOREACH(gc, &sc->groupq, entry)
+ len += strlen(gc->name) + 1;
q = p = xcalloc(len, sizeof(*p));
tlen = len;
- for (i = 0; i < sc->group_nonames; i++) {
- slen = strlen(sc->group_names[i]) + 1;
- (void)strlcpy(q, sc->group_names[i], tlen);
+ TAILQ_FOREACH(gc, &sc->groupq, entry) {
+ slen = strlen(gc->name) + 1;
+ (void)strlcpy(q, gc->name, tlen);
tlen -= slen;
q += slen;
}