From 1a06f09fa0e1a92d98757f1d9d0a001ecf3e3bb4 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 6 May 2013 19:09:19 +0000 Subject: negative values for borderwith, moveamount, snapdist and gap are configuration errors, so warn and load defaults. --- parse.y | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 2708948..9de56da 100644 --- a/parse.y +++ b/parse.y @@ -117,12 +117,24 @@ main : FONTNAME STRING { conf->flags |= CONF_STICKY_GROUPS; } | BORDERWIDTH NUMBER { + if ($2 < 0) { + yyerror("invalid borderwidth: %d", $2); + YYERROR; + } conf->bwidth = $2; } | MOVEAMOUNT NUMBER { + if ($2 < 0) { + yyerror("invalid movemount: %d", $2); + YYERROR; + } conf->mamount = $2; } | SNAPDIST NUMBER { + if ($2 < 0) { + yyerror("invalid snapdist: %d", $2); + YYERROR; + } conf->snapdist = $2; } | COMMAND STRING string { @@ -133,10 +145,9 @@ main : FONTNAME STRING { | AUTOGROUP NUMBER STRING { if ($2 < 0 || $2 > 9) { free($3); - yyerror("autogroup number out of range: %d", $2); + yyerror("invalid autogroup: %d", $2); YYERROR; } - conf_autogroup(conf, $2, $3); free($3); } @@ -150,6 +161,11 @@ main : FONTNAME STRING { free($3); } | GAP NUMBER NUMBER NUMBER NUMBER { + if ($2 < 0 || $3 < 0 || $4 < 0 || $5 < 0) { + yyerror("invalid gap: %d %d %d %d", + $2, $3, $4, $5); + YYERROR; + } conf->gap.top = $2; conf->gap.bottom = $3; conf->gap.left = $4; -- cgit 1.4.1 From dac00a232f975967dec9ae8e838b069ec01e6c62 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:09:59 +0000 Subject: - switch border colors to Xft - merge border/menu color structures/functions since they now both use Xft - switch xu_xorcolor to operating on XftColor instead of just XRenderColor (basically adding pixel) - if color name allocation fails, revert back to default (this, along with font validation should occur during config parse, but we don't have screens setup yet - likely to change at some point) --- calmwm.h | 29 ++++++++++------------------- client.c | 8 ++++---- conf.c | 47 +++++++++++++++++++++++++++++++---------------- font.c | 22 +--------------------- parse.y | 21 +++++++++------------ xutil.c | 24 ++++++------------------ 6 files changed, 61 insertions(+), 90 deletions(-) (limited to 'parse.y') diff --git a/calmwm.h b/calmwm.h index cf980e1..ebc5bd0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -85,20 +85,16 @@ union arg { int i; }; -enum menucolor { - CWM_COLOR_MENU_FG, - CWM_COLOR_MENU_BG, - CWM_COLOR_MENU_FONT, - CWM_COLOR_MENU_FONT_SEL, - CWM_COLOR_MENU_MAX -}; - -enum bordercolor { +enum color { CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_INACTIVE, CWM_COLOR_BORDER_GROUP, CWM_COLOR_BORDER_UNGROUP, - CWM_COLOR_BORDER_MAX + CWM_COLOR_MENU_FG, + CWM_COLOR_MENU_BG, + CWM_COLOR_MENU_FONT, + CWM_COLOR_MENU_FONT_SEL, + CWM_COLOR_MAX }; struct geom { @@ -213,13 +209,12 @@ struct screen_ctx { Colormap colormap; Window rootwin; Window menuwin; - unsigned long color[CWM_COLOR_BORDER_MAX]; int cycling; struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ struct gap gap; struct cycle_entry_q mruq; - XftColor xftcolor[CWM_COLOR_MENU_MAX]; + XftColor xftcolor[CWM_COLOR_MAX]; XftDraw *xftdraw; XftFont *xftfont; int xinerama_no; @@ -293,8 +288,7 @@ struct conf { #define CONF_SNAPDIST 0 int snapdist; struct gap gap; - char *color[CWM_COLOR_BORDER_MAX]; - char *menucolor[CWM_COLOR_MENU_MAX]; + char *color[CWM_COLOR_MAX]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; char known_hosts[MAXPATHLEN]; @@ -452,8 +446,7 @@ void conf_ungrab(struct conf *, struct keybinding *); void font_draw(struct screen_ctx *, const char *, Drawable, int, int, int); -void font_init(struct screen_ctx *, const char *, - const char **); +void font_init(struct screen_ctx *, const char *); int font_width(XftFont *, const char *, int); void xev_loop(void); @@ -462,7 +455,6 @@ void xu_btn_grab(Window, int, u_int); void xu_btn_ungrab(Window, int, u_int); void xu_configure(struct client_ctx *); void xu_getatoms(void); -unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); @@ -475,8 +467,7 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); -void xu_xorcolor(XRenderColor, XRenderColor, - XRenderColor *); +void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); void xu_ewmh_net_supported_wm_check(struct screen_ctx *); diff --git a/client.c b/client.c index 6001372..9ebd8bc 100644 --- a/client.c +++ b/client.c @@ -480,17 +480,17 @@ client_draw_border(struct client_ctx *cc) if (cc->active) switch (cc->flags & CLIENT_HIGHLIGHT) { case CLIENT_GROUP: - pixel = sc->color[CWM_COLOR_BORDER_GROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_GROUP].pixel; break; case CLIENT_UNGROUP: - pixel = sc->color[CWM_COLOR_BORDER_UNGROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_UNGROUP].pixel; break; default: - pixel = sc->color[CWM_COLOR_BORDER_ACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_ACTIVE].pixel; break; } else - pixel = sc->color[CWM_COLOR_BORDER_INACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel; XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth); XSetWindowBorder(X_Dpy, cc->win, pixel); diff --git a/conf.c b/conf.c index 698ab4c..657c686 100644 --- a/conf.c +++ b/conf.c @@ -84,31 +84,49 @@ conf_ignore(struct conf *c, char *val) TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); } -static char *menu_color_binds[CWM_COLOR_MENU_MAX] = { - "black", /* CWM_COLOR_MENU_FG */ - "white", /* CWM_COLOR_MENU_BG */ - "black", /* CWM_COLOR_MENU_FONT */ - "", /* CWM_COLOR_MENU_FONT_SEL */ -}; - -static char *color_binds[CWM_COLOR_BORDER_MAX] = { +static char *color_binds[CWM_COLOR_MAX] = { "#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */ "#666666", /* CWM_COLOR_BORDER_INACTIVE */ "blue", /* CWM_COLOR_BORDER_GROUP */ "red", /* CWM_COLOR_BORDER_UNGROUP */ + "black", /* CWM_COLOR_MENU_FG */ + "white", /* CWM_COLOR_MENU_BG */ + "black", /* CWM_COLOR_MENU_FONT */ + "", /* CWM_COLOR_MENU_FONT_SEL */ }; void conf_screen(struct screen_ctx *sc) { - int i; + int i; + XftColor xc; sc->gap = Conf.gap; - font_init(sc, Conf.font, (const char **)Conf.menucolor); + font_init(sc, Conf.font); + + for (i = 0; i < CWM_COLOR_MAX; i++) { + if (*Conf.color[i] == '\0') + break; + if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + Conf.color[i], &xc)) { + sc->xftcolor[i] = xc; + XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc); + } else { + warnx("XftColorAllocName: '%s'", Conf.color[i]); + XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + color_binds[i], &sc->xftcolor[i]); + } + } + if (i == CWM_COLOR_MAX) + return; - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) - sc->color[i] = xu_getcolor(sc, Conf.color[i]); + xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG], + sc->xftcolor[CWM_COLOR_MENU_FG], &xc); + xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc); + if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, + &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + warnx("XftColorAllocValue: '%s'", Conf.color[i]); } static struct { @@ -210,9 +228,6 @@ conf_init(struct conf *c) for (i = 0; i < nitems(color_binds); i++) c->color[i] = xstrdup(color_binds[i]); - for (i = 0; i < nitems(menu_color_binds); i++) - c->menucolor[i] = xstrdup(menu_color_binds[i]); - /* Default term/lock */ (void)strlcpy(c->termpath, "xterm", sizeof(c->termpath)); (void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath)); @@ -260,7 +275,7 @@ conf_clear(struct conf *c) free(mb); } - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) free(c->color[i]); free(c->font); diff --git a/font.c b/font.c index e2b68c0..f4251d9 100644 --- a/font.c +++ b/font.c @@ -31,11 +31,8 @@ #include "calmwm.h" void -font_init(struct screen_ctx *sc, const char *name, const char **color) +font_init(struct screen_ctx *sc, const char *name) { - int i; - XRenderColor c; - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, sc->visual, sc->colormap); if (sc->xftdraw == NULL) @@ -44,23 +41,6 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name); if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); - - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { - if (*color[i] == '\0') - break; - if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap, - color[i], &sc->xftcolor[i])) - errx(1, "XftColorAllocName"); - } - if (i == CWM_COLOR_MENU_MAX) - return; - - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color, - sc->xftcolor[CWM_COLOR_MENU_FG].color, &c); - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c); - if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, - &c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) - errx(1, "XftColorAllocValue"); } int diff --git a/parse.y b/parse.y index 9de56da..e0c13bb 100644 --- a/parse.y +++ b/parse.y @@ -198,20 +198,20 @@ colors : ACTIVEBORDER STRING { conf->color[CWM_COLOR_BORDER_UNGROUP] = $2; } | MENUBG STRING { - free(conf->menucolor[CWM_COLOR_MENU_BG]); - conf->menucolor[CWM_COLOR_MENU_BG] = $2; + free(conf->color[CWM_COLOR_MENU_BG]); + conf->color[CWM_COLOR_MENU_BG] = $2; } | MENUFG STRING { - free(conf->menucolor[CWM_COLOR_MENU_FG]); - conf->menucolor[CWM_COLOR_MENU_FG] = $2; + free(conf->color[CWM_COLOR_MENU_FG]); + conf->color[CWM_COLOR_MENU_FG] = $2; } | FONTCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT]); - conf->menucolor[CWM_COLOR_MENU_FONT] = $2; + free(conf->color[CWM_COLOR_MENU_FONT]); + conf->color[CWM_COLOR_MENU_FONT] = $2; } | FONTSELCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]); - conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2; + free(conf->color[CWM_COLOR_MENU_FONT_SEL]); + conf->color[CWM_COLOR_MENU_FONT_SEL] = $2; } ; %% @@ -589,12 +589,9 @@ parse_config(const char *filename, struct conf *xconf) (void)strlcpy(xconf->lockpath, conf->lockpath, sizeof(xconf->lockpath)); - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) xconf->color[i] = conf->color[i]; - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) - xconf->menucolor[i] = conf->menucolor[i]; - xconf->font = conf->font; } diff --git a/xutil.c b/xutil.c index d9f2106..bcc7366 100644 --- a/xutil.c +++ b/xutil.c @@ -420,24 +420,12 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } -unsigned long -xu_getcolor(struct screen_ctx *sc, char *name) -{ - XColor color, tmp; - - if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) { - warnx("XAllocNamedColor error: '%s'", name); - return (0); - } - - return (color.pixel); -} - void -xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r) +xu_xorcolor(XftColor a, XftColor b, XftColor *r) { - r->red = a.red ^ b.red; - r->green = a.green ^ b.green; - r->blue = a.blue ^ b.blue; - r->alpha = 0xffff; + r->pixel = a.pixel ^ b.pixel; + r->color.red = a.color.red ^ b.color.red; + r->color.green = a.color.green ^ b.color.green; + r->color.blue = a.color.blue ^ b.color.blue; + r->color.alpha = 0xffff; } -- cgit 1.4.1 From 866f5af9c746d84e68ab1a376c18f96581fb0765 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 13:02:14 +0000 Subject: sync with src changes --- parse.y | 63 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index e0c13bb..111be2e 100644 --- a/parse.y +++ b/parse.y @@ -42,18 +42,17 @@ static struct file { char *name; int lineno; int errors; -} *file; - -struct file *pushfile(const char *); -int popfile(void); -int yyparse(void); -int yylex(void); -int yyerror(const char *, ...); -int kw_cmp(const void *, const void *); -int lookup(char *); -int lgetc(int); -int lungetc(int); -int findeol(void); +} *file, *topfile; +struct file *pushfile(const char *); +int popfile(void); +int yyparse(void); +int yylex(void); +int yyerror(const char *, ...); +int kw_cmp(const void *, const void *); +int lookup(char *); +int lgetc(int); +int lungetc(int); +int findeol(void); static struct conf *conf; @@ -224,7 +223,7 @@ struct keywords { int yyerror(const char *fmt, ...) { - va_list ap; + va_list ap; file->errors++; va_start(ap, fmt); @@ -308,8 +307,9 @@ lgetc(int quotec) if (quotec) { if ((c = getc(file->stream)) == EOF) { - yyerror("reached end of file while parsing quoted string"); - if (popfile() == EOF) + yyerror("reached end of file while parsing " + "quoted string"); + if (file == topfile || popfile() == EOF) return (EOF); return (quotec); } @@ -327,7 +327,7 @@ lgetc(int quotec) } while (c == EOF) { - if (popfile() == EOF) + if (file == topfile || popfile() == EOF) return (EOF); c = getc(file->stream); } @@ -356,11 +356,13 @@ findeol(void) int c; parsebuf = NULL; - pushback_index = 0; /* skip to either EOF or the first real EOL */ while (1) { - c = lgetc(0); + if (pushback_index) + c = pushback_buffer[--pushback_index]; + else + c = lgetc(0); if (c == '\n') { file->lineno++; break; @@ -461,9 +463,10 @@ nodigits: #define allowed_in_string(x) \ (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && x != '<' && x != '>' && \ - x != '!' && x != '=' && x != '#' && x != ',')) + x != '!' && x != '=' && x != '/' && x != '#' && \ + x != ',')) - if (isalnum(c) || c == ':' || c == '_' || c == '*' || c == '/') { + if (isalnum(c) || c == ':' || c == '_' || c == '*') { do { *p++ = c; if ((unsigned)(p-buf) >= sizeof(buf)) { @@ -495,6 +498,7 @@ pushfile(const char *name) nfile->name = xstrdup(name); if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { + warn("%s", nfile->name); free(nfile->name); free(nfile); return (NULL); @@ -509,16 +513,15 @@ popfile(void) { struct file *prev; - if ((prev = TAILQ_PREV(file, files, entry)) != NULL) { + if ((prev = TAILQ_PREV(file, files, entry)) != NULL) prev->errors += file->errors; - TAILQ_REMOVE(&files, file, entry); - fclose(file->stream); - free(file->name); - free(file); - file = prev; - return (0); - } - return (EOF); + + TAILQ_REMOVE(&files, file, entry); + fclose(file->stream); + free(file->name); + free(file); + file = prev; + return (file ? 0 : EOF); } int @@ -532,12 +535,12 @@ parse_config(const char *filename, struct conf *xconf) free(conf); return (-1); } + topfile = file; conf_init(conf); yyparse(); errors = file->errors; - file->errors = 0; popfile(); if (errors) { -- cgit 1.4.1 From 532f132194751bd2f530a13c243a30c76f66bfaa Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 16:32:15 +0000 Subject: move validation of pointer Button into conf_mousebind so we check validity during the parse phase and not bother adding it to the queue, instead of each time a client needs to grab (when it's too late); furthermore, make this a config error, stop parsing and load the default config. --- calmwm.h | 2 +- conf.c | 44 ++++++++++++++++++++++---------------------- parse.y | 7 ++++++- 3 files changed, 29 insertions(+), 24 deletions(-) (limited to 'parse.y') diff --git a/calmwm.h b/calmwm.h index b925c2c..16901b3 100644 --- a/calmwm.h +++ b/calmwm.h @@ -439,7 +439,7 @@ void conf_grab(struct conf *, struct keybinding *); void conf_grab_mouse(struct client_ctx *); void conf_init(struct conf *); void conf_ignore(struct conf *, char *); -void conf_mousebind(struct conf *, char *, char *); +int conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); diff --git a/conf.c b/conf.c index 984e4cc..0afc11d 100644 --- a/conf.c +++ b/conf.c @@ -577,11 +577,14 @@ static struct { { "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT }, }; -void +static unsigned int mouse_btns[] = { Button1, Button2, Button3 }; + +int conf_mousebind(struct conf *c, char *name, char *binding) { struct mousebinding *current_binding; char *substring, *tmp; + u_int button; const char *errstr; u_int i; @@ -600,16 +603,27 @@ conf_mousebind(struct conf *c, char *name, char *binding) } else substring = name; - current_binding->button = strtonum(substring, 1, 3, &errstr); + button = strtonum(substring, 1, 3, &errstr); if (errstr) - warnx("number of buttons is %s: %s", errstr, substring); + warnx("button number is %s: %s", errstr, substring); + + for (i = 0; i < nitems(mouse_btns); i++) { + if (button == mouse_btns[i]) { + current_binding->button = button; + break; + } + } + if (!current_binding->button || errstr) { + free(current_binding); + return (0); + } /* We now have the correct binding, remove duplicates. */ conf_mouseunbind(c, current_binding); if (strcmp("unmap", binding) == 0) { free(current_binding); - return; + return (1); } for (i = 0; i < nitems(name_to_mousefunc); i++) { @@ -619,8 +633,10 @@ conf_mousebind(struct conf *c, char *name, char *binding) current_binding->context = name_to_mousefunc[i].context; current_binding->callback = name_to_mousefunc[i].handler; TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry); - return; + return (1); } + + return (0); } static void @@ -646,26 +662,10 @@ void conf_grab_mouse(struct client_ctx *cc) { struct mousebinding *mb; - u_int button; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) continue; - - switch(mb->button) { - case 1: - button = Button1; - break; - case 2: - button = Button2; - break; - case 3: - button = Button3; - break; - default: - warnx("strange button in mousebinding\n"); - continue; - } - xu_btn_grab(cc->win, mb->modmask, button); + xu_btn_grab(cc->win, mb->modmask, mb->button); } } diff --git a/parse.y b/parse.y index 111be2e..0e67ba1 100644 --- a/parse.y +++ b/parse.y @@ -171,7 +171,12 @@ main : FONTNAME STRING { conf->gap.right = $5; } | MOUSEBIND STRING string { - conf_mousebind(conf, $2, $3); + if (!conf_mousebind(conf, $2, $3)) { + yyerror("invalid mousebind: %s %s", $2, $3); + free($2); + free($3); + YYERROR; + } free($2); free($3); } -- cgit 1.4.1