From 469db5f3719333ff97443e17b81008fb0cddf922 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 27 Jan 2014 14:49:40 +0000 Subject: [PATCH 1/5] simplify parse_config using assignment; inspired by a very old diff from Tiago Cunha. --- parse.y | 59 ++------------------------------------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/parse.y b/parse.y index cb14dd1..a23e1c5 100644 --- a/parse.y +++ b/parse.y @@ -547,76 +547,21 @@ parse_config(const char *filename, struct conf *xconf) { int errors = 0; - conf = xcalloc(1, sizeof(*conf)); + conf = xconf; if ((file = pushfile(filename)) == NULL) { - free(conf); return (-1); } topfile = file; - conf_init(conf); - yyparse(); errors = file->errors; popfile(); if (errors) { conf_clear(conf); + conf_init(conf); } - else { - struct autogroupwin *ag; - struct keybinding *kb; - struct winmatch *wm; - struct cmd *cmd; - struct mousebinding *mb; - int i; - - conf_clear(xconf); - - xconf->flags = conf->flags; - xconf->bwidth = conf->bwidth; - xconf->mamount = conf->mamount; - xconf->snapdist = conf->snapdist; - xconf->gap = conf->gap; - - while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) { - TAILQ_REMOVE(&conf->cmdq, cmd, entry); - TAILQ_INSERT_TAIL(&xconf->cmdq, cmd, entry); - } - - while ((kb = TAILQ_FIRST(&conf->keybindingq)) != NULL) { - TAILQ_REMOVE(&conf->keybindingq, kb, entry); - TAILQ_INSERT_TAIL(&xconf->keybindingq, kb, entry); - } - - while ((ag = TAILQ_FIRST(&conf->autogroupq)) != NULL) { - TAILQ_REMOVE(&conf->autogroupq, ag, entry); - TAILQ_INSERT_TAIL(&xconf->autogroupq, ag, entry); - } - - while ((wm = TAILQ_FIRST(&conf->ignoreq)) != NULL) { - TAILQ_REMOVE(&conf->ignoreq, wm, entry); - TAILQ_INSERT_TAIL(&xconf->ignoreq, wm, entry); - } - - while ((mb = TAILQ_FIRST(&conf->mousebindingq)) != NULL) { - TAILQ_REMOVE(&conf->mousebindingq, mb, entry); - TAILQ_INSERT_TAIL(&xconf->mousebindingq, mb, entry); - } - - (void)strlcpy(xconf->termpath, conf->termpath, - sizeof(xconf->termpath)); - (void)strlcpy(xconf->lockpath, conf->lockpath, - sizeof(xconf->lockpath)); - - for (i = 0; i < CWM_COLOR_NITEMS; i++) - xconf->color[i] = conf->color[i]; - - xconf->font = conf->font; - } - - free(conf); return (errors ? -1 : 0); } From 0608610cc7fb83ffa360fa85968e60b098cf3ded Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 27 Jan 2014 15:13:09 +0000 Subject: [PATCH 2/5] move some init up and shed some blank lines --- client.c | 1 - screen.c | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client.c b/client.c index f7e3148..22ee927 100644 --- a/client.c +++ b/client.c @@ -119,7 +119,6 @@ client_init(Window win, struct screen_ctx *sc, int mapped) TAILQ_INSERT_TAIL(&Clientq, cc, entry); xu_ewmh_net_client_list(sc); - xu_ewmh_restore_net_wm_state(cc); if (mapped) diff --git a/screen.c b/screen.c index ed8606c..257afe3 100644 --- a/screen.c +++ b/screen.c @@ -41,20 +41,18 @@ screen_init(int which) sc = xcalloc(1, sizeof(*sc)); + TAILQ_INIT(&sc->mruq); + sc->which = which; sc->visual = DefaultVisual(X_Dpy, sc->which); sc->colormap = DefaultColormap(X_Dpy, sc->which); sc->rootwin = RootWindow(X_Dpy, sc->which); + conf_screen(sc); xu_ewmh_net_supported(sc); xu_ewmh_net_supported_wm_check(sc); - conf_screen(sc); - screen_update_geometry(sc); - - TAILQ_INIT(&sc->mruq); - group_init(sc); rootattr.cursor = Conf.cursor[CF_NORMAL]; From 51b3fbee52a54cd068b5485542b454244d651c34 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 28 Jan 2014 00:42:20 +0000 Subject: [PATCH 3/5] Move conf_init/clear into main - no behaviour change; from Tiago Cunha. --- calmwm.c | 5 ++++- parse.y | 7 +------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/calmwm.c b/calmwm.c index 1c38b2e..abdb79c 100644 --- a/calmwm.c +++ b/calmwm.c @@ -108,8 +108,11 @@ main(int argc, char **argv) } conf_init(&Conf); - if (conf_path && (parse_config(conf_path, &Conf) == -1)) + if (conf_path && (parse_config(conf_path, &Conf) == -1)) { warnx("config file %s has errors, not loading", conf_path); + conf_clear(&Conf); + conf_init(&Conf); + } free(conf_path); x_init(display_name); diff --git a/parse.y b/parse.y index a23e1c5..984f6bc 100644 --- a/parse.y +++ b/parse.y @@ -545,7 +545,7 @@ popfile(void) int parse_config(const char *filename, struct conf *xconf) { - int errors = 0; + int errors = 0; conf = xconf; @@ -558,10 +558,5 @@ parse_config(const char *filename, struct conf *xconf) errors = file->errors; popfile(); - if (errors) { - conf_clear(conf); - conf_init(conf); - } - return (errors ? -1 : 0); } From df15337a9f180e41d5489ad9d45fc39ed3cdd335 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 28 Jan 2014 13:40:40 +0000 Subject: [PATCH 4/5] The EWMH spec states that if the cardinal returned is 0xFFFFFFFF (-1) then the window should appear on all desktops, which in our case is assigned to group 0. Found to fix stalonetray due to the non-ewmh aware range checking in group_movetogroup(); from Thomas Adam. --- xevents.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xevents.c b/xevents.c index b01f966..b321acb 100644 --- a/xevents.c +++ b/xevents.c @@ -346,8 +346,17 @@ xev_handle_clientmessage(XEvent *ee) client_ptrwarp(cc); } - if (e->message_type == ewmh[_NET_WM_DESKTOP] && e->format == 32) - group_movetogroup(cc, e->data.l[0]); + if (e->message_type == ewmh[_NET_WM_DESKTOP] && e->format == 32) { + /* + * The EWMH spec states that if the cardinal returned is + * 0xFFFFFFFF (-1) then the window should appear on all + * desktops, which in our case is assigned to group 0. + */ + if (e->data.l[0] == (unsigned long)-1) + group_movetogroup(cc, 0); + else + group_movetogroup(cc, e->data.l[0]); + } if (e->message_type == ewmh[_NET_WM_STATE] && e->format == 32) xu_ewmh_handle_net_wm_state_msg(cc, From c28467cda5323f2251ed16a407fd77b7ec9e5ba6 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 28 Jan 2014 20:22:21 +0000 Subject: [PATCH 5/5] Check ignore windowname for truncation and provide user feedback during config parse; based on a discussion with Tiago Cunha. --- calmwm.h | 2 +- conf.c | 6 ++++-- parse.y | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 38323e0..4ea482e 100644 --- a/calmwm.h +++ b/calmwm.h @@ -528,7 +528,7 @@ void conf_cursor(struct conf *); void conf_grab_kbd(Window); void conf_grab_mouse(Window); void conf_init(struct conf *); -void conf_ignore(struct conf *, const char *); +int conf_ignore(struct conf *, const char *); void conf_screen(struct screen_ctx *); void xev_process(void); diff --git a/conf.c b/conf.c index fce37ab..9ecf1b4 100644 --- a/conf.c +++ b/conf.c @@ -73,16 +73,18 @@ conf_autogroup(struct conf *c, int no, const char *val) TAILQ_INSERT_TAIL(&c->autogroupq, aw, entry); } -void +int conf_ignore(struct conf *c, const char *val) { struct winmatch *wm; wm = xcalloc(1, sizeof(*wm)); - (void)strlcpy(wm->title, val, sizeof(wm->title)); + if (strlcpy(wm->title, val, sizeof(wm->title)) >= sizeof(wm->title)) + return (0); TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); + return (1); } static const char *color_binds[] = { diff --git a/parse.y b/parse.y index 984f6bc..672a896 100644 --- a/parse.y +++ b/parse.y @@ -151,7 +151,11 @@ main : FONTNAME STRING { free($3); } | IGNORE STRING { - conf_ignore(conf, $2); + if (!conf_ignore(conf, $2)) { + yyerror("ignore windowname too long"); + free($2); + YYERROR; + } free($2); } | BIND STRING string {