summary refs log tree commit diff
path: root/conf.c
diff options
context:
space:
mode:
authorokan <okan>2015-06-30 18:44:29 +0000
committerokan <okan>2015-06-30 18:44:29 +0000
commitc87953eb647c360cef8834c381bd22de4a0b524b (patch)
tree5fdf4220bf3d6d6e20ede51a595c55b6ab14925e /conf.c
parent6b8b8562172c860b8341fc9acf45ee7e2880e45a (diff)
downloadcwm-c87953eb647c360cef8834c381bd22de4a0b524b.tar.gz
cwm-c87953eb647c360cef8834c381bd22de4a0b524b.tar.xz
cwm-c87953eb647c360cef8834c381bd22de4a0b524b.zip
keep cmdq sorted
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/conf.c b/conf.c
index dab93e2..95054d2 100644
--- a/conf.c
+++ b/conf.c
@@ -40,7 +40,7 @@ static void		 conf_unbind_mouse(struct conf *, struct binding *);
 int
 conf_cmd_add(struct conf *c, const char *name, const char *path)
 {
-	struct cmd	*cmd;
+	struct cmd	*cmd, *prev;
 
 	cmd = xmalloc(sizeof(*cmd));
 
@@ -54,6 +54,14 @@ conf_cmd_add(struct conf *c, const char *name, const char *path)
 	conf_cmd_remove(c, name);
 
 	TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
+
+	/* keep queue sorted by name */
+	while ((prev = TAILQ_PREV(cmd, cmd_q, entry)) &&
+	    (strcmp(prev->name, cmd->name) > 0)) {
+		TAILQ_REMOVE(&c->cmdq, cmd, entry);
+		TAILQ_INSERT_BEFORE(prev, cmd, entry);
+	}
+
 	return(1);
 }