aboutsummaryrefslogtreecommitdiffstats
path: root/group.c
diff options
context:
space:
mode:
authorokan2014-08-24 15:37:45 +0000
committerokan2014-08-24 15:37:45 +0000
commit9beba1401a7ba0614ef2f779392ff8fd3ed54a52 (patch)
treef7ca64c5d4aec3c39c89a16aa83559c443f8a245 /group.c
parent6ccf70f82d9136844ae8f2bb68b43aa31fd09d25 (diff)
downloadcwm-9beba1401a7ba0614ef2f779392ff8fd3ed54a52.tar.gz
gc->hidden has never consistently kept track of a group's state;
group_show() and group_hide() are not the only ways a group can change state - if all clients in a group are either hidden or unhidden, then that group's state should change, as well as the various EWMH ways. Instead of trying to keep track in a wide variety of places, simply query the clients in a group before needing to take action based on the group's state. Solves long standing confusion of when a group is hidden or not.
Diffstat (limited to 'group.c')
-rw-r--r--group.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/group.c b/group.c
index 36a2bb4..e341c8c 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.93 2014/08/22 19:04:00 okan Exp $
+ * $OpenBSD: group.c,v 1.94 2014/08/24 15:37:45 okan Exp $
*/
#include <sys/param.h>
@@ -36,7 +36,7 @@ static void group_assign(struct group_ctx *, struct client_ctx *);
static void group_hide(struct screen_ctx *, struct group_ctx *);
static void group_show(struct screen_ctx *, struct group_ctx *);
static void group_restack(struct screen_ctx *, struct group_ctx *);
-static void group_set_hidden_state(struct group_ctx *);
+static int group_hidden_state(struct group_ctx *);
static void group_setactive(struct screen_ctx *, long);
static void group_set_names(struct screen_ctx *);
@@ -68,8 +68,6 @@ group_hide(struct screen_ctx *sc, struct group_ctx *gc)
TAILQ_FOREACH(cc, &gc->clients, group_entry)
client_hide(cc);
-
- gc->hidden = 1;
}
static void
@@ -80,8 +78,6 @@ group_show(struct screen_ctx *sc, struct group_ctx *gc)
TAILQ_FOREACH(cc, &gc->clients, group_entry)
client_unhide(cc);
- gc->hidden = 0;
-
group_restack(sc, gc);
group_setactive(sc, gc->num);
}
@@ -136,7 +132,6 @@ group_init(struct screen_ctx *sc)
for (i = 0; i < CALMWM_NGROUPS; i++) {
TAILQ_INIT(&sc->groups[i].clients);
- sc->groups[i].hidden = 0;
sc->groups[i].num = i;
TAILQ_INSERT_TAIL(&sc->groupq, &sc->groups[i], entry);
}
@@ -149,15 +144,6 @@ group_init(struct screen_ctx *sc)
group_setactive(sc, 1);
}
-void
-group_set_state(struct screen_ctx *sc)
-{
- struct group_ctx *gc;
-
- TAILQ_FOREACH(gc, &sc->groupq, entry)
- group_set_hidden_state(gc);
-}
-
static void
group_setactive(struct screen_ctx *sc, long idx)
{
@@ -176,9 +162,10 @@ group_movetogroup(struct client_ctx *cc, int idx)
errx(1, "group_movetogroup: index out of range (%d)", idx);
gc = &sc->groups[idx];
+
if (cc->group == gc)
return;
- if (gc->hidden)
+ if (group_hidden_state(gc))
client_hide(cc);
group_assign(gc, cc);
}
@@ -211,21 +198,23 @@ group_sticky_toggle_exit(struct client_ctx *cc)
}
/*
- * If all clients in a group are hidden, then set the group state as hidden.
+ * If all clients in a group are hidden, then the group state is hidden.
*/
-static void
-group_set_hidden_state(struct group_ctx *gc)
+static int
+group_hidden_state(struct group_ctx *gc)
{
struct client_ctx *cc;
- int same = 0;
+ int hidden = 0, same = 0;
TAILQ_FOREACH(cc, &gc->clients, group_entry) {
- if (gc->hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0))
+ if (hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0))
same++;
}
if (same == 0)
- gc->hidden = !gc->hidden;
+ hidden = !hidden;
+
+ return(hidden);
}
void
@@ -237,9 +226,8 @@ group_hidetoggle(struct screen_ctx *sc, int idx)
errx(1, "group_hidetoggle: index out of range (%d)", idx);
gc = &sc->groups[idx];
- group_set_hidden_state(gc);
- if (gc->hidden)
+ if (group_hidden_state(gc))
group_show(sc, gc);
else {
group_hide(sc, gc);
@@ -287,7 +275,7 @@ group_cycle(struct screen_ctx *sc, int flags)
if (!TAILQ_EMPTY(&gc->clients) && showgroup == NULL)
showgroup = gc;
- else if (!gc->hidden)
+ else if (!group_hidden_state(gc))
group_hide(sc, gc);
}
@@ -296,7 +284,7 @@ group_cycle(struct screen_ctx *sc, int flags)
group_hide(sc, sc->group_active);
- if (showgroup->hidden)
+ if (group_hidden_state(showgroup))
group_show(sc, showgroup);
else
group_setactive(sc, showgroup->num);
@@ -314,8 +302,8 @@ group_menu(struct screen_ctx *sc)
TAILQ_FOREACH(gc, &sc->groupq, entry) {
if (TAILQ_EMPTY(&gc->clients))
continue;
-
- menuq_add(&menuq, gc, gc->hidden ? "%d: [%s]" : "%d: %s",
+ menuq_add(&menuq, gc,
+ group_hidden_state(gc) ? "%d: [%s]" : "%d: %s",
gc->num, sc->group_names[gc->num]);
}
@@ -325,7 +313,8 @@ group_menu(struct screen_ctx *sc)
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
if (mi != NULL && mi->ctx != NULL) {
gc = (struct group_ctx *)mi->ctx;
- (gc->hidden) ? group_show(sc, gc) : group_hide(sc, gc);
+ (group_hidden_state(gc)) ?
+ group_show(sc, gc) : group_hide(sc, gc);
}
menuq_clear(&menuq);