diff --git a/calmwm.h b/calmwm.h index 096a5c4..35bf6c2 100644 --- a/calmwm.h +++ b/calmwm.h @@ -431,6 +431,7 @@ struct menu *menu_filter(struct screen_ctx *, struct menu_q *, void (*)(struct menu_q *, struct menu_q *, char *), void (*)(struct menu *, int)); void menu_init(struct screen_ctx *); +void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); diff --git a/group.c b/group.c index dd96575..1b89825 100644 --- a/group.c +++ b/group.c @@ -385,10 +385,7 @@ group_menu(XButtonEvent *e) (gc->hidden) ? group_show(sc, gc) : group_hide(sc, gc); cleanup: - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); } void diff --git a/kbfunc.c b/kbfunc.c index e8ab152..023069d 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -168,10 +168,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg) client_ptrwarp(cc); } - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); } void @@ -195,10 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg) search_match_text, NULL)) != NULL) u_spawn(((struct cmd *)mi->ctx)->image); - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); } void @@ -320,10 +314,7 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg) out: if (mi != NULL && mi->dummy) free(mi); - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); } void @@ -390,10 +381,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) out: if (mi != NULL && mi->dummy) free(mi); - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); } void diff --git a/menu.c b/menu.c index dd6de18..3889d96 100644 --- a/menu.c +++ b/menu.c @@ -215,10 +215,7 @@ menu_complete_path(struct menu_ctx *mc) strlcpy(path, mi->text, sizeof(mi->text)); } - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); if (path[0] != '\0') snprintf(mr->text, sizeof(mr->text), "%s \"%s\"", @@ -632,3 +629,14 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) return (0); } + +void +menuq_clear(struct menu_q *mq) +{ + struct menu *mi; + + while ((mi = TAILQ_FIRST(mq)) != NULL) { + TAILQ_REMOVE(mq, mi, entry); + free(mi); + } +} diff --git a/mousefunc.c b/mousefunc.c index a342b8e..eb5171a 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -250,12 +250,8 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg) if (old_cc != NULL) client_ptrsave(old_cc); client_ptrwarp(cc); - } else { - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } - } + } else + menuq_clear(&menuq); } void @@ -280,8 +276,5 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg) if (mi != NULL) u_spawn(((struct cmd *)mi->ctx)->image); else - while ((mi = TAILQ_FIRST(&menuq)) != NULL) { - TAILQ_REMOVE(&menuq, mi, entry); - free(mi); - } + menuq_clear(&menuq); }