From 5947879dfb16da35be7391e6f81d9313b9fab4c0 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Nov 2012 03:34:19 +0000 Subject: [PATCH 01/21] remove dead extern --- calmwm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index 1abcbef..cf00f54 100644 --- a/calmwm.h +++ b/calmwm.h @@ -509,7 +509,7 @@ extern struct screen_ctx_q Screenq; extern struct client_ctx_q Clientq; extern struct conf Conf; -extern int HasXinerama, HasRandr, Randr_ev; +extern int HasRandr, Randr_ev; enum { WM_STATE, From 7edabe94f2f5a0ac7b900908056173f00cde3837 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Nov 2012 03:54:46 +0000 Subject: [PATCH 02/21] x_setupscreen -> screen_init; no functional change. --- calmwm.c | 58 +------------------------------------------------------- calmwm.h | 1 + screen.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/calmwm.c b/calmwm.c index f95e811..c925760 100644 --- a/calmwm.c +++ b/calmwm.c @@ -54,7 +54,6 @@ static void dpy_init(const char *); static int x_errorhandler(Display *, XErrorEvent *); static int x_wmerrorhandler(Display *, XErrorEvent *); static void x_setup(void); -static void x_setupscreen(struct screen_ctx *, u_int); static void x_teardown(void); int @@ -135,7 +134,7 @@ x_setup(void) for (i = 0; i < ScreenCount(X_Dpy); i++) { sc = xcalloc(1, sizeof(*sc)); - x_setupscreen(sc, i); + screen_init(sc, i); TAILQ_INSERT_TAIL(&Screenq, sc, entry); } @@ -158,61 +157,6 @@ x_teardown(void) XCloseDisplay(X_Dpy); } -static void -x_setupscreen(struct screen_ctx *sc, u_int which) -{ - Window *wins, w0, w1; - XWindowAttributes winattr; - XSetWindowAttributes rootattr; - u_int nwins, i; - - sc->which = which; - sc->rootwin = RootWindow(X_Dpy, sc->which); - - xu_ewmh_net_supported(sc); - xu_ewmh_net_supported_wm_check(sc); - - conf_gap(&Conf, sc); - - screen_update_geometry(sc); - - conf_color(&Conf, sc); - - group_init(sc); - conf_font(&Conf, sc); - - TAILQ_INIT(&sc->mruq); - - /* Initialize menu window. */ - menu_init(sc); - - rootattr.cursor = Cursor_normal; - rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask| - LeaveWindowMask|ColormapChangeMask|BUTTONMASK; - - XChangeWindowAttributes(X_Dpy, sc->rootwin, - CWEventMask|CWCursor, &rootattr); - - /* Deal with existing clients. */ - XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins); - - for (i = 0; i < nwins; i++) { - XGetWindowAttributes(X_Dpy, wins[i], &winattr); - if (winattr.override_redirect || - winattr.map_state != IsViewable) - continue; - (void)client_new(wins[i], sc, winattr.map_state != IsUnmapped); - } - XFree(wins); - - screen_updatestackingorder(sc); - - if (HasRandr) - XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); - - XSync(X_Dpy, False); -} - static int x_wmerrorhandler(Display *dpy, XErrorEvent *e) { diff --git a/calmwm.h b/calmwm.h index cf00f54..38c3fee 100644 --- a/calmwm.h +++ b/calmwm.h @@ -369,6 +369,7 @@ void search_print_client(struct menu *, int); XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int); struct screen_ctx *screen_fromroot(Window); +void screen_init(struct screen_ctx *, u_int); void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); diff --git a/screen.c b/screen.c index b52856f..a515adb 100644 --- a/screen.c +++ b/screen.c @@ -32,6 +32,60 @@ static void screen_init_xinerama(struct screen_ctx *); +void +screen_init(struct screen_ctx *sc, u_int which) +{ + Window *wins, w0, w1; + XWindowAttributes winattr; + XSetWindowAttributes rootattr; + u_int nwins, i; + + sc->which = which; + sc->rootwin = RootWindow(X_Dpy, sc->which); + + xu_ewmh_net_supported(sc); + xu_ewmh_net_supported_wm_check(sc); + + conf_gap(&Conf, sc); + + screen_update_geometry(sc); + + conf_color(&Conf, sc); + + group_init(sc); + conf_font(&Conf, sc); + + TAILQ_INIT(&sc->mruq); + + menu_init(sc); + + rootattr.cursor = Cursor_normal; + rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask| + LeaveWindowMask|ColormapChangeMask|BUTTONMASK; + + XChangeWindowAttributes(X_Dpy, sc->rootwin, + CWEventMask|CWCursor, &rootattr); + + /* Deal with existing clients. */ + XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins); + + for (i = 0; i < nwins; i++) { + XGetWindowAttributes(X_Dpy, wins[i], &winattr); + if (winattr.override_redirect || + winattr.map_state != IsViewable) + continue; + (void)client_new(wins[i], sc, winattr.map_state != IsUnmapped); + } + XFree(wins); + + screen_updatestackingorder(sc); + + if (HasRandr) + XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); + + XSync(X_Dpy, False); +} + struct screen_ctx * screen_fromroot(Window rootwin) { From 560acb43fca290db3009a0b992c7c7c4a09d4c52 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Nov 2012 04:25:49 +0000 Subject: [PATCH 03/21] specific last match for autogroup; few iterations with Kent Spillner. --- cwmrc.5 | 1 + group.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cwmrc.5 b/cwmrc.5 index 39ab221..4e17dbd 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -50,6 +50,7 @@ or if their name and class properties match and .Ar windowclass , respectively. +The more specific last match wins. .Ar group is a number between 0 and 9. If diff --git a/group.c b/group.c index fd507be..dd96575 100644 --- a/group.c +++ b/group.c @@ -412,7 +412,7 @@ group_autogroup(struct client_ctx *cc) struct screen_ctx *sc = cc->sc; struct autogroupwin *aw; struct group_ctx *gc; - int no = -1; + int no = -1, both_match = 0; long *grpno; if (cc->app_class == NULL || cc->app_name == NULL) @@ -429,11 +429,13 @@ group_autogroup(struct client_ctx *cc) XFree(grpno); } else { TAILQ_FOREACH(aw, &Conf.autogroupq, entry) { - if (strcmp(aw->class, cc->app_class) == 0 && - (aw->name == NULL || - strcmp(aw->name, cc->app_name) == 0)) { - no = aw->num; - break; + if (strcmp(aw->class, cc->app_class) == 0) { + if ((aw->name != NULL) && + (strcmp(aw->name, cc->app_name) == 0)) { + no = aw->num; + both_match = 1; + } else if (aw->name == NULL && !both_match) + no = aw->num; } } } From a3aaad2c187278b7ac1cf75cb03882dd3d20f29b Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Nov 2012 16:50:03 +0000 Subject: [PATCH 04/21] zap extra lines --- calmwm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/calmwm.c b/calmwm.c index c925760..97a25b1 100644 --- a/calmwm.c +++ b/calmwm.c @@ -92,9 +92,7 @@ main(int argc, char **argv) conf_setup(&Conf, conf_file); xu_getatoms(); x_setup(); - xev_loop(); - x_teardown(); return (0); From 6900cd36121062f81f29ec3651aa1ee8807edbe1 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 02:28:45 +0000 Subject: [PATCH 05/21] non-trivial menu drawing rewrite, moving to Xft and solving various font/color drawing issues; from Alexander Polakov --- calmwm.c | 5 ---- calmwm.h | 20 ++++++++----- conf.c | 17 +++++++---- cwmrc.5 | 5 +++- font.c | 34 +++++++++++++++++----- menu.c | 81 +++++++++++++++++++++++++++++++++-------------------- mousefunc.c | 4 +-- parse.y | 23 ++++++++++----- xutil.c | 9 ++++++ 9 files changed, 133 insertions(+), 65 deletions(-) diff --git a/calmwm.c b/calmwm.c index 97a25b1..c699751 100644 --- a/calmwm.c +++ b/calmwm.c @@ -147,11 +147,6 @@ x_setup(void) static void x_teardown(void) { - struct screen_ctx *sc; - - TAILQ_FOREACH(sc, &Screenq, entry) - XFreeGC(X_Dpy, sc->gc); - XCloseDisplay(X_Dpy); } diff --git a/calmwm.h b/calmwm.h index 38c3fee..bd0dbd7 100644 --- a/calmwm.h +++ b/calmwm.h @@ -84,14 +84,19 @@ 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 cwmcolor { CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_INACTIVE, CWM_COLOR_BORDER_GROUP, CWM_COLOR_BORDER_UNGROUP, - CWM_COLOR_FG_MENU, - CWM_COLOR_BG_MENU, - CWM_COLOR_FONT, CWM_COLOR_MAX }; @@ -208,13 +213,12 @@ struct screen_ctx { Window rootwin; Window menuwin; struct color color[CWM_COLOR_MAX]; - GC gc; int cycling; struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ struct gap gap; struct cycle_entry_q mruq; - XftColor xftcolor; + XftColor xftcolor[CWM_COLOR_MENU_MAX]; XftDraw *xftdraw; XftFont *font; int xinerama_no; @@ -289,6 +293,7 @@ struct conf { int snapdist; struct gap gap; struct color color[CWM_COLOR_MAX]; + char *menucolor[CWM_COLOR_MENU_MAX]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; #define CONF_FONT "sans-serif:pixelsize=14:bold" @@ -445,10 +450,10 @@ void conf_ungrab(struct conf *, struct keybinding *); int font_ascent(struct screen_ctx *); int font_descent(struct screen_ctx *); void font_draw(struct screen_ctx *, const char *, int, - Drawable, int, int); + Drawable, int, int, int); u_int font_height(struct screen_ctx *); void font_init(struct screen_ctx *, const char *, - const char *); + const char **); int font_width(struct screen_ctx *, const char *, int); void xev_loop(void); @@ -486,6 +491,7 @@ void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, int); void xu_ewmh_net_wm_desktop(struct client_ctx *); +void xu_xorcolor(XRenderColor, XRenderColor, XRenderColor *); void u_exec(char *); void u_spawn(char *); diff --git a/conf.c b/conf.c index 2fe7363..a42be91 100644 --- a/conf.c +++ b/conf.c @@ -62,17 +62,21 @@ conf_gap(struct conf *c, struct screen_ctx *sc) void conf_font(struct conf *c, struct screen_ctx *sc) { - font_init(sc, c->font, c->color[CWM_COLOR_FONT].name); + font_init(sc, c->font, (const char**)c->menucolor); } -static struct color color_binds[] = { +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 struct color color_binds[CWM_COLOR_MAX] = { { "#CCCCCC", 0 }, /* CWM_COLOR_BORDER_ACTIVE */ { "#666666", 0 }, /* CWM_COLOR_BORDER_INACTIVE */ { "blue", 0 }, /* CWM_COLOR_BORDER_GROUP */ { "red", 0 }, /* CWM_COLOR_BORDER_UNGROUP */ - { "black", 0 }, /* CWM_COLOR_FG_MENU */ - { "white", 0 }, /* CWM_COLOR_BG_MENU */ - { "black", 0 }, /* CWM_COLOR_FONT */ }; void @@ -182,6 +186,9 @@ conf_init(struct conf *c) for (i = 0; i < nitems(color_binds); i++) c->color[i].name = xstrdup(color_binds[i].name); + 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)); diff --git a/cwmrc.5 b/cwmrc.5 index 4e17dbd..c8ea841 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 7 2012 $ +.Dd $Mdocdate: November 29 2012 $ .Dt CWMRC 5 .Os .Sh NAME @@ -112,6 +112,9 @@ Set the color of the active border. .It Ic color font Ar color Set menu font color. .Pp +.It Ic color selfont Ar color +Set font color for selected menu item. +.Pp .It Ic color groupborder Ar color Set the color of the border while grouping a window. .Pp diff --git a/font.c b/font.c index 0e1c144..cbd5b56 100644 --- a/font.c +++ b/font.c @@ -49,20 +49,37 @@ font_height(struct screen_ctx *sc) } void -font_init(struct screen_ctx *sc, const char *name, const char *color) +font_init(struct screen_ctx *sc, const char *name, const char **color) { + int i; + XRenderColor c; + sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which)); if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); - if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which), - DefaultColormap(X_Dpy, sc->which), color, &sc->xftcolor)) - errx(1, "XftColorAllocName"); - sc->font = XftFontOpenName(X_Dpy, sc->which, name); if (sc->font == NULL) errx(1, "XftFontOpenName"); + for(i = 0; i < CWM_COLOR_MENU_MAX; i++) { + if (*color[i] == '\0') + break; + if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which), + DefaultColormap(X_Dpy, sc->which), 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, DefaultVisual(X_Dpy, sc->which), + DefaultColormap(X_Dpy, sc->which), &c, + &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + errx(1, "XftColorAllocValue"); } int @@ -78,9 +95,12 @@ font_width(struct screen_ctx *sc, const char *text, int len) void font_draw(struct screen_ctx *sc, const char *text, int len, - Drawable d, int x, int y) + Drawable d, int active, int x, int y) { + int color; + + color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; XftDrawChange(sc->xftdraw, d); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor, sc->font, x, y, + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->font, x, y, (const FcChar8*)text, len); } diff --git a/menu.c b/menu.c index e2b6e0e..8a0ce26 100644 --- a/menu.c +++ b/menu.c @@ -65,11 +65,13 @@ struct menu_ctx { static struct menu *menu_handle_key(XEvent *, struct menu_ctx *, struct menu_q *, struct menu_q *); static void menu_handle_move(XEvent *, struct menu_ctx *, - struct screen_ctx *); + struct screen_ctx *, struct menu_q *); static struct menu *menu_handle_release(XEvent *, struct menu_ctx *, struct screen_ctx *, struct menu_q *); static void menu_draw(struct screen_ctx *, struct menu_ctx *, struct menu_q *, struct menu_q *); +static void menu_draw_entry(struct screen_ctx *, struct menu_ctx *, + struct menu_q *, int, int); static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *, int, int); static int menu_keycode(XKeyEvent *, enum ctltype *, @@ -78,20 +80,10 @@ static int menu_keycode(XKeyEvent *, enum ctltype *, void menu_init(struct screen_ctx *sc) { - XGCValues gv; - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, Conf.bwidth, - sc->color[CWM_COLOR_FG_MENU].pixel, - sc->color[CWM_COLOR_BG_MENU].pixel); - - gv.foreground = - sc->color[CWM_COLOR_FG_MENU].pixel^sc->color[CWM_COLOR_BG_MENU].pixel; - gv.background = sc->color[CWM_COLOR_BG_MENU].pixel; - gv.function = GXxor; - - sc->gc = XCreateGC(X_Dpy, sc->menuwin, - GCForeground|GCBackground|GCFunction, &gv); + sc->xftcolor[CWM_COLOR_MENU_FG].pixel, + sc->xftcolor[CWM_COLOR_MENU_BG].pixel); } struct menu * @@ -174,7 +166,7 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, menu_draw(sc, &mc, menuq, &resultq); break; case MotionNotify: - menu_handle_move(&e, &mc, sc); + menu_handle_move(&e, &mc, sc, &resultq); break; case ButtonRelease: if ((mi = menu_handle_release(&e, &mc, sc, &resultq)) @@ -442,8 +434,8 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width, mc->height); if (mc->hasprompt) { - font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin, - 0, font_ascent(sc) + 1); + font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin, 0, + 0, font_ascent(sc)); n = 1; } else n = 0; @@ -458,34 +450,61 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, break; font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY), - sc->menuwin, 0, y); + sc->menuwin, 0, 0, y); n++; } - - if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) - XFillRectangle(X_Dpy, sc->menuwin, sc->gc, - 0, font_height(sc), mc->width, font_height(sc)); - - if (mc->noresult) - XFillRectangle(X_Dpy, sc->menuwin, sc->gc, - 0, 0, mc->width, font_height(sc)); + if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { + mc->entry = 1; + menu_draw_entry(sc, mc, resultq, mc->entry, 1); + } } static void -menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc) +menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, + struct menu_q *resultq, int entry, int active) +{ + struct menu *mi; + char *text; + int color, i = 0; + + if (mc->hasprompt) + i = 1; + + TAILQ_FOREACH(mi, resultq, resultentry) + if (entry == i++) + break; + + if (mi == NULL) + return; + color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; + text = mi->print[0] != '\0' ? + mi->print : mi->text; + XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, + font_height(sc) * entry, mc->width, + font_height(sc) + font_descent(sc)); + font_draw(sc, text, strlen(text), sc->menuwin, active, + 0, font_height(sc) * entry + font_ascent(sc) + 1); +} + +static void +menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, + struct menu_q *resultq) { mc->prev = mc->entry; mc->entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y); + if (mc->prev == mc->entry) + return; + if (mc->prev != -1) - XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0, - font_height(sc) * mc->prev, mc->width, font_height(sc)); + menu_draw_entry(sc, mc, resultq, mc->prev, 0); if (mc->entry != -1) { (void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal); - XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0, - font_height(sc) * mc->entry, mc->width, font_height(sc)); + menu_draw_entry(sc, mc, resultq, mc->entry, 1); } else (void)xu_ptr_regrab(MENUGRABMASK, Cursor_default); + if (mc->hasprompt) + menu_draw_entry(sc, mc, resultq, 1, 1); } static struct menu * @@ -519,7 +538,7 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) entry = y / font_height(sc); /* in bounds? */ - if (x <= 0 || x > mc->width || y <= 0 || + if (x < 0 || x > mc->width || y < 0 || y > font_height(sc) * mc->num || entry < 0 || entry >= mc->num) entry = -1; diff --git a/mousefunc.c b/mousefunc.c index d61adca..a342b8e 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -68,9 +68,9 @@ mousefunc_sweep_draw(struct client_ctx *cc) XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, width, font_height(sc) * 2); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, + font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, 0, 2, font_ascent(sc) + 1); - font_draw(sc, asize, strlen(asize), sc->menuwin, + font_draw(sc, asize, strlen(asize), sc->menuwin, 0, width / 2 - width_size / 2, font_height(sc) + font_ascent(sc) + 1); } diff --git a/parse.y b/parse.y index c89c038..b36ee26 100644 --- a/parse.y +++ b/parse.y @@ -73,7 +73,8 @@ typedef struct { %token COLOR SNAPDIST %token ACTIVEBORDER INACTIVEBORDER %token GROUPBORDER UNGROUPBORDER -%token MENUBG MENUFG FONTCOLOR +%token MENUBG MENUFG +%token FONTCOLOR FONTSELCOLOR %token ERROR %token STRING %token NUMBER @@ -186,16 +187,20 @@ colors : ACTIVEBORDER STRING { conf->color[CWM_COLOR_BORDER_UNGROUP].name = $2; } | MENUBG STRING { - free(conf->color[CWM_COLOR_BG_MENU].name); - conf->color[CWM_COLOR_BG_MENU].name = $2; + free(conf->menucolor[CWM_COLOR_MENU_BG]); + conf->menucolor[CWM_COLOR_MENU_BG] = $2; } | MENUFG STRING { - free(conf->color[CWM_COLOR_FG_MENU].name); - conf->color[CWM_COLOR_FG_MENU].name = $2; + free(conf->menucolor[CWM_COLOR_MENU_FG]); + conf->menucolor[CWM_COLOR_MENU_FG] = $2; } | FONTCOLOR STRING { - free(conf->color[CWM_COLOR_FONT].name); - conf->color[CWM_COLOR_FONT].name = $2; + free(conf->menucolor[CWM_COLOR_MENU_FONT]); + conf->menucolor[CWM_COLOR_MENU_FONT] = $2; + } + | FONTSELCOLOR STRING { + free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]); + conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2; } ; %% @@ -247,6 +252,7 @@ lookup(char *s) { "mousebind", MOUSEBIND}, { "moveamount", MOVEAMOUNT}, { "no", NO}, + { "selfont", FONTSELCOLOR}, { "snapdist", SNAPDIST}, { "sticky", STICKY}, { "ungroupborder", UNGROUPBORDER}, @@ -575,6 +581,9 @@ parse_config(const char *filename, struct conf *xconf) for (i = 0; i < CWM_COLOR_MAX; i++) xconf->color[i].name = conf->color[i].name; + 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 9c80dfe..6e80379 100644 --- a/xutil.c +++ b/xutil.c @@ -430,3 +430,12 @@ xu_getcolor(struct screen_ctx *sc, char *name) return (color.pixel); } + +void +xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r) +{ + r->red = a.red ^ b.red; + r->green = a.green ^ b.green; + r->blue = a.blue ^ b.blue; + r->alpha = 0xffff; +} From 96cd288a2a34e90eb617e2225615eeba2ba690fb Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 02:53:29 +0000 Subject: [PATCH 06/21] knf --- calmwm.h | 14 ++++++++------ conf.c | 10 +++++----- font.c | 15 ++++++++------- menu.c | 12 ++++++------ parse.y | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/calmwm.h b/calmwm.h index bd0dbd7..0d3b92a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -317,7 +317,8 @@ __dead void usage(void); void client_applysizehints(struct client_ctx *); struct client_ctx *client_current(void); void client_cycle(struct screen_ctx *, int); -void client_cycle_leave(struct screen_ctx *, struct client_ctx *); +void client_cycle_leave(struct screen_ctx *, + struct client_ctx *); void client_delete(struct client_ctx *); void client_draw_border(struct client_ctx *); struct client_ctx *client_find(Window); @@ -364,8 +365,8 @@ void search_match_client(struct menu_q *, struct menu_q *, char *); void search_match_exec(struct menu_q *, struct menu_q *, char *); -void search_match_exec_path(struct menu_q *, struct menu_q *, - char *); +void search_match_exec_path(struct menu_q *, + struct menu_q *, char *); void search_match_path_any(struct menu_q *, struct menu_q *, char *); void search_match_text(struct menu_q *, struct menu_q *, @@ -475,6 +476,8 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_setstate(struct client_ctx *, int); +void xu_xorcolor(XRenderColor, XRenderColor, + XRenderColor *); void xu_ewmh_net_supported(struct screen_ctx *); void xu_ewmh_net_supported_wm_check(struct screen_ctx *); @@ -487,12 +490,11 @@ void xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *); void xu_ewmh_net_showing_desktop(struct screen_ctx *); void xu_ewmh_net_virtual_roots(struct screen_ctx *); void xu_ewmh_net_current_desktop(struct screen_ctx *, long); -void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, int); +void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, + int); void xu_ewmh_net_wm_desktop(struct client_ctx *); -void xu_xorcolor(XRenderColor, XRenderColor, XRenderColor *); - void u_exec(char *); void u_spawn(char *); diff --git a/conf.c b/conf.c index a42be91..5d4ec23 100644 --- a/conf.c +++ b/conf.c @@ -62,14 +62,14 @@ conf_gap(struct conf *c, struct screen_ctx *sc) void conf_font(struct conf *c, struct screen_ctx *sc) { - font_init(sc, c->font, (const char**)c->menucolor); + font_init(sc, c->font, (const char **)c->menucolor); } 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 */ + "black", /* CWM_COLOR_MENU_FG */ + "white", /* CWM_COLOR_MENU_BG */ + "black", /* CWM_COLOR_MENU_FONT */ + "", /* CWM_COLOR_MENU_FONT_SEL */ }; static struct color color_binds[CWM_COLOR_MAX] = { diff --git a/font.c b/font.c index cbd5b56..fefce3d 100644 --- a/font.c +++ b/font.c @@ -51,8 +51,8 @@ font_height(struct screen_ctx *sc) void font_init(struct screen_ctx *sc, const char *name, const char **color) { - int i; - XRenderColor c; + int i; + XRenderColor c; sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which)); @@ -62,7 +62,8 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) sc->font = XftFontOpenName(X_Dpy, sc->which, name); if (sc->font == NULL) errx(1, "XftFontOpenName"); - for(i = 0; i < CWM_COLOR_MENU_MAX; i++) { + + for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { if (*color[i] == '\0') break; if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which), @@ -74,11 +75,11 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) return; xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color, - sc->xftcolor[CWM_COLOR_MENU_FG].color, &c); + sc->xftcolor[CWM_COLOR_MENU_FG].color, &c); xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c); if (!XftColorAllocValue(X_Dpy, DefaultVisual(X_Dpy, sc->which), - DefaultColormap(X_Dpy, sc->which), &c, - &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + DefaultColormap(X_Dpy, sc->which), &c, + &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) errx(1, "XftColorAllocValue"); } @@ -97,7 +98,7 @@ void font_draw(struct screen_ctx *sc, const char *text, int len, Drawable d, int active, int x, int y) { - int color; + int color; color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; XftDrawChange(sc->xftdraw, d); diff --git a/menu.c b/menu.c index 8a0ce26..dd6de18 100644 --- a/menu.c +++ b/menu.c @@ -473,17 +473,16 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, TAILQ_FOREACH(mi, resultq, resultentry) if (entry == i++) break; - if (mi == NULL) return; + color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; - text = mi->print[0] != '\0' ? - mi->print : mi->text; + text = mi->print[0] != '\0' ? mi->print : mi->text; XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, - font_height(sc) * entry, mc->width, - font_height(sc) + font_descent(sc)); + font_height(sc) * entry, mc->width, + font_height(sc) + font_descent(sc)); font_draw(sc, text, strlen(text), sc->menuwin, active, - 0, font_height(sc) * entry + font_ascent(sc) + 1); + 0, font_height(sc) * entry + font_ascent(sc) + 1); } static void @@ -503,6 +502,7 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, menu_draw_entry(sc, mc, resultq, mc->entry, 1); } else (void)xu_ptr_regrab(MENUGRABMASK, Cursor_default); + if (mc->hasprompt) menu_draw_entry(sc, mc, resultq, 1, 1); } diff --git a/parse.y b/parse.y index b36ee26..2404f4b 100644 --- a/parse.y +++ b/parse.y @@ -582,7 +582,7 @@ parse_config(const char *filename, struct conf *xconf) xconf->color[i].name = conf->color[i].name; for (i = 0; i < CWM_COLOR_MENU_MAX; i++) - xconf->menucolor[i]= conf->menucolor[i]; + xconf->menucolor[i] = conf->menucolor[i]; xconf->font = conf->font; } From 980c6de1ff5e836b831e0cd49fcea5db4792103e Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 14:20:52 +0000 Subject: [PATCH 07/21] screen font -> xftfont --- calmwm.h | 2 +- font.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/calmwm.h b/calmwm.h index 0d3b92a..096a5c4 100644 --- a/calmwm.h +++ b/calmwm.h @@ -220,7 +220,7 @@ struct screen_ctx { struct cycle_entry_q mruq; XftColor xftcolor[CWM_COLOR_MENU_MAX]; XftDraw *xftdraw; - XftFont *font; + XftFont *xftfont; int xinerama_no; XineramaScreenInfo *xinerama; #define CALMWM_NGROUPS 9 diff --git a/font.c b/font.c index fefce3d..6aecf97 100644 --- a/font.c +++ b/font.c @@ -33,19 +33,19 @@ int font_ascent(struct screen_ctx *sc) { - return (sc->font->ascent); + return (sc->xftfont->ascent); } int font_descent(struct screen_ctx *sc) { - return (sc->font->descent); + return (sc->xftfont->descent); } u_int font_height(struct screen_ctx *sc) { - return (sc->font->height + 1); + return (sc->xftfont->height + 1); } void @@ -59,8 +59,8 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); - sc->font = XftFontOpenName(X_Dpy, sc->which, name); - if (sc->font == NULL) + sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name); + if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { @@ -88,7 +88,7 @@ font_width(struct screen_ctx *sc, const char *text, int len) { XGlyphInfo extents; - XftTextExtentsUtf8(X_Dpy, sc->font, (const FcChar8*)text, + XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text, len, &extents); return (extents.xOff); @@ -102,6 +102,6 @@ font_draw(struct screen_ctx *sc, const char *text, int len, color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; XftDrawChange(sc->xftdraw, d); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->font, x, y, + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, (const FcChar8*)text, len); } From d651c1cc3b5b1f4c00cbefd6247083c5f3f0fce5 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 14:26:29 +0000 Subject: [PATCH 08/21] current_client() returns _curcc, so use it where appropriate --- client.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client.c b/client.c index 57f2218..8824f1c 100644 --- a/client.c +++ b/client.c @@ -158,7 +158,7 @@ client_delete(struct client_ctx *cc) xu_ewmh_net_client_list(sc); - if (_curcc == cc) + if (cc == client_current()) client_none(sc); XFree(cc->size); @@ -180,7 +180,7 @@ client_leave(struct client_ctx *cc) struct screen_ctx *sc; if (cc == NULL) - cc = _curcc; + cc = client_current(); if (cc == NULL) return; @@ -194,7 +194,7 @@ client_setactive(struct client_ctx *cc, int fg) struct screen_ctx *sc; if (cc == NULL) - cc = _curcc; + cc = client_current(); if (cc == NULL) return; @@ -214,7 +214,7 @@ client_setactive(struct client_ctx *cc, int fg) } else client_leave(cc); - if (fg && _curcc != cc) { + if (fg && cc != client_current()) { client_setactive(NULL, 0); _curcc = cc; xu_ewmh_net_active_window(sc, cc->win); @@ -480,7 +480,7 @@ client_hide(struct client_ctx *cc) cc->flags |= CLIENT_HIDDEN; xu_setstate(cc, IconicState); - if (cc == _curcc) + if (cc == client_current()) client_none(cc->sc); } @@ -737,7 +737,7 @@ client_mtf(struct client_ctx *cc) struct screen_ctx *sc; if (cc == NULL) - cc = _curcc; + cc = client_current(); if (cc == NULL) return; From 3a3e0383b2b605ede516f4f58eef778bea7815e4 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 14:32:39 +0000 Subject: [PATCH 09/21] create and use menuq_clear() helper; from Tiago Cunha --- calmwm.h | 1 + group.c | 5 +---- kbfunc.c | 20 ++++---------------- menu.c | 16 ++++++++++++---- mousefunc.c | 13 +++---------- 5 files changed, 21 insertions(+), 34 deletions(-) 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); } From 8e67d1389ceb0450712039832e5ff868335c6846 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 14:58:46 +0000 Subject: [PATCH 10/21] make client_mtf static --- calmwm.h | 1 - client.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 35bf6c2..bfef2bd 100644 --- a/calmwm.h +++ b/calmwm.h @@ -331,7 +331,6 @@ void client_lower(struct client_ctx *); void client_map(struct client_ctx *); void client_maximize(struct client_ctx *); void client_move(struct client_ctx *); -void client_mtf(struct client_ctx *); struct client_ctx *client_new(Window, struct screen_ctx *, int); void client_ptrsave(struct client_ctx *); void client_ptrwarp(struct client_ctx *); diff --git a/client.c b/client.c index 8824f1c..3dd6c70 100644 --- a/client.c +++ b/client.c @@ -33,6 +33,7 @@ static struct client_ctx *client_mrunext(struct client_ctx *); static struct client_ctx *client_mruprev(struct client_ctx *); +static void client_mtf(struct client_ctx *); static void client_none(struct screen_ctx *); static void client_placecalc(struct client_ctx *); static void client_update(struct client_ctx *); @@ -731,7 +732,7 @@ client_placecalc(struct client_ctx *cc) } } -void +static void client_mtf(struct client_ctx *cc) { struct screen_ctx *sc; @@ -742,8 +743,6 @@ client_mtf(struct client_ctx *cc) return; sc = cc->sc; - - /* Move to front. */ TAILQ_REMOVE(&sc->mruq, cc, mru_entry); TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry); } From 82e8ec4245f44bd10c0fc5ed27640dafbb7beb44 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 17:48:57 +0000 Subject: [PATCH 11/21] replace client highlight with a client flag --- calmwm.h | 6 +++--- client.c | 7 +++---- group.c | 10 ++++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/calmwm.h b/calmwm.h index bfef2bd..601ca8f 100644 --- a/calmwm.h +++ b/calmwm.h @@ -159,16 +159,16 @@ struct client_ctx { #define CLIENT_VMAXIMIZED 0x0004 #define CLIENT_HMAXIMIZED 0x0008 #define CLIENT_FREEZE 0x0010 +#define CLIENT_GROUP 0x0020 +#define CLIENT_UNGROUP 0x0040 +#define CLIENT_HIGHLIGHT (CLIENT_GROUP | CLIENT_UNGROUP) #define CLIENT_MAXFLAGS (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED) #define CLIENT_MAXIMIZED (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED) int flags; int state; int active; int stackingorder; -#define CLIENT_HIGHLIGHT_GROUP 0x0001 -#define CLIENT_HIGHLIGHT_UNGROUP 0x0002 - int highlight; struct winname_q nameq; #define CLIENT_MAXNAMEQLEN 5 int nameqlen; diff --git a/client.c b/client.c index 3dd6c70..cae9ba4 100644 --- a/client.c +++ b/client.c @@ -490,7 +490,6 @@ client_unhide(struct client_ctx *cc) { XMapRaised(X_Dpy, cc->win); - cc->highlight = 0; cc->flags &= ~CLIENT_HIDDEN; xu_setstate(cc, NormalState); client_draw_border(cc); @@ -503,11 +502,11 @@ client_draw_border(struct client_ctx *cc) unsigned long pixel; if (cc->active) - switch (cc->highlight) { - case CLIENT_HIGHLIGHT_GROUP: + switch (cc->flags & CLIENT_HIGHLIGHT) { + case CLIENT_GROUP: pixel = sc->color[CWM_COLOR_BORDER_GROUP].pixel; break; - case CLIENT_HIGHLIGHT_UNGROUP: + case CLIENT_UNGROUP: pixel = sc->color[CWM_COLOR_BORDER_UNGROUP].pixel; break; default: diff --git a/group.c b/group.c index 1b89825..847cddd 100644 --- a/group.c +++ b/group.c @@ -218,16 +218,14 @@ void group_sticky_toggle_enter(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct group_ctx *gc; - - gc = sc->group_active; + struct group_ctx *gc = sc->group_active; if (gc == cc->group) { group_remove(cc); - cc->highlight = CLIENT_HIGHLIGHT_UNGROUP; + cc->flags |= CLIENT_UNGROUP; } else { group_add(gc, cc); - cc->highlight = CLIENT_HIGHLIGHT_GROUP; + cc->flags |= CLIENT_GROUP; } client_draw_border(cc); @@ -236,7 +234,7 @@ group_sticky_toggle_enter(struct client_ctx *cc) void group_sticky_toggle_exit(struct client_ctx *cc) { - cc->highlight = 0; + cc->flags &= ~CLIENT_HIGHLIGHT; client_draw_border(cc); } From af13c081080574a036565e2fa7c761b6e6233068 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 18:34:06 +0000 Subject: [PATCH 12/21] stash the default screen visual and colormap in screen_ctx --- calmwm.h | 2 ++ font.c | 12 +++++------- screen.c | 2 ++ xutil.c | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/calmwm.h b/calmwm.h index 601ca8f..e54c06b 100644 --- a/calmwm.h +++ b/calmwm.h @@ -210,6 +210,8 @@ TAILQ_HEAD(autogroupwin_q, autogroupwin); struct screen_ctx { TAILQ_ENTRY(screen_ctx) entry; u_int which; + Visual *visual; + Colormap colormap; Window rootwin; Window menuwin; struct color color[CWM_COLOR_MAX]; diff --git a/font.c b/font.c index 6aecf97..44d4666 100644 --- a/font.c +++ b/font.c @@ -55,7 +55,7 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) XRenderColor c; sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, - DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which)); + sc->visual, sc->colormap); if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); @@ -66,9 +66,8 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { if (*color[i] == '\0') break; - if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which), - DefaultColormap(X_Dpy, sc->which), color[i], - &sc->xftcolor[i])) + if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + color[i], &sc->xftcolor[i])) errx(1, "XftColorAllocName"); } if (i == CWM_COLOR_MENU_MAX) @@ -77,9 +76,8 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) 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, DefaultVisual(X_Dpy, sc->which), - DefaultColormap(X_Dpy, sc->which), &c, - &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, + &c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) errx(1, "XftColorAllocValue"); } diff --git a/screen.c b/screen.c index a515adb..9515d91 100644 --- a/screen.c +++ b/screen.c @@ -41,6 +41,8 @@ screen_init(struct screen_ctx *sc, u_int which) u_int nwins, i; sc->which = which; + sc->visual = DefaultVisual(X_Dpy, sc->which); + sc->colormap = DefaultColormap(X_Dpy, sc->which); sc->rootwin = RootWindow(X_Dpy, sc->which); xu_ewmh_net_supported(sc); diff --git a/xutil.c b/xutil.c index 6e80379..b910906 100644 --- a/xutil.c +++ b/xutil.c @@ -422,8 +422,7 @@ xu_getcolor(struct screen_ctx *sc, char *name) { XColor color, tmp; - if (!XAllocNamedColor(X_Dpy, DefaultColormap(X_Dpy, sc->which), - name, &color, &tmp)) { + if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) { warnx("XAllocNamedColor error: '%s'", name); return (0); } From fe44d1dfce326c846fa199d6972ca77649176046 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 18:35:26 +0000 Subject: [PATCH 13/21] cmap -> colormap in client_ctx --- calmwm.h | 2 +- client.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/calmwm.h b/calmwm.h index e54c06b..3f3ad23 100644 --- a/calmwm.h +++ b/calmwm.h @@ -132,7 +132,7 @@ struct client_ctx { struct screen_ctx *sc; Window win; XSizeHints *size; - Colormap cmap; + Colormap colormap; u_int bwidth; /* border width */ struct geom geom, savegeom; struct { diff --git a/client.c b/client.c index cae9ba4..2bdfe28 100644 --- a/client.c +++ b/client.c @@ -92,7 +92,7 @@ client_new(Window win, struct screen_ctx *sc, int mapped) cc->geom.y = wattr.y; cc->geom.w = wattr.width; cc->geom.h = wattr.height; - cc->cmap = wattr.colormap; + cc->colormap = wattr.colormap; if (wattr.map_state != IsViewable) { client_placecalc(cc); @@ -202,7 +202,7 @@ client_setactive(struct client_ctx *cc, int fg) sc = cc->sc; if (fg) { - XInstallColormap(X_Dpy, cc->cmap); + XInstallColormap(X_Dpy, cc->colormap); XSetInputFocus(X_Dpy, cc->win, RevertToPointerRoot, CurrentTime); conf_grab_mouse(cc); From 75f65f399e2cfc0fd73f6ae9f68e60313cfdd7e5 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 23:03:41 +0000 Subject: [PATCH 14/21] pull user home directory via getenv or getpwuid and stash it so we don't need to do this everytime; with Tiago Cunha --- calmwm.c | 11 +++++++++++ calmwm.h | 1 + conf.c | 6 +----- kbfunc.c | 7 ++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/calmwm.c b/calmwm.c index c699751..2c02342 100644 --- a/calmwm.c +++ b/calmwm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq); int HasRandr, Randr_ev; struct conf Conf; +char *homedir; static void sigchld_cb(int); static void dpy_init(const char *); @@ -62,6 +64,7 @@ main(int argc, char **argv) const char *conf_file = NULL; char *display_name = NULL; int ch; + struct passwd *pw; if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) warnx("no locale support"); @@ -86,6 +89,14 @@ main(int argc, char **argv) if (signal(SIGCHLD, sigchld_cb) == SIG_ERR) err(1, "signal"); + if ((homedir = getenv("HOME")) == NULL || *homedir == '\0') { + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0') + homedir = pw->pw_dir; + else + homedir = "/"; + } + dpy_init(display_name); bzero(&Conf, sizeof(Conf)); diff --git a/calmwm.h b/calmwm.h index 3f3ad23..87be644 100644 --- a/calmwm.h +++ b/calmwm.h @@ -519,6 +519,7 @@ extern Cursor Cursor_resize; extern struct screen_ctx_q Screenq; extern struct client_ctx_q Clientq; extern struct conf Conf; +extern char *homedir; extern int HasRandr, Randr_ev; diff --git a/conf.c b/conf.c index 5d4ec23..9bdea9b 100644 --- a/conf.c +++ b/conf.c @@ -243,18 +243,14 @@ void conf_setup(struct conf *c, const char *conf_file) { char conf_path[MAXPATHLEN]; - char *home; struct stat sb; int parse = 0; conf_init(c); if (conf_file == NULL) { - if ((home = getenv("HOME")) == NULL) - errx(1, "No HOME directory."); - (void)snprintf(conf_path, sizeof(conf_path), "%s/%s", - home, CONFFILE); + homedir, CONFFILE); if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG)) parse = 1; diff --git a/kbfunc.c b/kbfunc.c index 023069d..d62867d 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -324,16 +324,13 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) struct menu *mi; struct menu_q menuq; FILE *fp; - char *buf, *lbuf, *p, *home; + char *buf, *lbuf, *p; char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN]; char cmd[256]; int l; size_t len; - if ((home = getenv("HOME")) == NULL) - return; - - l = snprintf(filename, sizeof(filename), "%s/%s", home, KNOWN_HOSTS); + l = snprintf(filename, sizeof(filename), "%s/%s", homedir, KNOWN_HOSTS); if (l == -1 || l >= sizeof(filename)) return; From 479e9f769c5a822da49ec60cd7ceb533e1739527 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 17 Dec 2012 23:54:57 +0000 Subject: [PATCH 15/21] put a default known_hosts into conf --- calmwm.h | 1 + conf.c | 3 +++ kbfunc.c | 11 ++++------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/calmwm.h b/calmwm.h index 87be644..256ce9e 100644 --- a/calmwm.h +++ b/calmwm.h @@ -298,6 +298,7 @@ struct conf { char *menucolor[CWM_COLOR_MENU_MAX]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; + char known_hosts[MAXPATHLEN]; #define CONF_FONT "sans-serif:pixelsize=14:bold" char *font; }; diff --git a/conf.c b/conf.c index 9bdea9b..d1cbbf8 100644 --- a/conf.c +++ b/conf.c @@ -193,6 +193,9 @@ conf_init(struct conf *c) (void)strlcpy(c->termpath, "xterm", sizeof(c->termpath)); (void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath)); + (void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s", + homedir, ".ssh/known_hosts"); + c->font = xstrdup(CONF_FONT); } diff --git a/kbfunc.c b/kbfunc.c index d62867d..452ca0a 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -33,7 +33,6 @@ #include "calmwm.h" -#define KNOWN_HOSTS ".ssh/known_hosts" #define HASH_MARKER "|1|" extern char **cwm_argv; @@ -325,17 +324,15 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) struct menu_q menuq; FILE *fp; char *buf, *lbuf, *p; - char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN]; + char hostbuf[MAXHOSTNAMELEN]; char cmd[256]; int l; size_t len; - l = snprintf(filename, sizeof(filename), "%s/%s", homedir, KNOWN_HOSTS); - if (l == -1 || l >= sizeof(filename)) - return; - - if ((fp = fopen(filename, "r")) == NULL) + if ((fp = fopen(Conf.known_hosts, "r")) == NULL) { + warn("kbfunc_ssh: %s", Conf.known_hosts); return; + } TAILQ_INIT(&menuq); lbuf = NULL; From b848a2b236424a33d0fcf1f07e3b4473a56604ff Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Dec 2012 00:14:41 +0000 Subject: [PATCH 16/21] simplify config file setup; with Tiago Cunha --- calmwm.c | 21 ++++++++++++++++++--- calmwm.h | 1 - conf.c | 31 ++----------------------------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/calmwm.c b/calmwm.c index 2c02342..25ac559 100644 --- a/calmwm.c +++ b/calmwm.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) { const char *conf_file = NULL; - char *display_name = NULL; + char *conf_path, *display_name = NULL; int ch; struct passwd *pw; @@ -97,10 +97,25 @@ main(int argc, char **argv) homedir = "/"; } + if (conf_file == NULL) + xasprintf(&conf_path, "%s/%s", homedir, CONFFILE); + else + conf_path = xstrdup(conf_file); + + if (access(conf_path, R_OK) != 0) { + if (conf_file != NULL) + warn("%s", conf_file); + free(conf_path); + conf_path = NULL; + } + dpy_init(display_name); - bzero(&Conf, sizeof(Conf)); - conf_setup(&Conf, conf_file); + conf_init(&Conf); + if (conf_path && (parse_config(conf_path, &Conf) == -1)) + warnx("config file %s has errors, not loading", conf_path); + free(conf_path); + xu_getatoms(); x_setup(); xev_loop(); diff --git a/calmwm.h b/calmwm.h index 256ce9e..3d44e9b 100644 --- a/calmwm.h +++ b/calmwm.h @@ -448,7 +448,6 @@ void conf_grab(struct conf *, struct keybinding *); void conf_grab_mouse(struct client_ctx *); void conf_init(struct conf *); void conf_mousebind(struct conf *, char *, char *); -void conf_setup(struct conf *, const char *); void conf_ungrab(struct conf *, struct keybinding *); int font_ascent(struct screen_ctx *); diff --git a/conf.c b/conf.c index d1cbbf8..19a7a6d 100644 --- a/conf.c +++ b/conf.c @@ -166,7 +166,8 @@ conf_init(struct conf *c) { int i; - c->flags = 0; + bzero(c, sizeof(*c)); + c->bwidth = CONF_BWIDTH; c->mamount = CONF_MAMOUNT; c->snapdist = CONF_SNAPDIST; @@ -242,34 +243,6 @@ conf_clear(struct conf *c) free(c->font); } -void -conf_setup(struct conf *c, const char *conf_file) -{ - char conf_path[MAXPATHLEN]; - struct stat sb; - int parse = 0; - - conf_init(c); - - if (conf_file == NULL) { - (void)snprintf(conf_path, sizeof(conf_path), "%s/%s", - homedir, CONFFILE); - - if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG)) - parse = 1; - } else { - if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG)) - errx(1, "%s: %s", conf_file, strerror(errno)); - else { - (void)strlcpy(conf_path, conf_file, sizeof(conf_path)); - parse = 1; - } - } - - if (parse && (parse_config(conf_path, c) == -1)) - warnx("config file %s has errors, not loading", conf_path); -} - void conf_client(struct client_ctx *cc) { From e5d59c2d7b9934445c060b03a1f3c99246d65b93 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Dec 2012 17:37:39 +0000 Subject: [PATCH 17/21] define LockMask|Mod2Mask; no functional change --- calmwm.h | 1 + xevents.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 3d44e9b..8ea091a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -53,6 +53,7 @@ #define MENUGRABMASK (BUTTONMASK|ButtonMotionMask|StructureNotifyMask|\ PointerMotionMask) #define SEARCHMASK (KeyPressMask|ExposureMask) +#define IGNOREMODMASK (LockMask|Mod2Mask) /* kb movement */ #define CWM_MOVE 0x0001 diff --git a/xevents.c b/xevents.c index e167189..421a1b7 100644 --- a/xevents.c +++ b/xevents.c @@ -241,8 +241,7 @@ xev_handle_buttonpress(XEvent *ee) sc = screen_fromroot(e->root); cc = client_find(e->window); - /* Ignore caps lock and numlock */ - e->state &= ~(Mod2Mask | LockMask); + e->state &= ~IGNOREMODMASK; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (e->button == mb->button && e->state == mb->modmask) @@ -283,8 +282,7 @@ xev_handle_keypress(XEvent *ee) keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); skeysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 1); - /* we don't care about caps lock and numlock here */ - e->state &= ~(LockMask | Mod2Mask); + e->state &= ~IGNOREMODMASK; TAILQ_FOREACH(kb, &Conf.keybindingq, entry) { if (keysym != kb->keysym && skeysym == kb->keysym) From 31e9fe4dcdc59eb5ff74e69f9e674a74905f27bf Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Dec 2012 17:44:18 +0000 Subject: [PATCH 18/21] remove unused SEARCHMASK --- calmwm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index 8ea091a..1722eba 100644 --- a/calmwm.h +++ b/calmwm.h @@ -52,7 +52,6 @@ PointerMotionMask) #define MENUGRABMASK (BUTTONMASK|ButtonMotionMask|StructureNotifyMask|\ PointerMotionMask) -#define SEARCHMASK (KeyPressMask|ExposureMask) #define IGNOREMODMASK (LockMask|Mod2Mask) /* kb movement */ From 86eaf5e973a19f2edb9b7c2921363b7a70413049 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Dec 2012 18:35:36 +0000 Subject: [PATCH 19/21] use MOUSEMASK since we already have it --- calmwm.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 1722eba..2f20ab4 100644 --- a/calmwm.h +++ b/calmwm.h @@ -47,11 +47,9 @@ #define CHILDMASK (SubstructureRedirectMask|SubstructureNotifyMask) #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) +#define MENUMASK (MOUSEMASK|ButtonMotionMask|ExposureMask) +#define MENUGRABMASK (MOUSEMASK|ButtonMotionMask|StructureNotifyMask) #define KEYMASK (KeyPressMask|ExposureMask) -#define MENUMASK (BUTTONMASK|ButtonMotionMask|ExposureMask| \ - PointerMotionMask) -#define MENUGRABMASK (BUTTONMASK|ButtonMotionMask|StructureNotifyMask|\ - PointerMotionMask) #define IGNOREMODMASK (LockMask|Mod2Mask) /* kb movement */ From c565b790eda26074619aaf7c29234b6975862056 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Dec 2012 18:39:55 +0000 Subject: [PATCH 20/21] expand CHILDMASK --- calmwm.h | 1 - screen.c | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/calmwm.h b/calmwm.h index 2f20ab4..fc33829 100644 --- a/calmwm.h +++ b/calmwm.h @@ -44,7 +44,6 @@ #define CONFFILE ".cwmrc" #define WMNAME "CWM" -#define CHILDMASK (SubstructureRedirectMask|SubstructureNotifyMask) #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define MENUMASK (MOUSEMASK|ButtonMotionMask|ExposureMask) diff --git a/screen.c b/screen.c index 9515d91..461d308 100644 --- a/screen.c +++ b/screen.c @@ -62,8 +62,9 @@ screen_init(struct screen_ctx *sc, u_int which) menu_init(sc); rootattr.cursor = Cursor_normal; - rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask| - LeaveWindowMask|ColormapChangeMask|BUTTONMASK; + rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask| + PropertyChangeMask|EnterWindowMask|LeaveWindowMask| + ColormapChangeMask|BUTTONMASK; XChangeWindowAttributes(X_Dpy, sc->rootwin, CWEventMask|CWCursor, &rootattr); From dc1e3a88438dc732349154bca610dbe813d2fc04 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 19 Dec 2012 15:21:34 +0000 Subject: [PATCH 21/21] gc unused cmd 'flags' variable --- calmwm.h | 3 +-- conf.c | 3 +-- parse.y | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/calmwm.h b/calmwm.h index fc33829..edac516 100644 --- a/calmwm.h +++ b/calmwm.h @@ -257,7 +257,6 @@ TAILQ_HEAD(mousebinding_q, mousebinding); struct cmd { TAILQ_ENTRY(cmd) entry; - int flags; char image[MAXPATHLEN]; #define CMD_MAXLABELLEN 256 char label[CMD_MAXLABELLEN]; @@ -437,7 +436,7 @@ int parse_config(const char *, struct conf *); void conf_bindname(struct conf *, char *, char *); void conf_clear(struct conf *); void conf_client(struct client_ctx *); -void conf_cmd_add(struct conf *, char *, char *, int); +void conf_cmd_add(struct conf *, char *, char *); void conf_color(struct conf *, struct screen_ctx *); void conf_font(struct conf *, struct screen_ctx *); void conf_gap(struct conf *, struct screen_ctx *); diff --git a/conf.c b/conf.c index 19a7a6d..2541f81 100644 --- a/conf.c +++ b/conf.c @@ -36,7 +36,7 @@ static void conf_unbind(struct conf *, struct keybinding *); /* Add an command menu entry to the end of the menu */ void -conf_cmd_add(struct conf *c, char *image, char *label, int flags) +conf_cmd_add(struct conf *c, char *image, char *label) { /* "term" and "lock" have special meanings. */ @@ -46,7 +46,6 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags) (void)strlcpy(c->lockpath, image, sizeof(c->lockpath)); else { struct cmd *cmd = xmalloc(sizeof(*cmd)); - cmd->flags = flags; (void)strlcpy(cmd->image, image, sizeof(cmd->image)); (void)strlcpy(cmd->label, label, sizeof(cmd->label)); TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry); diff --git a/parse.y b/parse.y index 2404f4b..4f00198 100644 --- a/parse.y +++ b/parse.y @@ -126,7 +126,7 @@ main : FONTNAME STRING { conf->snapdist = $2; } | COMMAND STRING string { - conf_cmd_add(conf, $3, $2, 0); + conf_cmd_add(conf, $3, $2); free($2); free($3); }