aboutsummaryrefslogtreecommitdiffstats
path: root/group.c
diff options
context:
space:
mode:
authorokan2015-08-25 18:29:10 +0000
committerokan2015-08-25 18:29:10 +0000
commit3ca9c4569b8898dcc407ed0020fc50bc6e459b3a (patch)
tree7f891ebfd7983a56fc0134b09bf6be4d36918d27 /group.c
parentf507af43cc37948b1f83ba74c8200059d4bba742 (diff)
downloadcwm-3ca9c4569b8898dcc407ed0020fc50bc6e459b3a.tar.gz
Split out sticky mode checks and the restoring of a client's group and
_NET_WM_DESKTOP from the config-based auto-grouping; no (intentional) behavior changes. Needed for further work in cleaning up this area.
Diffstat (limited to 'group.c')
-rw-r--r--group.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/group.c b/group.c
index 3532c8a..593a0d6 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.114 2015/08/23 17:31:20 okan Exp $
+ * $OpenBSD: group.c,v 1.115 2015/08/25 18:29:10 okan Exp $
*/
#include <sys/types.h>
@@ -34,7 +34,6 @@
static struct group_ctx *group_next(struct group_ctx *);
static struct group_ctx *group_prev(struct group_ctx *);
-static void group_assign(struct group_ctx *, struct client_ctx *);
static void group_restack(struct group_ctx *);
static void group_setactive(struct group_ctx *);
@@ -43,7 +42,7 @@ const char *num_to_name[] = {
"seven", "eight", "nine"
};
-static void
+void
group_assign(struct group_ctx *gc, struct client_ctx *cc)
{
if (cc->group != NULL)
@@ -324,51 +323,65 @@ group_alltoggle(struct screen_ctx *sc)
sc->hideall = !sc->hideall;
}
-void
-group_autogroup(struct client_ctx *cc)
+int
+group_restore(struct client_ctx *cc)
{
struct screen_ctx *sc = cc->sc;
- struct autogroupwin *aw;
struct group_ctx *gc;
- int num = -2, both_match = 0;
+ int num = -1;
long *grpnum;
- if (cc->ch.res_class == NULL || cc->ch.res_name == NULL)
- return;
+ if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP], XA_CARDINAL, 1L,
+ (unsigned char **)&grpnum) <= 0)
+ return(0);
- if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP],
- XA_CARDINAL, 1, (unsigned char **)&grpnum) > 0) {
- num = *grpnum;
- if (num > CALMWM_NGROUPS || num < -1)
- num = CALMWM_NGROUPS - 1;
- XFree(grpnum);
- } else {
- TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
- if (strcmp(aw->class, cc->ch.res_class) == 0) {
- if ((aw->name != NULL) &&
- (strcmp(aw->name, cc->ch.res_name) == 0)) {
- num = aw->num;
- both_match = 1;
- } else if (aw->name == NULL && !both_match)
- num = aw->num;
- }
- }
- }
+ num = MIN(*grpnum, (CALMWM_NGROUPS - 1));
+ XFree(grpnum);
if ((num == -1) || (num == 0)) {
group_assign(NULL, cc);
- return;
+ return(1);
}
-
TAILQ_FOREACH(gc, &sc->groupq, entry) {
if (gc->num == num) {
group_assign(gc, cc);
- return;
+ return(1);
}
}
+ return(0);
+}
- if (Conf.flags & CONF_STICKY_GROUPS)
- group_assign(sc->group_active, cc);
- else
+int
+group_autogroup(struct client_ctx *cc)
+{
+ struct screen_ctx *sc = cc->sc;
+ struct autogroupwin *aw;
+ struct group_ctx *gc;
+ int num = -1, both_match = 0;
+
+ if (cc->ch.res_class == NULL || cc->ch.res_name == NULL)
+ return(0);
+
+ TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
+ if (strcmp(aw->class, cc->ch.res_class) == 0) {
+ if ((aw->name != NULL) &&
+ (strcmp(aw->name, cc->ch.res_name) == 0)) {
+ num = aw->num;
+ both_match = 1;
+ } else if (aw->name == NULL && !both_match)
+ num = aw->num;
+ }
+ }
+
+ if (num == 0) {
group_assign(NULL, cc);
+ return(1);
+ }
+ TAILQ_FOREACH(gc, &sc->groupq, entry) {
+ if (gc->num == num) {
+ group_assign(gc, cc);
+ return(1);
+ }
+ }
+ return(0);
}