From e829ebdfb7b6c439829f9be1473e94d9e0724294 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 6 Sep 2014 16:08:58 +0000 Subject: 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. --- calmwm.h | 5 ++--- group.c | 56 +++----------------------------------------------------- mousefunc.c | 4 ++-- xevents.c | 4 ++-- xutil.c | 46 +++++++++++++++++++++++++++++++++++++--------- 5 files changed, 46 insertions(+), 69 deletions(-) diff --git a/calmwm.h b/calmwm.h index ae73818..d99865a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -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: calmwm.h,v 1.266 2014/09/01 18:04:58 okan Exp $ + * $OpenBSD: calmwm.h,v 1.267 2014/09/06 16:08:58 okan Exp $ */ #ifndef _CALMWM_H_ @@ -204,6 +204,7 @@ TAILQ_HEAD(cycle_entry_q, client_ctx); struct group_ctx { TAILQ_ENTRY(group_ctx) entry; struct client_ctx_q clients; + char *name; int num; }; TAILQ_HEAD(group_ctx_q, group_ctx); @@ -242,9 +243,7 @@ struct screen_ctx { struct group_ctx groups[CALMWM_NGROUPS]; struct group_ctx_q groupq; int group_hideall; - int group_nonames; struct group_ctx *group_active; - char **group_names; }; TAILQ_HEAD(screen_ctx_q, screen_ctx); diff --git a/group.c b/group.c index 5282f18..6377d79 100644 --- a/group.c +++ b/group.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: group.c,v 1.97 2014/09/01 18:04:58 okan Exp $ + * $OpenBSD: group.c,v 1.98 2014/09/06 16:08:58 okan Exp $ */ #include @@ -120,18 +120,15 @@ group_init(struct screen_ctx *sc) TAILQ_INIT(&sc->groupq); sc->group_hideall = 0; - /* - * See if any group names have already been set and update the - * property with ours if they'll have changed. - */ - group_update_names(sc); for (i = 0; i < CALMWM_NGROUPS; i++) { TAILQ_INIT(&sc->groups[i].clients); + sc->groups[i].name = xstrdup(num_to_name[i]); sc->groups[i].num = i; TAILQ_INSERT_TAIL(&sc->groupq, &sc->groups[i], entry); } + xu_ewmh_net_desktop_names(sc); xu_ewmh_net_wm_desktop_viewport(sc); xu_ewmh_net_wm_number_of_desktops(sc); xu_ewmh_net_showing_desktop(sc); @@ -350,50 +347,3 @@ group_autogroup(struct client_ctx *cc) else group_assign(NULL, cc); } - -void -group_update_names(struct screen_ctx *sc) -{ - char **strings, *p; - unsigned char *prop_ret; - int i = 0, j = 0, nstrings = 0, n = 0, setnames = 0; - - 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++; - } - } - - strings = xcalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS : - nstrings), sizeof(*strings)); - - p = (char *)prop_ret; - while (n < nstrings) { - strings[n++] = xstrdup(p); - p += strlen(p) + 1; - } - /* - * make sure we always set our defaults if nothing is there to - * replace them. - */ - if (n < CALMWM_NGROUPS) { - setnames = 1; - i = 0; - while (n < CALMWM_NGROUPS) - strings[n++] = xstrdup(num_to_name[i++]); - } - - if (prop_ret != NULL) - XFree(prop_ret); - if (sc->group_nonames != 0) - free(sc->group_names); - - sc->group_names = strings; - sc->group_nonames = n; - - if (setnames) - xu_ewmh_net_desktop_names(sc); -} diff --git a/mousefunc.c b/mousefunc.c index 2cd9d6e..8e27461 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: mousefunc.c,v 1.76 2014/09/02 14:08:39 okan Exp $ + * $OpenBSD: mousefunc.c,v 1.77 2014/09/06 16:08:58 okan Exp $ */ #include @@ -192,7 +192,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) continue; menuq_add(&menuq, gc, group_hidden_state(gc) ? "%d: [%s]" : "%d: %s", - gc->num, sc->group_names[gc->num]); + gc->num, gc->name); } if (TAILQ_EMPTY(&menuq)) return; diff --git a/xevents.c b/xevents.c index c9c48d1..8968f83 100644 --- a/xevents.c +++ b/xevents.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: xevents.c,v 1.111 2014/02/03 20:20:39 okan Exp $ + * $OpenBSD: xevents.c,v 1.112 2014/09/06 16:08:58 okan Exp $ */ /* @@ -196,7 +196,7 @@ xev_handle_propertynotify(XEvent *ee) TAILQ_FOREACH(sc, &Screenq, entry) { if (sc->rootwin == e->window) { if (e->atom == ewmh[_NET_DESKTOP_NAMES]) - group_update_names(sc); + xu_ewmh_net_desktop_names(sc); } } } 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 @@ -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; } -- cgit v1.2.3-2-gb3c3