summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2016-10-04 15:52:32 +0000
committerokan <okan>2016-10-04 15:52:32 +0000
commit5c13775d31ce277bba94c68daff12cf50224aba0 (patch)
tree210c8ac83b54ec23d1b2e0d6917ca7d7cf1d416a
parent9306c1fbd3e491b9dcdcbb8587460296843a10ce (diff)
downloadcwm-5c13775d31ce277bba94c68daff12cf50224aba0.tar.gz
cwm-5c13775d31ce277bba94c68daff12cf50224aba0.tar.xz
cwm-5c13775d31ce277bba94c68daff12cf50224aba0.zip
Calculate client nameqlen in client_setname(), the only place it's
needed/used.
-rw-r--r--calmwm.h3
-rw-r--r--client.c13
-rw-r--r--conf.c1
3 files changed, 9 insertions, 8 deletions
diff --git a/calmwm.h b/calmwm.h
index d9734d9..867f3ad 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -187,8 +187,6 @@ struct client_ctx {
 	int			 flags;
 	int			 stackingorder;
 	struct winname_q	 nameq;
-#define CLIENT_MAXNAMEQLEN		5
-	int			 nameqlen;
 	char			*name;
 	char			*label;
 	char			*matchname;
@@ -284,6 +282,7 @@ struct conf {
 	struct cmd_q		 cmdq;
 	int			 ngroups;
 	int			 stickygroups;
+	int			 nameqlen;
 	int			 bwidth;
 	int			 mamount;
 	int			 snapdist;
diff --git a/client.c b/client.c
index 1de9290..ce7392e 100644
--- a/client.c
+++ b/client.c
@@ -605,6 +605,7 @@ client_setname(struct client_ctx *cc)
 {
 	struct winname	*wn;
 	char		*newname;
+	int		 i = 0;
 
 	if (!xu_getstrprop(cc->win, ewmh[_NET_WM_NAME], &newname))
 		if (!xu_getstrprop(cc->win, XA_WM_NAME, &newname))
@@ -621,19 +622,19 @@ client_setname(struct client_ctx *cc)
 	wn = xmalloc(sizeof(*wn));
 	wn->name = newname;
 	TAILQ_INSERT_TAIL(&cc->nameq, wn, entry);
-	cc->nameqlen++;
 
 match:
 	cc->name = wn->name;
 
-	/* Now, do some garbage collection. */
-	if (cc->nameqlen > CLIENT_MAXNAMEQLEN) {
-		if ((wn = TAILQ_FIRST(&cc->nameq)) == NULL)
-			errx(1, "client_setname: window name queue empty");
+	/* Do some garbage collection. */
+	TAILQ_FOREACH(wn, &cc->nameq, entry)
+		i++;
+	if (i > Conf.nameqlen) {
+		wn = TAILQ_FIRST(&cc->nameq);
 		TAILQ_REMOVE(&cc->nameq, wn, entry);
 		free(wn->name);
 		free(wn);
-		cc->nameqlen--;
+		i--;
 	}
 }
 
diff --git a/conf.c b/conf.c
index 478768d..974388c 100644
--- a/conf.c
+++ b/conf.c
@@ -259,6 +259,7 @@ conf_init(struct conf *c)
 	c->mamount = 1;
 	c->snapdist = 0;
 	c->ngroups = 10;
+	c->nameqlen = 5;
 
 	TAILQ_INIT(&c->ignoreq);
 	TAILQ_INIT(&c->cmdq);