summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2014-02-08 02:49:30 +0000
committerokan <okan>2014-02-08 02:49:30 +0000
commit8ddc90665e293efeb810ce73b871ee6e4f6ce68a (patch)
treef9420dc05d83dbd934bbb425161603bb0c4b4bb8
parent8653141b4b5d76bd7238003cf43034681c7724a4 (diff)
parent6798e3dde302febeef3aa641eadea55d394461ff (diff)
downloadcwm-8ddc90665e293efeb810ce73b871ee6e4f6ce68a.tar.gz
cwm-8ddc90665e293efeb810ce73b871ee6e4f6ce68a.tar.xz
cwm-8ddc90665e293efeb810ce73b871ee6e4f6ce68a.zip
cvsimport
-rw-r--r--calmwm.h1
-rw-r--r--client.c3
-rw-r--r--group.c77
-rw-r--r--mousefunc.c2
-rw-r--r--screen.c1
-rw-r--r--search.c2
-rw-r--r--xutil.c6
7 files changed, 40 insertions, 52 deletions
diff --git a/calmwm.h b/calmwm.h
index 6026206..b68cc37 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -427,6 +427,7 @@ 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 *);
diff --git a/client.c b/client.c
index 5005d49..adc2f9c 100644
--- a/client.c
+++ b/client.c
@@ -491,7 +491,8 @@ client_unhide(struct client_ctx *cc)
 void
 client_urgency(struct client_ctx *cc)
 {
-	cc->flags |= CLIENT_URGENCY;
+	if (!cc->active)
+		cc->flags |= CLIENT_URGENCY;
 }
 
 void
diff --git a/group.c b/group.c
index 990b914..8ad372e 100644
--- a/group.c
+++ b/group.c
@@ -32,8 +32,7 @@
 
 #include "calmwm.h"
 
-static void		 group_add(struct group_ctx *, struct client_ctx *);
-static void		 group_remove(struct client_ctx *);
+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_fix_hidden_state(struct group_ctx *);
@@ -46,11 +45,10 @@ const char *shortcut_to_name[] = {
 };
 
 static void
-group_add(struct group_ctx *gc, struct client_ctx *cc)
+group_assign(struct group_ctx *gc, struct client_ctx *cc)
 {
-	if (cc == NULL || gc == NULL)
-		errx(1, "group_add: a ctx is NULL");
-
+	if (gc == NULL)
+		gc = TAILQ_FIRST(&cc->sc->groupq);
 	if (cc->group == gc)
 		return;
 
@@ -64,18 +62,6 @@ group_add(struct group_ctx *gc, struct client_ctx *cc)
 }
 
 static void
-group_remove(struct client_ctx *cc)
-{
-	if (cc == NULL || cc->group == NULL)
-		errx(1, "group_remove: a ctx is NULL");
-
-	TAILQ_REMOVE(&cc->group->clients, cc, group_entry);
-	cc->group = NULL;
-
-	xu_ewmh_net_wm_desktop(cc);
-}
-
-static void
 group_hide(struct screen_ctx *sc, struct group_ctx *gc)
 {
 	struct client_ctx	*cc;
@@ -162,6 +148,15 @@ 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_fix_hidden_state(gc);
+}
+
 static void
 group_setactive(struct screen_ctx *sc, long idx)
 {
@@ -186,7 +181,7 @@ group_movetogroup(struct client_ctx *cc, int idx)
 		client_hide(cc);
 		gc->nhidden++;
 	}
-	group_add(gc, cc);
+	group_assign(gc, cc);
 }
 
 /*
@@ -199,10 +194,10 @@ group_sticky_toggle_enter(struct client_ctx *cc)
 	struct group_ctx	*gc = sc->group_active;
 
 	if (gc == cc->group) {
-		group_remove(cc);
+		group_assign(NULL, cc);
 		cc->flags |= CLIENT_UNGROUP;
 	} else {
-		group_add(gc, cc);
+		group_assign(gc, cc);
 		cc->flags |= CLIENT_GROUP;
 	}
 
@@ -258,16 +253,16 @@ group_hidetoggle(struct screen_ctx *sc, int idx)
 void
 group_only(struct screen_ctx *sc, int idx)
 {
-	int	 i;
+	struct group_ctx	*gc;
 
 	if (idx < 0 || idx >= CALMWM_NGROUPS)
 		errx(1, "group_only: index out of range (%d)", idx);
 
-	for (i = 0; i < CALMWM_NGROUPS; i++) {
-		if (i == idx)
-			group_show(sc, &sc->groups[i]);
+	TAILQ_FOREACH(gc, &sc->groupq, entry) {
+		if (gc->shortcut == idx)
+			group_show(sc, gc);
 		else
-			group_hide(sc, &sc->groups[i]);
+			group_hide(sc, gc);
 	}
 }
 
@@ -314,18 +309,15 @@ group_menu(struct screen_ctx *sc)
 	struct group_ctx	*gc;
 	struct menu		*mi;
 	struct menu_q		 menuq;
-	int			 i;
 
 	TAILQ_INIT(&menuq);
 
-	for (i = 0; i < CALMWM_NGROUPS; i++) {
-		gc = &sc->groups[i];
-
+	TAILQ_FOREACH(gc, &sc->groupq, entry) {
 		if (TAILQ_EMPTY(&gc->clients))
 			continue;
 
 		menuq_add(&menuq, gc, gc->hidden ? "%d: [%s]" : "%d: %s",
-		    gc->shortcut, sc->group_names[i]);
+		    gc->shortcut, sc->group_names[gc->shortcut]);
 	}
 
 	if (TAILQ_EMPTY(&menuq))
@@ -343,16 +335,15 @@ group_menu(struct screen_ctx *sc)
 void
 group_alltoggle(struct screen_ctx *sc)
 {
-	int	 i;
+	struct group_ctx	*gc;
 
-	for (i = 0; i < CALMWM_NGROUPS; i++) {
+	TAILQ_FOREACH(gc, &sc->groupq, entry) {
 		if (sc->group_hideall)
-			group_show(sc, &sc->groups[i]);
+			group_show(sc, gc);
 		else
-			group_hide(sc, &sc->groups[i]);
+			group_hide(sc, gc);
 	}
-
-	sc->group_hideall = (!sc->group_hideall);
+	sc->group_hideall = !sc->group_hideall;
 }
 
 void
@@ -369,7 +360,7 @@ group_autogroup(struct client_ctx *cc)
 
 	if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP],
 	    XA_CARDINAL, 1, (unsigned char **)&grpno) > 0) {
-		if (*grpno == 0xffffffff)
+		if (*grpno == -1)
 			no = 0;
 		else if (*grpno > CALMWM_NGROUPS || *grpno < 0)
 			no = CALMWM_NGROUPS - 1;
@@ -389,19 +380,17 @@ group_autogroup(struct client_ctx *cc)
 		}
 	}
 
-	/* no group please */
-	if (no == 0)
-		return;
-
 	TAILQ_FOREACH(gc, &sc->groupq, entry) {
 		if (gc->shortcut == no) {
-			group_add(gc, cc);
+			group_assign(gc, cc);
 			return;
 		}
 	}
 
 	if (Conf.flags & CONF_STICKY_GROUPS)
-		group_add(sc->group_active, cc);
+		group_assign(sc->group_active, cc);
+	else
+		group_assign(NULL, cc);
 }
 
 void
diff --git a/mousefunc.c b/mousefunc.c
index 19668be..9db0aa6 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -203,7 +203,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, union arg *arg)
 				continue;
 
 			menuq_add(&menuq, cc, "(%d) %s",
-			    cc->group ? cc->group->shortcut : 0, wname);
+			    cc->group->shortcut, wname);
 		}
 
 	if (TAILQ_EMPTY(&menuq))
diff --git a/screen.c b/screen.c
index 22f7ef0..59fa992 100644
--- a/screen.c
+++ b/screen.c
@@ -69,6 +69,7 @@ screen_init(int which)
 		XFree(wins);
 	}
 	screen_updatestackingorder(sc);
+	group_set_state(sc);
 
 	if (HasRandr)
 		XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask);
diff --git a/search.c b/search.c
index 4424a8e..980cb54 100644
--- a/search.c
+++ b/search.c
@@ -143,7 +143,7 @@ search_print_client(struct menu *mi, int list)
 		cc->matchname = cc->name;
 
 	(void)snprintf(mi->print, sizeof(mi->print), "(%d) %c%s",
-	    cc->group ? cc->group->shortcut : 0, flag, cc->matchname);
+	    cc->group->shortcut, flag, cc->matchname);
 
 	if (!list && cc->matchname != cc->name &&
 	    strlen(mi->print) < sizeof(mi->print) - 1) {
diff --git a/xutil.c b/xutil.c
index 1884d5f..58ee304 100644
--- a/xutil.c
+++ b/xutil.c
@@ -291,11 +291,7 @@ xu_ewmh_net_desktop_names(struct screen_ctx *sc, char *data, int n)
 void
 xu_ewmh_net_wm_desktop(struct client_ctx *cc)
 {
-	struct group_ctx	*gc = cc->group;
-	long			 no = 0xffffffff;
-
-	if (gc)
-		no = gc->shortcut;
+	int	 no = cc->group->shortcut;
 
 	XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_DESKTOP],
 	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1);