From 78e0f2122580291206b5c9c3d07db9663f409c0b Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 7 Sep 2014 17:27:20 +0000 Subject: Get rid of a redundant array of groups per screen; we already have a link to the group queue for each screen. --- group.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'group.c') diff --git a/group.c b/group.c index d1ae4f4..dcea84f 100644 --- a/group.c +++ b/group.c @@ -116,16 +116,18 @@ group_restack(struct screen_ctx *sc, struct group_ctx *gc) void group_init(struct screen_ctx *sc) { - int i; + struct group_ctx *gc; + int i; TAILQ_INIT(&sc->groupq); sc->group_hideall = 0; 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); + gc = xcalloc(1, sizeof(*gc)); + TAILQ_INIT(&gc->clients); + gc->name = xstrdup(num_to_name[i]); + gc->num = i; + TAILQ_INSERT_TAIL(&sc->groupq, gc, entry); } xu_ewmh_net_desktop_names(sc); @@ -140,7 +142,13 @@ group_init(struct screen_ctx *sc) static void group_setactive(struct screen_ctx *sc, long idx) { - sc->group_active = &sc->groups[idx]; + struct group_ctx *gc; + + TAILQ_FOREACH(gc, &sc->groupq, entry) { + if (gc->num == idx) + break; + } + sc->group_active = gc; xu_ewmh_net_current_desktop(sc, idx); } @@ -154,7 +162,10 @@ group_movetogroup(struct client_ctx *cc, int idx) if (idx < 0 || idx >= CALMWM_NGROUPS) errx(1, "group_movetogroup: index out of range (%d)", idx); - gc = &sc->groups[idx]; + TAILQ_FOREACH(gc, &sc->groupq, entry) { + if (gc->num == idx) + break; + } if (cc->group == gc) return; @@ -220,7 +231,10 @@ group_hidetoggle(struct screen_ctx *sc, int idx) if (idx < 0 || idx >= CALMWM_NGROUPS) errx(1, "group_hidetoggle: index out of range (%d)", idx); - gc = &sc->groups[idx]; + TAILQ_FOREACH(gc, &sc->groupq, entry) { + if (gc->num == idx) + break; + } if (group_hidden_state(gc)) group_show(sc, gc); -- cgit 1.4.1 From 5b46f0f7d8c6bb97f6eef28ee21d762fb65e9c88 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 7 Sep 2014 20:57:26 +0000 Subject: Add screen_ctx to group_ctx, and populate on init. --- calmwm.h | 1 + group.c | 1 + 2 files changed, 2 insertions(+) (limited to 'group.c') diff --git a/calmwm.h b/calmwm.h index 31f9165..6ab92e0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -203,6 +203,7 @@ TAILQ_HEAD(cycle_entry_q, client_ctx); struct group_ctx { TAILQ_ENTRY(group_ctx) entry; + struct screen_ctx *sc; struct client_ctx_q clients; char *name; int num; diff --git a/group.c b/group.c index dcea84f..aad482d 100644 --- a/group.c +++ b/group.c @@ -124,6 +124,7 @@ group_init(struct screen_ctx *sc) for (i = 0; i < CALMWM_NGROUPS; i++) { gc = xcalloc(1, sizeof(*gc)); + gc->sc = sc; TAILQ_INIT(&gc->clients); gc->name = xstrdup(num_to_name[i]); gc->num = i; -- cgit 1.4.1 From a7f3f29ea91dc06ad326d22a161f046aab03697e Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Sep 2014 13:51:29 +0000 Subject: Now that a group knows its screen, only pass down the group_ctx. --- calmwm.h | 4 ++-- group.c | 32 ++++++++++++++++---------------- mousefunc.c | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'group.c') diff --git a/calmwm.h b/calmwm.h index 6ab92e0..f4a79db 100644 --- a/calmwm.h +++ b/calmwm.h @@ -408,12 +408,12 @@ void group_alltoggle(struct screen_ctx *); void group_autogroup(struct client_ctx *); void group_cycle(struct screen_ctx *, int); int group_hidden_state(struct group_ctx *); -void group_hide(struct screen_ctx *, struct group_ctx *); +void group_hide(struct group_ctx *); void group_hidetoggle(struct screen_ctx *, int); void group_init(struct screen_ctx *); void group_movetogroup(struct client_ctx *, int); void group_only(struct screen_ctx *, int); -void group_show(struct screen_ctx *, struct group_ctx *); +void group_show(struct group_ctx *); void group_sticky(struct client_ctx *); void group_sticky_toggle_enter(struct client_ctx *); void group_sticky_toggle_exit(struct client_ctx *); diff --git a/group.c b/group.c index aad482d..9f1ad62 100644 --- a/group.c +++ b/group.c @@ -33,7 +33,7 @@ #include "calmwm.h" static void group_assign(struct group_ctx *, struct client_ctx *); -static void group_restack(struct screen_ctx *, struct group_ctx *); +static void group_restack(struct group_ctx *); static void group_setactive(struct screen_ctx *, long); const char *num_to_name[] = { @@ -56,30 +56,30 @@ group_assign(struct group_ctx *gc, struct client_ctx *cc) } void -group_hide(struct screen_ctx *sc, struct group_ctx *gc) +group_hide(struct group_ctx *gc) { struct client_ctx *cc; - screen_updatestackingorder(sc); + screen_updatestackingorder(gc->sc); TAILQ_FOREACH(cc, &gc->clients, group_entry) client_hide(cc); } void -group_show(struct screen_ctx *sc, struct group_ctx *gc) +group_show(struct group_ctx *gc) { struct client_ctx *cc; TAILQ_FOREACH(cc, &gc->clients, group_entry) client_unhide(cc); - group_restack(sc, gc); - group_setactive(sc, gc->num); + group_restack(gc); + group_setactive(gc->sc, gc->num); } static void -group_restack(struct screen_ctx *sc, struct group_ctx *gc) +group_restack(struct group_ctx *gc) { struct client_ctx *cc; Window *winlist; @@ -238,9 +238,9 @@ group_hidetoggle(struct screen_ctx *sc, int idx) } if (group_hidden_state(gc)) - group_show(sc, gc); + group_show(gc); else { - group_hide(sc, gc); + group_hide(gc); /* make clients stick to empty group */ if (TAILQ_EMPTY(&gc->clients)) group_setactive(sc, idx); @@ -257,9 +257,9 @@ group_only(struct screen_ctx *sc, int idx) TAILQ_FOREACH(gc, &sc->groupq, entry) { if (gc->num == idx) - group_show(sc, gc); + group_show(gc); else - group_hide(sc, gc); + group_hide(gc); } } @@ -286,16 +286,16 @@ group_cycle(struct screen_ctx *sc, int flags) if (!TAILQ_EMPTY(&gc->clients) && showgroup == NULL) showgroup = gc; else if (!group_hidden_state(gc)) - group_hide(sc, gc); + group_hide(gc); } if (showgroup == NULL) return; - group_hide(sc, sc->group_active); + group_hide(sc->group_active); if (group_hidden_state(showgroup)) - group_show(sc, showgroup); + group_show(showgroup); else group_setactive(sc, showgroup->num); } @@ -307,9 +307,9 @@ group_alltoggle(struct screen_ctx *sc) TAILQ_FOREACH(gc, &sc->groupq, entry) { if (sc->group_hideall) - group_show(sc, gc); + group_show(gc); else - group_hide(sc, gc); + group_hide(gc); } sc->group_hideall = !sc->group_hideall; } diff --git a/mousefunc.c b/mousefunc.c index 2499ae1..421b743 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -201,7 +201,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) NULL, NULL)) != NULL) { gc = (struct group_ctx *)mi->ctx; (group_hidden_state(gc)) ? - group_show(sc, gc) : group_hide(sc, gc); + group_show(gc) : group_hide(gc); } menuq_clear(&menuq); -- cgit 1.4.1 From aac16013d21fd14ac9e570ffee91a591987c50d1 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Sep 2014 21:15:14 +0000 Subject: name the group client queue appropriately, like other queues --- calmwm.h | 2 +- client.c | 10 +++++----- group.c | 20 ++++++++++---------- mousefunc.c | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'group.c') diff --git a/calmwm.h b/calmwm.h index 243be98..252ba3d 100644 --- a/calmwm.h +++ b/calmwm.h @@ -202,7 +202,7 @@ TAILQ_HEAD(client_ctx_q, client_ctx); struct group_ctx { TAILQ_ENTRY(group_ctx) entry; struct screen_ctx *sc; - struct client_ctx_q clients; + struct client_ctx_q clientq; char *name; int num; }; diff --git a/client.c b/client.c index 2a6a83e..0b10053 100644 --- a/client.c +++ b/client.c @@ -154,7 +154,7 @@ client_delete(struct client_ctx *cc) xu_ewmh_net_client_list(sc); if (cc->group != NULL) - TAILQ_REMOVE(&cc->group->clients, cc, group_entry); + TAILQ_REMOVE(&cc->group->clientq, cc, group_entry); if (cc == client_current()) client_none(sc); @@ -943,7 +943,7 @@ client_htile(struct client_ctx *cc) return; i = n = 0; - TAILQ_FOREACH(ci, &gc->clients, group_entry) { + TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; @@ -971,7 +971,7 @@ client_htile(struct client_ctx *cc) x = xine.x; w = xine.w / n; h = xine.h - mh; - TAILQ_FOREACH(ci, &gc->clients, group_entry) { + TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; @@ -1002,7 +1002,7 @@ client_vtile(struct client_ctx *cc) return; i = n = 0; - TAILQ_FOREACH(ci, &gc->clients, group_entry) { + TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; @@ -1030,7 +1030,7 @@ client_vtile(struct client_ctx *cc) y = xine.y; h = xine.h / n; w = xine.w - mw; - TAILQ_FOREACH(ci, &gc->clients, group_entry) { + TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; diff --git a/group.c b/group.c index 9f1ad62..bc8c300 100644 --- a/group.c +++ b/group.c @@ -45,12 +45,12 @@ static void group_assign(struct group_ctx *gc, struct client_ctx *cc) { if (cc->group != NULL) - TAILQ_REMOVE(&cc->group->clients, cc, group_entry); + TAILQ_REMOVE(&cc->group->clientq, cc, group_entry); cc->group = gc; if (cc->group != NULL) - TAILQ_INSERT_TAIL(&gc->clients, cc, group_entry); + TAILQ_INSERT_TAIL(&gc->clientq, cc, group_entry); xu_ewmh_net_wm_desktop(cc); } @@ -62,7 +62,7 @@ group_hide(struct group_ctx *gc) screen_updatestackingorder(gc->sc); - TAILQ_FOREACH(cc, &gc->clients, group_entry) + TAILQ_FOREACH(cc, &gc->clientq, group_entry) client_hide(cc); } @@ -71,7 +71,7 @@ group_show(struct group_ctx *gc) { struct client_ctx *cc; - TAILQ_FOREACH(cc, &gc->clients, group_entry) + TAILQ_FOREACH(cc, &gc->clientq, group_entry) client_unhide(cc); group_restack(gc); @@ -86,14 +86,14 @@ group_restack(struct group_ctx *gc) int i, lastempty = -1; int nwins = 0, highstack = 0; - TAILQ_FOREACH(cc, &gc->clients, group_entry) { + TAILQ_FOREACH(cc, &gc->clientq, group_entry) { if (cc->stackingorder > highstack) highstack = cc->stackingorder; } winlist = xcalloc((highstack + 1), sizeof(*winlist)); /* Invert the stacking order for XRestackWindows(). */ - TAILQ_FOREACH(cc, &gc->clients, group_entry) { + TAILQ_FOREACH(cc, &gc->clientq, group_entry) { winlist[highstack - cc->stackingorder] = cc->win; nwins++; } @@ -125,7 +125,7 @@ group_init(struct screen_ctx *sc) for (i = 0; i < CALMWM_NGROUPS; i++) { gc = xcalloc(1, sizeof(*gc)); gc->sc = sc; - TAILQ_INIT(&gc->clients); + TAILQ_INIT(&gc->clientq); gc->name = xstrdup(num_to_name[i]); gc->num = i; TAILQ_INSERT_TAIL(&sc->groupq, gc, entry); @@ -211,7 +211,7 @@ group_hidden_state(struct group_ctx *gc) struct client_ctx *cc; int hidden = 0, same = 0; - TAILQ_FOREACH(cc, &gc->clients, group_entry) { + TAILQ_FOREACH(cc, &gc->clientq, group_entry) { if (cc->flags & CLIENT_STICKY) continue; if (hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0)) @@ -242,7 +242,7 @@ group_hidetoggle(struct screen_ctx *sc, int idx) else { group_hide(gc); /* make clients stick to empty group */ - if (TAILQ_EMPTY(&gc->clients)) + if (TAILQ_EMPTY(&gc->clientq)) group_setactive(sc, idx); } } @@ -283,7 +283,7 @@ group_cycle(struct screen_ctx *sc, int flags) if (gc == sc->group_active) break; - if (!TAILQ_EMPTY(&gc->clients) && showgroup == NULL) + if (!TAILQ_EMPTY(&gc->clientq) && showgroup == NULL) showgroup = gc; else if (!group_hidden_state(gc)) group_hide(gc); diff --git a/mousefunc.c b/mousefunc.c index b46fcfc..2d3909e 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -188,7 +188,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) TAILQ_INIT(&menuq); TAILQ_FOREACH(gc, &sc->groupq, entry) { - if (TAILQ_EMPTY(&gc->clients)) + if (TAILQ_EMPTY(&gc->clientq)) continue; menuq_add(&menuq, gc, group_hidden_state(gc) ? "%d: [%s]" : "%d: %s", -- cgit 1.4.1 From 74f4a1bad98bdb25212b32d15fa411d2ed16b6df Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 17 Sep 2014 14:31:37 +0000 Subject: Introduce a check to see if a group holds only 'sticky' clients and use this check to decide if a group is virtually empty. Rationale: if a group contains *only* 'sticky' clients, it should be skipped while cycling through groups. Apply similar logic to the group menu. Based on an idea from phessler@, who also tested another version. --- calmwm.h | 2 +- group.c | 15 ++++++++++++++- mousefunc.c | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'group.c') diff --git a/calmwm.h b/calmwm.h index eda8904..23879c5 100644 --- a/calmwm.h +++ b/calmwm.h @@ -407,11 +407,11 @@ void group_cycle(struct screen_ctx *, int); int group_hidden_state(struct group_ctx *); void group_hide(struct group_ctx *); void group_hidetoggle(struct screen_ctx *, int); +int group_holds_only_sticky(struct group_ctx *); void group_init(struct screen_ctx *); void group_movetogroup(struct client_ctx *, int); void group_only(struct screen_ctx *, int); void group_show(struct group_ctx *); -void group_sticky(struct client_ctx *); void group_sticky_toggle_enter(struct client_ctx *); void group_sticky_toggle_exit(struct client_ctx *); void group_update_names(struct screen_ctx *); diff --git a/group.c b/group.c index bc8c300..8976f86 100644 --- a/group.c +++ b/group.c @@ -202,6 +202,19 @@ group_sticky_toggle_exit(struct client_ctx *cc) client_draw_border(cc); } +int +group_holds_only_sticky(struct group_ctx *gc) +{ + struct client_ctx *cc; + + /* Check if all clients in the group are 'sticky'. */ + TAILQ_FOREACH(cc, &gc->clientq, group_entry) { + if (!(cc->flags & CLIENT_STICKY)) + return(0); + } + return(1); +} + /* * If all clients in a group are hidden, then the group state is hidden. */ @@ -283,7 +296,7 @@ group_cycle(struct screen_ctx *sc, int flags) if (gc == sc->group_active) break; - if (!TAILQ_EMPTY(&gc->clientq) && showgroup == NULL) + if (!group_holds_only_sticky(gc) && showgroup == NULL) showgroup = gc; else if (!group_hidden_state(gc)) group_hide(gc); diff --git a/mousefunc.c b/mousefunc.c index 2d3909e..6b35029 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -188,7 +188,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) TAILQ_INIT(&menuq); TAILQ_FOREACH(gc, &sc->groupq, entry) { - if (TAILQ_EMPTY(&gc->clientq)) + if (group_holds_only_sticky(gc)) continue; menuq_add(&menuq, gc, group_hidden_state(gc) ? "%d: [%s]" : "%d: %s", -- cgit 1.4.1 From 736d973f4668d0c2db37b54c3ecfd41aa6e5ca39 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 17 Sep 2014 16:32:53 +0000 Subject: Use a similarly named check as sticky for hidden check in a group. --- calmwm.h | 2 +- group.c | 14 +++++--------- mousefunc.c | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'group.c') diff --git a/calmwm.h b/calmwm.h index 639e3ca..616839b 100644 --- a/calmwm.h +++ b/calmwm.h @@ -406,9 +406,9 @@ void client_wm_hints(struct client_ctx *); void group_alltoggle(struct screen_ctx *); void group_autogroup(struct client_ctx *); void group_cycle(struct screen_ctx *, int); -int group_hidden_state(struct group_ctx *); void group_hide(struct group_ctx *); void group_hidetoggle(struct screen_ctx *, int); +int group_holds_only_hidden(struct group_ctx *); int group_holds_only_sticky(struct group_ctx *); void group_init(struct screen_ctx *); void group_movetogroup(struct client_ctx *, int); diff --git a/group.c b/group.c index 8976f86..ce5a504 100644 --- a/group.c +++ b/group.c @@ -170,7 +170,7 @@ group_movetogroup(struct client_ctx *cc, int idx) if (cc->group == gc) return; - if (group_hidden_state(gc)) + if (group_holds_only_hidden(gc)) client_hide(cc); group_assign(gc, cc); } @@ -207,7 +207,6 @@ group_holds_only_sticky(struct group_ctx *gc) { struct client_ctx *cc; - /* Check if all clients in the group are 'sticky'. */ TAILQ_FOREACH(cc, &gc->clientq, group_entry) { if (!(cc->flags & CLIENT_STICKY)) return(0); @@ -215,11 +214,8 @@ group_holds_only_sticky(struct group_ctx *gc) return(1); } -/* - * If all clients in a group are hidden, then the group state is hidden. - */ int -group_hidden_state(struct group_ctx *gc) +group_holds_only_hidden(struct group_ctx *gc) { struct client_ctx *cc; int hidden = 0, same = 0; @@ -250,7 +246,7 @@ group_hidetoggle(struct screen_ctx *sc, int idx) break; } - if (group_hidden_state(gc)) + if (group_holds_only_hidden(gc)) group_show(gc); else { group_hide(gc); @@ -298,7 +294,7 @@ group_cycle(struct screen_ctx *sc, int flags) if (!group_holds_only_sticky(gc) && showgroup == NULL) showgroup = gc; - else if (!group_hidden_state(gc)) + else if (!group_holds_only_hidden(gc)) group_hide(gc); } @@ -307,7 +303,7 @@ group_cycle(struct screen_ctx *sc, int flags) group_hide(sc->group_active); - if (group_hidden_state(showgroup)) + if (group_holds_only_hidden(showgroup)) group_show(showgroup); else group_setactive(sc, showgroup->num); diff --git a/mousefunc.c b/mousefunc.c index 6b35029..8784039 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -191,7 +191,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) if (group_holds_only_sticky(gc)) continue; menuq_add(&menuq, gc, - group_hidden_state(gc) ? "%d: [%s]" : "%d: %s", + group_holds_only_hidden(gc) ? "%d: [%s]" : "%d: %s", gc->num, gc->name); } if (TAILQ_EMPTY(&menuq)) @@ -200,7 +200,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) if ((mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL)) != NULL) { gc = (struct group_ctx *)mi->ctx; - (group_hidden_state(gc)) ? + (group_holds_only_hidden(gc)) ? group_show(gc) : group_hide(gc); } -- cgit 1.4.1