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.
This commit is contained in:
okan 2014-08-24 15:37:45 +00:00
parent fe533fdc8e
commit 9f36d4af35
3 changed files with 18 additions and 32 deletions

View File

@ -204,7 +204,6 @@ struct group_ctx {
TAILQ_ENTRY(group_ctx) entry;
struct client_ctx_q clients;
int num;
int hidden;
};
TAILQ_HEAD(group_ctx_q, group_ctx);
@ -413,7 +412,6 @@ void group_init(struct screen_ctx *);
void group_menu(struct screen_ctx *);
void group_movetogroup(struct client_ctx *, int);
void group_only(struct screen_ctx *, int);
void group_set_state(struct screen_ctx *);
void group_sticky(struct client_ctx *);
void group_sticky_toggle_enter(struct client_ctx *);
void group_sticky_toggle_exit(struct client_ctx *);

47
group.c
View File

@ -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);

View File

@ -69,7 +69,6 @@ screen_init(int which)
XFree(wins);
}
screen_updatestackingorder(sc);
group_set_state(sc);
if (HasRandr)
XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask);