From 9cf31746965729f6ea8289849f08fe7a8b825555 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 20 Sep 2016 18:21:32 +0000 Subject: [PATCH 01/34] Get rid of curcc, instead cycle through the queue; removes the need for client_none(). --- Makefile | 2 +- client.c | 32 ++++++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index f00441b..879ccdf 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} -CFLAGS+= -Wall +CFLAGS+= -Wall -g LDADD+= -L${X11BASE}/lib -lXft -lXrender -lX11 -lxcb -lXau -lXdmcp \ -lfontconfig -lexpat -lfreetype -lz -lXrandr -lXext diff --git a/client.c b/client.c index d42391b..8ccf033 100644 --- a/client.c +++ b/client.c @@ -34,14 +34,11 @@ static struct client_ctx *client_next(struct client_ctx *); static struct client_ctx *client_prev(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_wm_protocols(struct client_ctx *); static void client_mwm_hints(struct client_ctx *); static int client_inbound(struct client_ctx *, int, int); -struct client_ctx *curcc = NULL; - struct client_ctx * client_init(Window win, struct screen_ctx *sc, int active) { @@ -178,7 +175,7 @@ client_delete(struct client_ctx *cc) xu_ewmh_net_client_list_stacking(sc); if (cc->flags & CLIENT_ACTIVE) - client_none(sc); + xu_ewmh_net_active_window(sc, None); if (cc->gc != NULL) TAILQ_REMOVE(&cc->gc->clientq, cc, group_entry); @@ -227,7 +224,6 @@ client_setactive(struct client_ctx *cc) if (!sc->cycling) client_mtf(cc); - curcc = cc; cc->flags |= CLIENT_ACTIVE; cc->flags &= ~CLIENT_URGENCY; client_draw_border(cc); @@ -235,23 +231,19 @@ client_setactive(struct client_ctx *cc) xu_ewmh_net_active_window(sc, cc->win); } -/* - * set when there is no active client - */ -static void -client_none(struct screen_ctx *sc) -{ - Window none = None; - - xu_ewmh_net_active_window(sc, none); - - curcc = NULL; -} - struct client_ctx * client_current(void) { - return(curcc); + struct screen_ctx *sc; + struct client_ctx *cc; + + TAILQ_FOREACH(sc, &Screenq, entry) { + TAILQ_FOREACH(cc, &sc->clientq, entry) { + if (cc->flags & CLIENT_ACTIVE) + return(cc); + } + } + return(NULL); } void @@ -512,7 +504,7 @@ client_hide(struct client_ctx *cc) XUnmapWindow(X_Dpy, cc->win); if (cc->flags & CLIENT_ACTIVE) - client_none(cc->sc); + xu_ewmh_net_active_window(cc->sc, None); cc->flags &= ~CLIENT_ACTIVE; cc->flags |= CLIENT_HIDDEN; From 74e4a3c60b75db4687d1032cc3d95709ccd4fb90 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 20 Sep 2016 18:23:12 +0000 Subject: [PATCH 02/34] remove debug that accidentally snuck in --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 879ccdf..f00441b 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} -CFLAGS+= -Wall -g +CFLAGS+= -Wall LDADD+= -L${X11BASE}/lib -lXft -lXrender -lX11 -lxcb -lXau -lXdmcp \ -lfontconfig -lexpat -lfreetype -lz -lXrandr -lXext From 08631748fdd4abfdb90c6f57acb273e066bef1f4 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 20 Sep 2016 19:11:19 +0000 Subject: [PATCH 03/34] de-static client_inbound() --- calmwm.h | 1 + client.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/calmwm.h b/calmwm.h index c6d9ca7..60989c9 100644 --- a/calmwm.h +++ b/calmwm.h @@ -398,6 +398,7 @@ void client_lower(struct client_ctx *); void client_map(struct client_ctx *); void client_msg(struct client_ctx *, Atom, Time); void client_move(struct client_ctx *); +int client_inbound(struct client_ctx *, int, int); struct client_ctx *client_init(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 8ccf033..9fb097a 100644 --- a/client.c +++ b/client.c @@ -37,7 +37,6 @@ static void client_mtf(struct client_ctx *); static void client_placecalc(struct client_ctx *); static void client_wm_protocols(struct client_ctx *); static void client_mwm_hints(struct client_ctx *); -static int client_inbound(struct client_ctx *, int, int); struct client_ctx * client_init(Window win, struct screen_ctx *sc, int active) @@ -917,7 +916,7 @@ client_transient(struct client_ctx *cc) } } -static int +int client_inbound(struct client_ctx *cc, int x, int y) { return(x < cc->geom.w && x >= 0 && From 3947f1268ab4ba15af8f4eeea6224628188a7f5f Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 20 Sep 2016 19:58:54 +0000 Subject: [PATCH 04/34] Allow ctrl-[ for abort (esc); from Benjamin Scher Purcell --- menu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/menu.c b/menu.c index d9eac91..5c91ce1 100644 --- a/menu.c +++ b/menu.c @@ -565,6 +565,9 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) case XK_A: *ctl = CTL_ALL; break; + case XK_bracketleft: + *ctl = CTL_ABORT; + break; } } From 57b2a6cf796614df4723cc5ffff12101a21e7850 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 22 Sep 2016 14:36:03 +0000 Subject: [PATCH 05/34] Continue merging kb and mouse functions: fold mousefunc_menu_{client,cmd,group} into the respective kbfunc_menu_{client,cmd,group} functions; simply pass a flag down from config denoting mouse action behaviour. --- calmwm.h | 4 --- conf.c | 9 ++++--- kbfunc.c | 29 +++++++++++++++----- mousefunc.c | 77 ----------------------------------------------------- 4 files changed, 28 insertions(+), 91 deletions(-) diff --git a/calmwm.h b/calmwm.h index 60989c9..44084ea 100644 --- a/calmwm.h +++ b/calmwm.h @@ -508,10 +508,6 @@ void mousefunc_client_move(struct client_ctx *, union arg *); void mousefunc_client_resize(struct client_ctx *, union arg *); -void mousefunc_menu_client(struct client_ctx *, - union arg *); -void mousefunc_menu_cmd(struct client_ctx *, union arg *); -void mousefunc_menu_group(struct client_ctx *, union arg *); struct menu *menu_filter(struct screen_ctx *, struct menu_q *, const char *, const char *, int, diff --git a/conf.c b/conf.c index 7d7026d..7f7300e 100644 --- a/conf.c +++ b/conf.c @@ -485,9 +485,12 @@ static const struct { { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} }, { "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {.i = CWM_MOUSE} }, - { "menu_group", mousefunc_menu_group, CWM_CONTEXT_SCREEN, {0} }, - { "menu_unhide", mousefunc_menu_client, CWM_CONTEXT_SCREEN, {0} }, - { "menu_cmd", mousefunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} }, + { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, + {.i = CWM_MOUSE} }, + { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, + {.i = CWM_MOUSE} }, + { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, + {.i = CWM_MOUSE} }, }; static const struct { diff --git a/kbfunc.c b/kbfunc.c index fdb8e4b..efcfd3c 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -167,14 +167,22 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg) struct client_ctx *old_cc; struct menu *mi; struct menu_q menuq; + int m = (arg->i == CWM_MOUSE); old_cc = client_current(); TAILQ_INIT(&menuq); - TAILQ_FOREACH(cc, &sc->clientq, entry) - menuq_add(&menuq, cc, NULL); + TAILQ_FOREACH(cc, &sc->clientq, entry) { + if (m) { + if (cc->flags & CLIENT_HIDDEN) + menuq_add(&menuq, cc, NULL); + } else + menuq_add(&menuq, cc, NULL); + } - if ((mi = menu_filter(sc, &menuq, "window", NULL, 0, + if ((mi = menu_filter(sc, &menuq, + (m) ? NULL : "window", NULL, + (m) ? CWM_MENU_LIST : 0, search_match_client, search_print_client)) != NULL) { cc = (struct client_ctx *)mi->ctx; if (cc->flags & CLIENT_HIDDEN) @@ -194,6 +202,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) struct cmd *cmd; struct menu *mi; struct menu_q menuq; + int m = (arg->i == CWM_MOUSE); TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { @@ -204,9 +213,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) menuq_add(&menuq, cmd, "%s", cmd->name); } - if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, - search_match_text, search_print_cmd)) != NULL) - u_spawn(((struct cmd *)mi->ctx)->path); + if ((mi = menu_filter(sc, &menuq, + (m) ? NULL : "application", NULL, + (m) ? CWM_MENU_LIST : 0, + search_match_text, search_print_cmd)) != NULL) { + cmd = (struct cmd *)mi->ctx; + u_spawn(cmd->path); + } menuq_clear(&menuq); } @@ -218,6 +231,7 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg) struct group_ctx *gc; struct menu *mi; struct menu_q menuq; + int m = (arg->i == CWM_MOUSE); TAILQ_INIT(&menuq); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -226,7 +240,8 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg) menuq_add(&menuq, gc, "%d %s", gc->num, gc->name); } - if ((mi = menu_filter(sc, &menuq, "group", NULL, CWM_MENU_LIST, + if ((mi = menu_filter(sc, &menuq, + (m) ? NULL : "group", NULL, CWM_MENU_LIST, search_match_text, search_print_group)) != NULL) { gc = (struct group_ctx *)mi->ctx; (group_holds_only_hidden(gc)) ? diff --git a/mousefunc.c b/mousefunc.c index 36f9460..23f2490 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -155,80 +155,3 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) } /* NOTREACHED */ } - -void -mousefunc_menu_group(struct client_ctx *cc, union arg *arg) -{ - struct screen_ctx *sc = cc->sc; - struct group_ctx *gc; - struct menu *mi; - struct menu_q menuq; - - TAILQ_INIT(&menuq); - TAILQ_FOREACH(gc, &sc->groupq, entry) { - if (group_holds_only_sticky(gc)) - continue; - menuq_add(&menuq, gc, "%d %s", gc->num, gc->name); - } - - if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, - NULL, search_print_group)) != NULL) { - gc = (struct group_ctx *)mi->ctx; - (group_holds_only_hidden(gc)) ? - group_show(gc) : group_hide(gc); - } - - menuq_clear(&menuq); -} - -void -mousefunc_menu_client(struct client_ctx *cc, union arg *arg) -{ - struct screen_ctx *sc = cc->sc; - struct client_ctx *old_cc; - struct menu *mi; - struct menu_q menuq; - - old_cc = client_current(); - - TAILQ_INIT(&menuq); - TAILQ_FOREACH(cc, &sc->clientq, entry) { - if (cc->flags & CLIENT_HIDDEN) { - menuq_add(&menuq, cc, NULL); - } - } - - if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, - NULL, search_print_client)) != NULL) { - cc = (struct client_ctx *)mi->ctx; - client_unhide(cc); - if (old_cc != NULL) - client_ptrsave(old_cc); - client_ptrwarp(cc); - } - - menuq_clear(&menuq); -} - -void -mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg) -{ - struct screen_ctx *sc = cc->sc; - struct cmd *cmd; - struct menu *mi; - struct menu_q menuq; - - TAILQ_INIT(&menuq); - TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { - if ((strcmp(cmd->name, "lock") == 0) || - (strcmp(cmd->name, "term") == 0)) - continue; - menuq_add(&menuq, cmd, NULL); - } - - if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, - NULL, search_print_cmd)) != NULL) - u_spawn(((struct cmd *)mi->ctx)->path); - - menuq_clear(&menuq); -} From b32989d3793bf0247cd517bf232799f12b5652ab Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 28 Sep 2016 15:54:54 +0000 Subject: [PATCH 06/34] Do not call sweep_draw() too early: don't yet have w/h dimensions; plus we will get a MotionNotify event right away anyway, setting required parameters. --- mousefunc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mousefunc.c b/mousefunc.c index 23f2490..42b7fb1 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -68,7 +68,6 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) return; xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); - mousefunc_sweep_draw(cc); for (;;) { XMaskEvent(X_Dpy, MOUSEMASK, &ev); From 92b81d3df5d28e86e849a414eb9bc6cebe0c5f3f Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 28 Sep 2016 17:06:33 +0000 Subject: [PATCH 07/34] Inline Xft draw and extents wrappers; too much abstraction. --- calmwm.h | 3 --- menu.c | 32 +++++++++++++++++++++++--------- mousefunc.c | 10 ++++++++-- xutil.c | 18 ------------------ 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/calmwm.h b/calmwm.h index 44084ea..fd0b864 100644 --- a/calmwm.h +++ b/calmwm.h @@ -549,9 +549,6 @@ int xu_ptr_grab(Window, unsigned int, Cursor); int xu_ptr_regrab(unsigned int, Cursor); void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); -void xu_xft_draw(struct screen_ctx *, const char *, - int, int, int); -int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); diff --git a/menu.c b/menu.c index 5c91ce1..5aefe18 100644 --- a/menu.c +++ b/menu.c @@ -334,6 +334,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) struct menu *mi; struct geom area; int n, xsave, ysave; + XGlyphInfo extents; if (mc->list) { if (TAILQ_EMPTY(resultq)) { @@ -352,8 +353,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); - mc->geom.w = xu_xft_width(sc->xftfont, mc->dispstr, - strlen(mc->dispstr)); + + XftTextExtentsUtf8(X_Dpy, sc->xftfont, + (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents); + + mc->geom.w = extents.xOff; mc->geom.h = sc->xftfont->height + 1; mc->num = 1; } @@ -365,8 +369,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) (void)snprintf(mi->print, sizeof(mi->print), "%s", mi->text); - mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont, - mi->print, MIN(strlen(mi->print), MENU_MAXENTRY))); + XftTextExtentsUtf8(X_Dpy, sc->xftfont, + (const FcChar8*)mi->print, + MIN(strlen(mi->print), MENU_MAXENTRY), &extents); + + mc->geom.w = MAX(mc->geom.w, extents.xOff); mc->geom.h += sc->xftfont->height + 1; mc->num++; } @@ -400,8 +407,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->geom.w, mc->geom.h); if (mc->hasprompt) { - xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT, - 0, sc->xftfont->ascent); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, + 0, sc->xftfont->ascent, + (const FcChar8*)mc->dispstr, strlen(mc->dispstr)); n = 1; } else n = 0; @@ -413,7 +422,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->geom.y + y > area.h) break; - xu_xft_draw(sc, mi->print, CWM_COLOR_MENU_FONT, 0, y); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, + 0, y, + (const FcChar8*)mi->print, strlen(mi->print)); n++; } if (mc->hasprompt && n > 1) @@ -442,8 +454,10 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, (sc->xftfont->height + 1) * entry, mc->geom.w, (sc->xftfont->height + 1) + sc->xftfont->descent); color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - xu_xft_draw(sc, mi->print, color, - 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[color], sc->xftfont, + 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1, + (const FcChar8*)mi->print, strlen(mi->print)); } static void diff --git a/mousefunc.c b/mousefunc.c index 42b7fb1..3366bf1 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -39,16 +39,22 @@ mousefunc_sweep_draw(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; char s[14]; /* fits " nnnn x nnnn \0" */ + XGlyphInfo extents; (void)snprintf(s, sizeof(s), " %4d x %-4d ", cc->dim.w, cc->dim.h); + XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)s, + strlen(s), &extents); + XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, - xu_xft_width(sc->xftfont, s, strlen(s)), sc->xftfont->height); + extents.xOff, sc->xftfont->height); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - xu_xft_draw(sc, s, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], + sc->xftfont, 0, sc->xftfont->ascent + 1, + (const FcChar8*)s, strlen(s)); } void diff --git a/xutil.c b/xutil.c index eaaa0a4..39639ef 100644 --- a/xutil.c +++ b/xutil.c @@ -531,21 +531,3 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r) r->color.blue = a.color.blue ^ b.color.blue; r->color.alpha = 0xffff; } - -int -xu_xft_width(XftFont *xftfont, const char *text, int len) -{ - XGlyphInfo extents; - - XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, - len, &extents); - - return(extents.xOff); -} - -void -xu_xft_draw(struct screen_ctx *sc, const char *text, int color, int x, int y) -{ - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, - x, y, (const FcChar8*)text, strlen(text)); -} From 0e8c7066333ffd331743658e82cfedaf3e0078a2 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Sep 2016 00:21:55 +0000 Subject: [PATCH 08/34] Mechanical change: move screen menu bits to their own struct. --- calmwm.c | 6 +++--- calmwm.h | 6 ++++-- conf.c | 6 +++--- menu.c | 30 +++++++++++++++--------------- mousefunc.c | 14 +++++++------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/calmwm.c b/calmwm.c index 9166485..afb5e6d 100644 --- a/calmwm.c +++ b/calmwm.c @@ -161,10 +161,10 @@ x_teardown(void) XftColorFree(X_Dpy, DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which), &sc->xftcolor[i]); - XftDrawDestroy(sc->xftdraw); + XftDrawDestroy(sc->menu.xftdraw); XftFontClose(X_Dpy, sc->xftfont); - XUnmapWindow(X_Dpy, sc->menuwin); - XDestroyWindow(X_Dpy, sc->menuwin); + XUnmapWindow(X_Dpy, sc->menu.win); + XDestroyWindow(X_Dpy, sc->menu.win); XUngrabKey(X_Dpy, AnyKey, AnyModifier, sc->rootwin); } XUngrabPointer(X_Dpy, CurrentTime); diff --git a/calmwm.h b/calmwm.h index fd0b864..97fa0ed 100644 --- a/calmwm.h +++ b/calmwm.h @@ -228,7 +228,6 @@ struct screen_ctx { TAILQ_ENTRY(screen_ctx) entry; int which; Window rootwin; - Window menuwin; int cycling; int hideall; int snapdist; @@ -240,8 +239,11 @@ struct screen_ctx { #define CALMWM_NGROUPS 10 struct group_ctx_q groupq; struct group_ctx *group_active; + struct { + Window win; + XftDraw *xftdraw; + } menu; XftColor xftcolor[CWM_COLOR_NITEMS]; - XftDraw *xftdraw; XftFont *xftfont; }; TAILQ_HEAD(screen_ctx_q, screen_ctx); diff --git a/conf.c b/conf.c index 7f7300e..c0c7b41 100644 --- a/conf.c +++ b/conf.c @@ -162,13 +162,13 @@ conf_screen(struct screen_ctx *sc) } } - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, + sc->menu.win = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, Conf.bwidth, sc->xftcolor[CWM_COLOR_MENU_FG].pixel, sc->xftcolor[CWM_COLOR_MENU_BG].pixel); - sc->xftdraw = XftDrawCreate(X_Dpy, sc->menuwin, visual, colormap); - if (sc->xftdraw == NULL) + sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win, visual, colormap); + if (sc->menu.xftdraw == NULL) errx(1, "XftDrawCreate"); conf_grab_kbd(sc->rootwin); diff --git a/menu.c b/menu.c index 5aefe18..a84f578 100644 --- a/menu.c +++ b/menu.c @@ -118,26 +118,26 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt, mc.hasprompt = 1; } - XSelectInput(X_Dpy, sc->menuwin, evmask); - XMapRaised(X_Dpy, sc->menuwin); + XSelectInput(X_Dpy, sc->menu.win, evmask); + XMapRaised(X_Dpy, sc->menu.win); - if (xu_ptr_grab(sc->menuwin, MENUGRABMASK, + if (xu_ptr_grab(sc->menu.win, MENUGRABMASK, Conf.cursor[CF_QUESTION]) < 0) { - XUnmapWindow(X_Dpy, sc->menuwin); + XUnmapWindow(X_Dpy, sc->menu.win); return(NULL); } XGetInputFocus(X_Dpy, &focuswin, &focusrevert); - XSetInputFocus(X_Dpy, sc->menuwin, RevertToPointerRoot, CurrentTime); + XSetInputFocus(X_Dpy, sc->menu.win, RevertToPointerRoot, CurrentTime); /* make sure keybindings don't remove keys from the menu stream */ - XGrabKeyboard(X_Dpy, sc->menuwin, True, + XGrabKeyboard(X_Dpy, sc->menu.win, True, GrabModeAsync, GrabModeAsync, CurrentTime); for (;;) { mc.changed = 0; - XWindowEvent(X_Dpy, sc->menuwin, evmask, &e); + XWindowEvent(X_Dpy, sc->menu.win, evmask, &e); switch (e.type) { case KeyPress: @@ -174,8 +174,8 @@ out: xu_ptr_setpos(sc->rootwin, xsave, ysave); xu_ptr_ungrab(); - XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, 1, 1); - XUnmapWindow(X_Dpy, sc->menuwin); + XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, 1, 1); + XUnmapWindow(X_Dpy, sc->menu.win); XUngrabKeyboard(X_Dpy, CurrentTime); return(mi); @@ -402,12 +402,12 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->geom.x != xsave || mc->geom.y != ysave) xu_ptr_setpos(sc->rootwin, mc->geom.x, mc->geom.y); - XClearWindow(X_Dpy, sc->menuwin); - XMoveResizeWindow(X_Dpy, sc->menuwin, mc->geom.x, mc->geom.y, + XClearWindow(X_Dpy, sc->menu.win); + XMoveResizeWindow(X_Dpy, sc->menu.win, mc->geom.x, mc->geom.y, mc->geom.w, mc->geom.h); if (mc->hasprompt) { - XftDrawStringUtf8(sc->xftdraw, + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, 0, sc->xftfont->ascent, (const FcChar8*)mc->dispstr, strlen(mc->dispstr)); @@ -422,7 +422,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->geom.y + y > area.h) break; - XftDrawStringUtf8(sc->xftdraw, + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, 0, y, (const FcChar8*)mi->print, strlen(mi->print)); @@ -450,11 +450,11 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, return; color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; - XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, + XftDrawRect(sc->menu.xftdraw, &sc->xftcolor[color], 0, (sc->xftfont->height + 1) * entry, mc->geom.w, (sc->xftfont->height + 1) + sc->xftfont->descent); color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - XftDrawStringUtf8(sc->xftdraw, + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[color], sc->xftfont, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1, (const FcChar8*)mi->print, strlen(mi->print)); diff --git a/mousefunc.c b/mousefunc.c index 3366bf1..5b795cc 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -46,13 +46,13 @@ mousefunc_sweep_draw(struct client_ctx *cc) XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)s, strlen(s), &extents); - XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); - XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, + XReparentWindow(X_Dpy, sc->menu.win, cc->win, 0, 0); + XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, extents.xOff, sc->xftfont->height); - XMapWindow(X_Dpy, sc->menuwin); - XClearWindow(X_Dpy, sc->menuwin); + XMapWindow(X_Dpy, sc->menu.win); + XClearWindow(X_Dpy, sc->menu.win); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, 0, sc->xftfont->ascent + 1, (const FcChar8*)s, strlen(s)); } @@ -93,8 +93,8 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) break; case ButtonRelease: client_resize(cc, 1); - XUnmapWindow(X_Dpy, sc->menuwin); - XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0); + XUnmapWindow(X_Dpy, sc->menu.win); + XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); xu_ptr_ungrab(); /* Make sure the pointer stays within the window. */ From 24d6348e52c0732e1c2564eceeae8159a47d9bb7 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 29 Sep 2016 00:30:40 +0000 Subject: [PATCH 09/34] no need to unmap menu window again --- calmwm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/calmwm.c b/calmwm.c index afb5e6d..a6c5bc4 100644 --- a/calmwm.c +++ b/calmwm.c @@ -161,9 +161,8 @@ x_teardown(void) XftColorFree(X_Dpy, DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which), &sc->xftcolor[i]); - XftDrawDestroy(sc->menu.xftdraw); XftFontClose(X_Dpy, sc->xftfont); - XUnmapWindow(X_Dpy, sc->menu.win); + XftDrawDestroy(sc->menu.xftdraw); XDestroyWindow(X_Dpy, sc->menu.win); XUngrabKey(X_Dpy, AnyKey, AnyModifier, sc->rootwin); } From f63b2e2341b8e883598ab33a46708ae315a63a99 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 30 Sep 2016 15:05:02 +0000 Subject: [PATCH 10/34] Switch to XWindowEvent() pulling out events that match the mask *and* window. --- mousefunc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mousefunc.c b/mousefunc.c index 5b795cc..9d47531 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -76,7 +76,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); for (;;) { - XMaskEvent(X_Dpy, MOUSEMASK, &ev); + XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev); switch (ev.type) { case MotionNotify: @@ -129,7 +129,7 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) xu_ptr_getpos(cc->win, &px, &py); for (;;) { - XMaskEvent(X_Dpy, MOUSEMASK, &ev); + XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev); switch (ev.type) { case MotionNotify: From 8b26a43bf17b3834de3127408e7274e8effc9beb Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 30 Sep 2016 15:12:19 +0000 Subject: [PATCH 11/34] Replace mousefunc_sweep_draw() with a generic menu_windraw() using va lists; use it appropriately for both window dimension and position in the respective mousefunc calls. ok bryent@ --- calmwm.h | 2 ++ menu.c | 32 ++++++++++++++++++++++++++++++++ mousefunc.c | 32 ++++++-------------------------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/calmwm.h b/calmwm.h index 97fa0ed..bbfebea 100644 --- a/calmwm.h +++ b/calmwm.h @@ -511,6 +511,8 @@ void mousefunc_client_move(struct client_ctx *, void mousefunc_client_resize(struct client_ctx *, union arg *); +void menu_windraw(struct screen_ctx *, Window, + const char *, ...); struct menu *menu_filter(struct screen_ctx *, struct menu_q *, const char *, const char *, int, void (*)(struct menu_q *, struct menu_q *, char *), diff --git a/menu.c b/menu.c index a84f578..80197b9 100644 --- a/menu.c +++ b/menu.c @@ -638,3 +638,35 @@ menuq_clear(struct menu_q *mq) free(mi); } } + +void +menu_windraw(struct screen_ctx *sc, Window win, const char *fmt, ...) +{ + va_list ap; + int i; + char *text; + XGlyphInfo extents; + + va_start(ap, fmt); + i = vasprintf(&text, fmt, ap); + va_end(ap); + + if (i < 0 || text == NULL) + err(1, "vasprintf"); + + XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text, + strlen(text), &extents); + + XReparentWindow(X_Dpy, sc->menu.win, win, 0, 0); + XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, + extents.xOff, sc->xftfont->height); + XMapWindow(X_Dpy, sc->menu.win); + XClearWindow(X_Dpy, sc->menu.win); + + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], + sc->xftfont, 0, sc->xftfont->ascent + 1, + (const FcChar8*)text, strlen(text)); + + free(text); +} + diff --git a/mousefunc.c b/mousefunc.c index 9d47531..f7d5768 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -32,31 +32,6 @@ #include "calmwm.h" -static void mousefunc_sweep_draw(struct client_ctx *); - -static void -mousefunc_sweep_draw(struct client_ctx *cc) -{ - struct screen_ctx *sc = cc->sc; - char s[14]; /* fits " nnnn x nnnn \0" */ - XGlyphInfo extents; - - (void)snprintf(s, sizeof(s), " %4d x %-4d ", cc->dim.w, cc->dim.h); - - XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)s, - strlen(s), &extents); - - XReparentWindow(X_Dpy, sc->menu.win, cc->win, 0, 0); - XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, - extents.xOff, sc->xftfont->height); - XMapWindow(X_Dpy, sc->menu.win); - XClearWindow(X_Dpy, sc->menu.win); - - XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], - sc->xftfont, 0, sc->xftfont->ascent + 1, - (const FcChar8*)s, strlen(s)); -} - void mousefunc_client_resize(struct client_ctx *cc, union arg *arg) { @@ -89,7 +64,8 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) cc->geom.h = ev.xmotion.y; client_applysizehints(cc); client_resize(cc, 1); - mousefunc_sweep_draw(cc); + menu_windraw(sc, cc->win, + "%4d x %-4d", cc->dim.w, cc->dim.h); break; case ButtonRelease: client_resize(cc, 1); @@ -151,9 +127,13 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) cc->geom.y + cc->geom.h + (cc->bwidth * 2), area.y, area.y + area.h, sc->snapdist); client_move(cc); + menu_windraw(sc, cc->win, + "%4d, %-4d", cc->geom.x, cc->geom.y); break; case ButtonRelease: client_move(cc); + XUnmapWindow(X_Dpy, sc->menu.win); + XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); xu_ptr_ungrab(); return; } From 2d8f621b8d285b1cf8e29feb383fa2268e57ee5a Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 30 Sep 2016 18:28:06 +0000 Subject: [PATCH 12/34] Use instinsic X11 functions for key/btn/ptr grab/ungrab/regrab requests; the one line wrappers provided no value and limited altering calls where needed; additionally, most of them had but one caller. --- calmwm.h | 7 ------ conf.c | 32 +++++++++++++++++++++------ menu.c | 17 +++++++++------ mousefunc.c | 12 +++++++---- xutil.c | 62 ----------------------------------------------------- 5 files changed, 45 insertions(+), 85 deletions(-) diff --git a/calmwm.h b/calmwm.h index bbfebea..c61e9ed 100644 --- a/calmwm.h +++ b/calmwm.h @@ -542,17 +542,10 @@ void conf_screen(struct screen_ctx *); void xev_process(void); -void xu_btn_grab(Window, int, unsigned int); -void xu_btn_ungrab(Window); int xu_getprop(Window, Atom, Atom, long, unsigned char **); int xu_getstrprop(Window, Atom, char **); -void xu_key_grab(Window, unsigned int, KeySym); -void xu_key_ungrab(Window); void xu_ptr_getpos(Window, int *, int *); -int xu_ptr_grab(Window, unsigned int, Cursor); -int xu_ptr_regrab(unsigned int, Cursor); void xu_ptr_setpos(Window, int, int); -void xu_ptr_ungrab(void); void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); diff --git a/conf.c b/conf.c index c0c7b41..e03b337 100644 --- a/conf.c +++ b/conf.c @@ -655,28 +655,48 @@ conf_cursor(struct conf *c) c->cursor[i] = XCreateFontCursor(X_Dpy, cursor_binds[i]); } +static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; + void conf_grab_mouse(Window win) { struct binding *mb; + unsigned int i; - xu_btn_ungrab(win); + XUngrabButton(X_Dpy, AnyButton, AnyModifier, win); TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { - if (mb->context == CWM_CONTEXT_CLIENT) - xu_btn_grab(win, mb->modmask, mb->press.button); + if (mb->context != CWM_CONTEXT_CLIENT) + continue; + for (i = 0; i < nitems(ign_mods); i++) { + XGrabButton(X_Dpy, mb->press.button, + (mb->modmask | ign_mods[i]), win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, + None, None); + } } + } void conf_grab_kbd(Window win) { struct binding *kb; + KeyCode kc; + unsigned int i; - xu_key_ungrab(win); + XUngrabKey(X_Dpy, AnyKey, AnyModifier, win); - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - xu_key_grab(win, kb->modmask, kb->press.keysym); + TAILQ_FOREACH(kb, &Conf.keybindingq, entry) { + kc = XKeysymToKeycode(X_Dpy, kb->press.keysym); + if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) && + (XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym)) + kb->modmask |= ShiftMask; + + for (i = 0; i < nitems(ign_mods); i++) + XGrabKey(X_Dpy, kc, (kb->modmask | ign_mods[i]), win, + True, GrabModeAsync, GrabModeAsync); + } } static char *cwmhints[] = { diff --git a/menu.c b/menu.c index 80197b9..c3a4f9d 100644 --- a/menu.c +++ b/menu.c @@ -121,10 +121,12 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt, XSelectInput(X_Dpy, sc->menu.win, evmask); XMapRaised(X_Dpy, sc->menu.win); - if (xu_ptr_grab(sc->menu.win, MENUGRABMASK, - Conf.cursor[CF_QUESTION]) < 0) { + if (XGrabPointer(X_Dpy, sc->menu.win, False, MENUGRABMASK, + GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_QUESTION], + CurrentTime) != GrabSuccess) { XUnmapWindow(X_Dpy, sc->menu.win); return(NULL); + } XGetInputFocus(X_Dpy, &focuswin, &focusrevert); @@ -172,7 +174,7 @@ out: xu_ptr_getpos(sc->rootwin, &xcur, &ycur); if (xcur == mc.geom.x && ycur == mc.geom.y) xu_ptr_setpos(sc->rootwin, xsave, ysave); - xu_ptr_ungrab(); + XUngrabPointer(X_Dpy, CurrentTime); XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, 1, 1); XUnmapWindow(X_Dpy, sc->menu.win); @@ -472,10 +474,13 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) if (mc->prev != -1) menu_draw_entry(mc, resultq, mc->prev, 0); if (mc->entry != -1) { - (void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_NORMAL]); + XChangeActivePointerGrab(X_Dpy, MENUGRABMASK, + Conf.cursor[CF_NORMAL], CurrentTime); menu_draw_entry(mc, resultq, mc->entry, 1); - } else - (void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]); + } else { + XChangeActivePointerGrab(X_Dpy, MENUGRABMASK, + Conf.cursor[CF_DEFAULT], CurrentTime); + } } static struct menu * diff --git a/mousefunc.c b/mousefunc.c index f7d5768..cd7a897 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -45,7 +45,9 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) client_raise(cc); client_ptrsave(cc); - if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0) + if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, + GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE], + CurrentTime) != GrabSuccess) return; xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); @@ -71,7 +73,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) client_resize(cc, 1); XUnmapWindow(X_Dpy, sc->menu.win); XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); - xu_ptr_ungrab(); + XUngrabPointer(X_Dpy, CurrentTime); /* Make sure the pointer stays within the window. */ if (cc->ptr.x > cc->geom.w) @@ -99,7 +101,9 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) if (cc->flags & CLIENT_FREEZE) return; - if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0) + if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, + GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE], + CurrentTime) != GrabSuccess) return; xu_ptr_getpos(cc->win, &px, &py); @@ -134,7 +138,7 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) client_move(cc); XUnmapWindow(X_Dpy, sc->menu.win); XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); - xu_ptr_ungrab(); + XUngrabPointer(X_Dpy, CurrentTime); return; } } diff --git a/xutil.c b/xutil.c index 39639ef..cd7dfb9 100644 --- a/xutil.c +++ b/xutil.c @@ -31,68 +31,6 @@ #include "calmwm.h" -static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; - -void -xu_btn_grab(Window win, int mask, unsigned int btn) -{ - unsigned int i; - - for (i = 0; i < nitems(ign_mods); i++) - XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win, - False, BUTTONMASK, GrabModeAsync, - GrabModeSync, None, None); -} - -void -xu_btn_ungrab(Window win) -{ - XUngrabButton(X_Dpy, AnyButton, AnyModifier, win); -} - -void -xu_key_grab(Window win, unsigned int mask, KeySym keysym) -{ - KeyCode code; - unsigned int i; - - code = XKeysymToKeycode(X_Dpy, keysym); - if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && - (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym)) - mask |= ShiftMask; - - for (i = 0; i < nitems(ign_mods); i++) - XGrabKey(X_Dpy, code, (mask | ign_mods[i]), win, - True, GrabModeAsync, GrabModeAsync); -} - -void -xu_key_ungrab(Window win) -{ - XUngrabKey(X_Dpy, AnyKey, AnyModifier, win); -} - -int -xu_ptr_grab(Window win, unsigned int mask, Cursor curs) -{ - return(XGrabPointer(X_Dpy, win, False, mask, - GrabModeAsync, GrabModeAsync, - None, curs, CurrentTime) == GrabSuccess ? 0 : -1); -} - -int -xu_ptr_regrab(unsigned int mask, Cursor curs) -{ - return(XChangeActivePointerGrab(X_Dpy, mask, - curs, CurrentTime) == GrabSuccess ? 0 : -1); -} - -void -xu_ptr_ungrab(void) -{ - XUngrabPointer(X_Dpy, CurrentTime); -} - void xu_ptr_getpos(Window win, int *x, int *y) { From 1c54fc079dab7dcc56d057f40be01fb1f3a21c2a Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 30 Sep 2016 20:55:54 +0000 Subject: [PATCH 13/34] Set the initial ptr position during client init, instead of waiting until (maybe) a ptrwarp call. Likewise, explicitly ensure an inbounds ptr position (same as initial) when saving. --- client.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/client.c b/client.c index 9fb097a..6e91ea5 100644 --- a/client.c +++ b/client.c @@ -75,8 +75,6 @@ client_init(Window win, struct screen_ctx *sc, int active) cc->stackingorder = 0; memset(&cc->hint, 0, sizeof(cc->hint)); memset(&cc->ch, 0, sizeof(cc->ch)); - cc->ptr.x = -1; - cc->ptr.y = -1; TAILQ_INIT(&cc->nameq); client_setname(cc); @@ -93,6 +91,9 @@ client_init(Window win, struct screen_ctx *sc, int active) cc->geom.y = wattr.y; cc->geom.w = wattr.width; cc->geom.h = wattr.height; + cc->ptr.x = cc->geom.w / 2; + cc->ptr.y = cc->geom.h / 2; + cc->colormap = wattr.colormap; if (wattr.map_state != IsViewable) { @@ -468,18 +469,12 @@ client_config(struct client_ctx *cc) void client_ptrwarp(struct client_ctx *cc) { - int x = cc->ptr.x, y = cc->ptr.y; - - if (x == -1 || y == -1) { - x = cc->geom.w / 2; - y = cc->geom.h / 2; - } - if (cc->flags & CLIENT_HIDDEN) client_unhide(cc); else client_raise(cc); - xu_ptr_setpos(cc->win, x, y); + + xu_ptr_setpos(cc->win, cc->ptr.x, cc->ptr.y); } void @@ -492,8 +487,8 @@ client_ptrsave(struct client_ctx *cc) cc->ptr.x = x; cc->ptr.y = y; } else { - cc->ptr.x = -1; - cc->ptr.y = -1; + cc->ptr.x = cc->geom.w / 2; + cc->ptr.y = cc->geom.h / 2; } } From 1d3a6905f13d83e61cf5b7403a09d6899cd067e3 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 30 Sep 2016 21:44:51 +0000 Subject: [PATCH 14/34] remove unused proto --- calmwm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index c61e9ed..98eb064 100644 --- a/calmwm.h +++ b/calmwm.h @@ -422,7 +422,6 @@ void client_transient(struct client_ctx *); void client_unhide(struct client_ctx *); void client_urgency(struct client_ctx *); void client_vtile(struct client_ctx *); -void client_warp(struct client_ctx *); void client_wm_hints(struct client_ctx *); void group_alltoggle(struct screen_ctx *); From a8a111dffd2752fc5be7773a67d03306dd92d05e Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 3 Oct 2016 13:41:30 +0000 Subject: [PATCH 15/34] client_ptrwarp should not deal with unhiding or raising clients (non ptr requests); most callers do this already - deal with the few that do not. client_ptrwarp becomes a simple wrapper (setpos) but it will be expanded. --- client.c | 6 +----- kbfunc.c | 2 ++ xevents.c | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/client.c b/client.c index 6e91ea5..4aa69b9 100644 --- a/client.c +++ b/client.c @@ -469,11 +469,6 @@ client_config(struct client_ctx *cc) void client_ptrwarp(struct client_ctx *cc) { - if (cc->flags & CLIENT_HIDDEN) - client_unhide(cc); - else - client_raise(cc); - xu_ptr_setpos(cc->win, cc->ptr.x, cc->ptr.y); } @@ -686,6 +681,7 @@ client_cycle(struct screen_ctx *sc, int flags) /* reset when cycling mod is released. XXX I hate this hack */ sc->cycling = 1; client_ptrsave(oldcc); + client_raise(newcc); client_ptrwarp(newcc); } diff --git a/kbfunc.c b/kbfunc.c index efcfd3c..c5b0083 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -187,6 +187,8 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg) cc = (struct client_ctx *)mi->ctx; if (cc->flags & CLIENT_HIDDEN) client_unhide(cc); + else + client_raise(cc); if (old_cc) client_ptrsave(old_cc); client_ptrwarp(cc); diff --git a/xevents.c b/xevents.c index 582f839..a4ff04d 100644 --- a/xevents.c +++ b/xevents.c @@ -344,6 +344,10 @@ xev_handle_clientmessage(XEvent *ee) if ((cc = client_find(e->window)) != NULL) { if ((old_cc = client_current()) != NULL) client_ptrsave(old_cc); + if (cc->flags & CLIENT_HIDDEN) + client_unhide(cc); + else + client_raise(cc); client_ptrwarp(cc); } } else if (e->message_type == ewmh[_NET_WM_DESKTOP]) { From 792f85cde97742d0c580ee2354044870d0f8754f Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 3 Oct 2016 13:52:17 +0000 Subject: [PATCH 16/34] For both kb and mouse move, it is possible to grab a client and move it completely off the screen/region; instead, if the pointer is outside of the client bounds, warp the pointer to the closest edge before moving. --- kbfunc.c | 14 +++++++++++++- mousefunc.c | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/kbfunc.c b/kbfunc.c index c5b0083..fc2bc8b 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -95,12 +95,24 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg) { struct screen_ctx *sc = cc->sc; struct geom area; - int x, y; + int x, y, px, py; unsigned int mx = 0, my = 0; if (cc->flags & CLIENT_FREEZE) return; + xu_ptr_getpos(cc->win, &px, &py); + if (px < 0) + px = 0; + else if (px > cc->geom.w) + px = cc->geom.w; + if (py < 0) + py = 0; + else if (py > cc->geom.h) + py = cc->geom.h; + + xu_ptr_setpos(cc->win, px, py); + kbfunc_amount(arg->i, Conf.mamount, &mx, &my); cc->geom.x += mx; diff --git a/mousefunc.c b/mousefunc.c index cd7a897..2bf19db 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -45,13 +45,13 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) client_raise(cc); client_ptrsave(cc); + xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); + if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE], CurrentTime) != GrabSuccess) return; - xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h); - for (;;) { XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev); @@ -101,13 +101,23 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) if (cc->flags & CLIENT_FREEZE) return; + xu_ptr_getpos(cc->win, &px, &py); + if (px < 0) + px = 0; + else if (px > cc->geom.w) + px = cc->geom.w; + if (py < 0) + py = 0; + else if (py > cc->geom.h) + py = cc->geom.h; + + xu_ptr_setpos(cc->win, px, py); + if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE], CurrentTime) != GrabSuccess) return; - xu_ptr_getpos(cc->win, &px, &py); - for (;;) { XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev); From 03f5dc219e20edbcf4b7eac1f733a188ab8f7c29 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 3 Oct 2016 14:42:34 +0000 Subject: [PATCH 17/34] Defaults are split between defines and conf_init(); normalize these, as well as give 'sticky' groups its own variable. --- calmwm.h | 17 ++++++----------- client.c | 2 +- conf.c | 9 +++++---- parse.y | 5 +---- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/calmwm.h b/calmwm.h index 98eb064..f69eab9 100644 --- a/calmwm.h +++ b/calmwm.h @@ -284,34 +284,26 @@ struct conf { struct autogroupwin_q autogroupq; struct ignore_q ignoreq; struct cmd_q cmdq; -#define CONF_STICKY_GROUPS 0x0001 - int flags; -#define CONF_BWIDTH 1 + int stickygroups; int bwidth; -#define CONF_MAMOUNT 1 int mamount; -#define CONF_SNAPDIST 0 int snapdist; struct gap gap; char *color[CWM_COLOR_NITEMS]; char known_hosts[PATH_MAX]; -#define CONF_FONT "sans-serif:pixelsize=14:bold" char *font; Cursor cursor[CF_NITEMS]; }; /* MWM hints */ struct mwm_hints { - unsigned long flags; - unsigned long functions; - unsigned long decorations; -}; #define MWM_HINTS_ELEMENTS 3L +#define MWM_FLAGS_STATUS (1<<3) #define MWM_FLAGS_FUNCTIONS (1<<0) #define MWM_FLAGS_DECORATIONS (1<<1) #define MWM_FLAGS_INPUT_MODE (1<<2) -#define MWM_FLAGS_STATUS (1<<3) + unsigned long flags; #define MWM_FUNCS_ALL (1<<0) #define MWM_FUNCS_RESIZE (1<<1) @@ -319,6 +311,7 @@ struct mwm_hints { #define MWM_FUNCS_MINIMIZE (1<<3) #define MWM_FUNCS_MAXIMIZE (1<<4) #define MWM_FUNCS_CLOSE (1<<5) + unsigned long functions; #define MWM_DECOR_ALL (1<<0) #define MWM_DECOR_BORDER (1<<1) @@ -327,6 +320,8 @@ struct mwm_hints { #define MWM_DECOR_MENU (1<<4) #define MWM_DECOR_MINIMIZE (1<<5) #define MWM_DECOR_MAXIMIZE (1<<6) + unsigned long decorations; +}; extern Display *X_Dpy; extern Time Last_Event_Time; diff --git a/client.c b/client.c index 4aa69b9..1de9290 100644 --- a/client.c +++ b/client.c @@ -133,7 +133,7 @@ client_init(Window win, struct screen_ctx *sc, int active) goto out; if (group_autogroup(cc)) goto out; - if (Conf.flags & CONF_STICKY_GROUPS) + if (Conf.stickygroups) group_assign(sc->group_active, cc); else group_assign(NULL, cc); diff --git a/conf.c b/conf.c index e03b337..47a9566 100644 --- a/conf.c +++ b/conf.c @@ -254,9 +254,10 @@ conf_init(struct conf *c) { unsigned int i; - c->bwidth = CONF_BWIDTH; - c->mamount = CONF_MAMOUNT; - c->snapdist = CONF_SNAPDIST; + c->stickygroups = 0; + c->bwidth = 1; + c->mamount = 1; + c->snapdist = 0; TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->cmdq); @@ -279,7 +280,7 @@ conf_init(struct conf *c) (void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s", homedir, ".ssh/known_hosts"); - c->font = xstrdup(CONF_FONT); + c->font = xstrdup("sans-serif:pixelsize=14:bold"); } void diff --git a/parse.y b/parse.y index dd0714e..c035e4e 100644 --- a/parse.y +++ b/parse.y @@ -112,10 +112,7 @@ main : FONTNAME STRING { conf->font = $2; } | STICKY yesno { - if ($2 == 0) - conf->flags &= ~CONF_STICKY_GROUPS; - else - conf->flags |= CONF_STICKY_GROUPS; + conf->stickygroups = $2; } | BORDERWIDTH NUMBER { if ($2 < 0 || $2 > UINT_MAX) { From 8aa5033d12eec5e764885f3e8b27c1df22d6b0df Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 3 Oct 2016 18:43:49 +0000 Subject: [PATCH 18/34] Start simplifying menu code; and in turn, remove a cursor no longer needed. --- calmwm.h | 5 ++--- conf.c | 5 ++--- menu.c | 39 ++++++++++++++++++--------------------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/calmwm.h b/calmwm.h index f69eab9..4381f62 100644 --- a/calmwm.h +++ b/calmwm.h @@ -96,11 +96,10 @@ union press { }; enum cursor_font { - CF_DEFAULT, - CF_MOVE, CF_NORMAL, - CF_QUESTION, + CF_MOVE, CF_RESIZE, + CF_QUESTION, CF_NITEMS }; enum color { diff --git a/conf.c b/conf.c index 47a9566..f415257 100644 --- a/conf.c +++ b/conf.c @@ -640,11 +640,10 @@ conf_unbind_mouse(struct conf *c, struct binding *unbind) } static int cursor_binds[] = { - XC_X_cursor, /* CF_DEFAULT */ - XC_fleur, /* CF_MOVE */ XC_left_ptr, /* CF_NORMAL */ - XC_question_arrow, /* CF_QUESTION */ + XC_fleur, /* CF_MOVE */ XC_bottom_right_corner, /* CF_RESIZE */ + XC_question_arrow, /* CF_QUESTION */ }; void diff --git a/menu.c b/menu.c index c3a4f9d..4f91f9a 100644 --- a/menu.c +++ b/menu.c @@ -63,10 +63,10 @@ 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 menu_q *); -static struct menu *menu_handle_release(XEvent *, struct menu_ctx *, - struct menu_q *); +static void menu_handle_move(struct menu_ctx *, + struct menu_q *, int, int); +static struct menu *menu_handle_release(struct menu_ctx *, + struct menu_q *, int, int); static void menu_draw(struct menu_ctx *, struct menu_q *, struct menu_q *); static void menu_draw_entry(struct menu_ctx *, struct menu_q *, @@ -151,11 +151,12 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt, menu_draw(&mc, menuq, &resultq); break; case MotionNotify: - menu_handle_move(&e, &mc, &resultq); + menu_handle_move(&mc, &resultq, + e.xbutton.x, e.xbutton.y); break; case ButtonRelease: - if ((mi = menu_handle_release(&e, &mc, &resultq)) - != NULL) + if ((mi = menu_handle_release(&mc, &resultq, + e.xbutton.x, e.xbutton.y)) != NULL) goto out; break; default: @@ -408,14 +409,14 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) XMoveResizeWindow(X_Dpy, sc->menu.win, mc->geom.x, mc->geom.y, mc->geom.w, mc->geom.h); + n = 0; if (mc->hasprompt) { XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, 0, sc->xftfont->ascent, (const FcChar8*)mc->dispstr, strlen(mc->dispstr)); - n = 1; - } else - n = 0; + n++; + } TAILQ_FOREACH(mi, resultq, resultentry) { int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; @@ -463,10 +464,10 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, } static void -menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) +menu_handle_move(struct menu_ctx *mc, struct menu_q *resultq, int x, int y) { mc->prev = mc->entry; - mc->entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y); + mc->entry = menu_calc_entry(mc, x, y); if (mc->prev == mc->entry) return; @@ -477,19 +478,16 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) XChangeActivePointerGrab(X_Dpy, MENUGRABMASK, Conf.cursor[CF_NORMAL], CurrentTime); menu_draw_entry(mc, resultq, mc->entry, 1); - } else { - XChangeActivePointerGrab(X_Dpy, MENUGRABMASK, - Conf.cursor[CF_DEFAULT], CurrentTime); } } static struct menu * -menu_handle_release(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) +menu_handle_release(struct menu_ctx *mc, struct menu_q *resultq, int x, int y) { struct menu *mi; int entry, i = 0; - entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y); + entry = menu_calc_entry(mc, x, y); if (mc->hasprompt) i = 1; @@ -529,13 +527,12 @@ static int menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) { KeySym ks; - unsigned int state = ev->state; *ctl = CTL_NONE; chr[0] = '\0'; ks = XkbKeycodeToKeysym(X_Dpy, ev->keycode, 0, - (state & ShiftMask) ? 1 : 0); + (ev->state & ShiftMask) ? 1 : 0); /* Look for control characters. */ switch (ks) { @@ -560,7 +557,7 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) break; } - if (*ctl == CTL_NONE && (state & ControlMask)) { + if (*ctl == CTL_NONE && (ev->state & ControlMask)) { switch (ks) { case XK_s: case XK_S: @@ -590,7 +587,7 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) } } - if (*ctl == CTL_NONE && (state & Mod1Mask)) { + if (*ctl == CTL_NONE && (ev->state & Mod1Mask)) { switch (ks) { case XK_j: case XK_J: From 9306c1fbd3e491b9dcdcbb8587460296843a10ce Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 4 Oct 2016 15:18:20 +0000 Subject: [PATCH 19/34] Turn CALMWM_NGROUPS define into variable, ngroups. --- calmwm.h | 2 +- conf.c | 1 + group.c | 8 ++++---- screen.c | 2 +- xutil.c | 23 ++++++++++++----------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/calmwm.h b/calmwm.h index 4381f62..d9734d9 100644 --- a/calmwm.h +++ b/calmwm.h @@ -235,7 +235,6 @@ struct screen_ctx { struct gap gap; struct client_ctx_q clientq; struct region_ctx_q regionq; -#define CALMWM_NGROUPS 10 struct group_ctx_q groupq; struct group_ctx *group_active; struct { @@ -283,6 +282,7 @@ struct conf { struct autogroupwin_q autogroupq; struct ignore_q ignoreq; struct cmd_q cmdq; + int ngroups; int stickygroups; int bwidth; int mamount; diff --git a/conf.c b/conf.c index f415257..478768d 100644 --- a/conf.c +++ b/conf.c @@ -258,6 +258,7 @@ conf_init(struct conf *c) c->bwidth = 1; c->mamount = 1; c->snapdist = 0; + c->ngroups = 10; TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->cmdq); diff --git a/group.c b/group.c index 81961e7..36fd397 100644 --- a/group.c +++ b/group.c @@ -154,7 +154,7 @@ group_movetogroup(struct client_ctx *cc, int idx) struct screen_ctx *sc = cc->sc; struct group_ctx *gc; - if (idx < 0 || idx >= CALMWM_NGROUPS) + if (idx < 0 || idx >= Conf.ngroups) errx(1, "group_movetogroup: index out of range (%d)", idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -222,7 +222,7 @@ group_hidetoggle(struct screen_ctx *sc, int idx) { struct group_ctx *gc; - if (idx < 0 || idx >= CALMWM_NGROUPS) + if (idx < 0 || idx >= Conf.ngroups) errx(1, "group_hidetoggle: index out of range (%d)", idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -245,7 +245,7 @@ group_only(struct screen_ctx *sc, int idx) { struct group_ctx *gc; - if (idx < 0 || idx >= CALMWM_NGROUPS) + if (idx < 0 || idx >= Conf.ngroups) errx(1, "group_only: index out of range (%d)", idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -335,7 +335,7 @@ group_restore(struct client_ctx *cc) return(0); num = (*grpnum == -1) ? 0 : *grpnum; - num = MIN(num, (CALMWM_NGROUPS - 1)); + num = MIN(num, (Conf.ngroups - 1)); XFree(grpnum); TAILQ_FOREACH(gc, &sc->groupq, entry) { diff --git a/screen.c b/screen.c index 7f2132f..79e7cc5 100644 --- a/screen.c +++ b/screen.c @@ -57,7 +57,7 @@ screen_init(int which) screen_update_geometry(sc); - for (i = 0; i < CALMWM_NGROUPS; i++) + for (i = 0; i < Conf.ngroups; i++) group_init(sc, i); xu_ewmh_net_desktop_names(sc); diff --git a/xutil.c b/xutil.c index cd7dfb9..5cb3637 100644 --- a/xutil.c +++ b/xutil.c @@ -131,19 +131,20 @@ xu_ewmh_net_desktop_geometry(struct screen_ctx *sc) void xu_ewmh_net_workarea(struct screen_ctx *sc) { - long workareas[CALMWM_NGROUPS][4]; - int i; + unsigned long *workarea; + int i, ngroups = Conf.ngroups; - for (i = 0; i < CALMWM_NGROUPS; i++) { - workareas[i][0] = sc->work.x; - workareas[i][1] = sc->work.y; - workareas[i][2] = sc->work.w; - workareas[i][3] = sc->work.h; + workarea = xreallocarray(NULL, ngroups * 4, sizeof(unsigned long)); + for (i = 0; i < ngroups; i++) { + workarea[4 * i + 0] = sc->work.x; + workarea[4 * i + 1] = sc->work.y; + workarea[4 * i + 2] = sc->work.w; + workarea[4 * i + 3] = sc->work.h; } - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_WORKAREA], - XA_CARDINAL, 32, PropModeReplace, (unsigned char *)workareas, - CALMWM_NGROUPS * 4); + XA_CARDINAL, 32, PropModeReplace, (unsigned char *)workarea, + ngroups * 4); + free(workarea); } void @@ -223,7 +224,7 @@ xu_ewmh_net_wm_desktop_viewport(struct screen_ctx *sc) void xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *sc) { - long ndesks = CALMWM_NGROUPS; + long ndesks = Conf.ngroups; XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&ndesks, 1); From 5c13775d31ce277bba94c68daff12cf50224aba0 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 4 Oct 2016 15:52:32 +0000 Subject: [PATCH 20/34] Calculate client nameqlen in client_setname(), the only place it's needed/used. --- calmwm.h | 3 +-- client.c | 13 +++++++------ conf.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/calmwm.h b/calmwm.h index d9734d9..867f3ad 100644 --- a/calmwm.h +++ b/calmwm.h @@ -187,8 +187,6 @@ struct client_ctx { int flags; int stackingorder; struct winname_q nameq; -#define CLIENT_MAXNAMEQLEN 5 - int nameqlen; char *name; char *label; char *matchname; @@ -284,6 +282,7 @@ struct conf { struct cmd_q cmdq; int ngroups; int stickygroups; + int nameqlen; int bwidth; int mamount; int snapdist; diff --git a/client.c b/client.c index 1de9290..ce7392e 100644 --- a/client.c +++ b/client.c @@ -605,6 +605,7 @@ client_setname(struct client_ctx *cc) { struct winname *wn; char *newname; + int i = 0; if (!xu_getstrprop(cc->win, ewmh[_NET_WM_NAME], &newname)) if (!xu_getstrprop(cc->win, XA_WM_NAME, &newname)) @@ -621,19 +622,19 @@ client_setname(struct client_ctx *cc) wn = xmalloc(sizeof(*wn)); wn->name = newname; TAILQ_INSERT_TAIL(&cc->nameq, wn, entry); - cc->nameqlen++; match: cc->name = wn->name; - /* Now, do some garbage collection. */ - if (cc->nameqlen > CLIENT_MAXNAMEQLEN) { - if ((wn = TAILQ_FIRST(&cc->nameq)) == NULL) - errx(1, "client_setname: window name queue empty"); + /* Do some garbage collection. */ + TAILQ_FOREACH(wn, &cc->nameq, entry) + i++; + if (i > Conf.nameqlen) { + wn = TAILQ_FIRST(&cc->nameq); TAILQ_REMOVE(&cc->nameq, wn, entry); free(wn->name); free(wn); - cc->nameqlen--; + i--; } } diff --git a/conf.c b/conf.c index 478768d..974388c 100644 --- a/conf.c +++ b/conf.c @@ -259,6 +259,7 @@ conf_init(struct conf *c) c->mamount = 1; c->snapdist = 0; c->ngroups = 10; + c->nameqlen = 5; TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->cmdq); From a37606c63ff059a458023ddef1bd6e8926497f18 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 4 Oct 2016 20:15:55 +0000 Subject: [PATCH 21/34] When removing xrandr regions, ensure clients are within the bounds of the screen; adapted from an ancient diff from Sviatoslav Chagaev. Things in this area will likely change, but put this in so it works now and serves as a reminder. --- calmwm.h | 1 + screen.c | 23 +++++++++++++++++++++++ xevents.c | 1 + 3 files changed, 25 insertions(+) diff --git a/calmwm.h b/calmwm.h index 867f3ad..f62014b 100644 --- a/calmwm.h +++ b/calmwm.h @@ -455,6 +455,7 @@ struct geom screen_area(struct screen_ctx *, int, int, int); void screen_init(int); void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); +void screen_assert_clients_within(struct screen_ctx *); void kbfunc_client_cycle(struct client_ctx *, union arg *); void kbfunc_client_delete(struct client_ctx *, union arg *); diff --git a/screen.c b/screen.c index 79e7cc5..b9f1ac9 100644 --- a/screen.c +++ b/screen.c @@ -229,3 +229,26 @@ screen_apply_gap(struct screen_ctx *sc, struct geom geom) return(geom); } + +/* Bring back clients which are beyond the screen. */ +void +screen_assert_clients_within(struct screen_ctx *sc) +{ + struct client_ctx *cc; + int top, left, right, bottom; + + TAILQ_FOREACH(cc, &sc->clientq, entry) { + if (cc->sc != sc) + continue; + top = cc->geom.y; + left = cc->geom.x; + right = cc->geom.x + cc->geom.w + (cc->bwidth * 2) - 1; + bottom = cc->geom.y + cc->geom.h + (cc->bwidth * 2) - 1; + if ((top > sc->view.h || left > sc->view.w) || + (bottom < 0 || right < 0)) { + cc->geom.x = sc->gap.left; + cc->geom.y = sc->gap.top; + client_move(cc); + } + } +} diff --git a/xevents.c b/xevents.c index a4ff04d..3dab168 100644 --- a/xevents.c +++ b/xevents.c @@ -386,6 +386,7 @@ xev_handle_randr(XEvent *ee) if (sc->which == i) { XRRUpdateConfiguration(ee); screen_update_geometry(sc); + screen_assert_clients_within(sc); } } } From d40820d3f34f2787fa6397216112281b1eead3b7 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 5 Oct 2016 13:10:59 +0000 Subject: [PATCH 22/34] Stash wmname into conf. --- calmwm.h | 2 +- conf.c | 2 ++ xutil.c | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/calmwm.h b/calmwm.h index f62014b..15fb8b3 100644 --- a/calmwm.h +++ b/calmwm.h @@ -41,7 +41,6 @@ #endif #define CONFFILE ".cwmrc" -#define WMNAME "CWM" #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) #define MOUSEMASK (BUTTONMASK | PointerMotionMask) @@ -290,6 +289,7 @@ struct conf { char *color[CWM_COLOR_NITEMS]; char known_hosts[PATH_MAX]; char *font; + char *wmname; Cursor cursor[CF_NITEMS]; }; diff --git a/conf.c b/conf.c index 974388c..9cf196a 100644 --- a/conf.c +++ b/conf.c @@ -283,6 +283,7 @@ conf_init(struct conf *c) homedir, ".ssh/known_hosts"); c->font = xstrdup("sans-serif:pixelsize=14:bold"); + c->wmname = xstrdup("CWM"); } void @@ -327,6 +328,7 @@ conf_clear(struct conf *c) free(c->color[i]); free(c->font); + free(c->wmname); } void diff --git a/xutil.c b/xutil.c index 5cb3637..1b6faf0 100644 --- a/xutil.c +++ b/xutil.c @@ -115,8 +115,8 @@ xu_ewmh_net_supported_wm_check(struct screen_ctx *sc) XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK], XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME], - cwmh[UTF8_STRING], 8, PropModeReplace, (unsigned char *)WMNAME, - strlen(WMNAME)); + cwmh[UTF8_STRING], 8, PropModeReplace, + (unsigned char *)Conf.wmname, strlen(Conf.wmname)); } void From c131620d7bfe451c5366a1dcfd5a9a1d5689f5f1 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 5 Oct 2016 13:35:17 +0000 Subject: [PATCH 23/34] Add CM-a for 'nogroup' (CM-0 stays for now); update manpage to reflect. --- conf.c | 1 + cwm.1 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conf.c b/conf.c index 9cf196a..3ee6467 100644 --- a/conf.c +++ b/conf.c @@ -192,6 +192,7 @@ static const struct { { "MS-Tab", "rcycle" }, { "CM-n", "label" }, { "CM-x", "delete" }, + { "CM-a", "nogroup" }, { "CM-0", "nogroup" }, { "CM-1", "group1" }, { "CM-2", "group2" }, diff --git a/cwm.1 b/cwm.1 index 447b646..71a2f4a 100644 --- a/cwm.1 +++ b/cwm.1 @@ -97,7 +97,7 @@ Reverse cycle through currently visible windows. Delete current window. .It Ic CM-[n] Select group n, where n is 1-9. -.It Ic CM-0 +.It Ic CM-a Select all groups. .It Ic CM-g Toggle group membership of current window. From e7dcb17e1e5df88e90efd67e63d46f0435ad8099 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 5 Oct 2016 14:01:23 +0000 Subject: [PATCH 24/34] More accurate to say 'toggle', rather than 'select', for group[n]/nogroup. --- cwm.1 | 4 ++-- cwmrc.5 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cwm.1 b/cwm.1 index 71a2f4a..68434c3 100644 --- a/cwm.1 +++ b/cwm.1 @@ -96,9 +96,9 @@ Reverse cycle through currently visible windows. .It Ic CM-x Delete current window. .It Ic CM-[n] -Select group n, where n is 1-9. +Toggle visibility of group n, where n is 1-9. .It Ic CM-a -Select all groups. +Toggle visibility of all groups. .It Ic CM-g Toggle group membership of current window. .It Ic M-Right diff --git a/cwmrc.5 b/cwmrc.5 index 19a4152..93f7273 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -266,13 +266,13 @@ Launch .Dq ssh menu. .It group[n] -Select group n, where n is 1-9. +Toggle visibility of group n, where n is 1-9. .It grouponly[n] Like .Ar group[n] but also hides the other groups. .It nogroup -Select all groups. +Toggle visibility of all groups. .It grouptoggle Toggle group membership of current window. .It movetogroup[n] From 66f5360fd48401a1d8ac204e36567597a3974164 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 6 Oct 2016 14:30:05 +0000 Subject: [PATCH 25/34] Check the ptr bounds in the new client during cycling, since not all actions do ptrsave, such as restoring client geometry; adapted from a diff by Vadim Vygonets. --- client.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.c b/client.c index ce7392e..ab84b9a 100644 --- a/client.c +++ b/client.c @@ -683,6 +683,10 @@ client_cycle(struct screen_ctx *sc, int flags) sc->cycling = 1; client_ptrsave(oldcc); client_raise(newcc); + if (!client_inbound(newcc, newcc->ptr.x, newcc->ptr.y)) { + newcc->ptr.x = newcc->geom.w / 2; + newcc->ptr.y = newcc->geom.h / 2; + } client_ptrwarp(newcc); } From 987ee736b92ec889391283624d84cc6cc87c8c1a Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 6 Oct 2016 14:41:19 +0000 Subject: [PATCH 26/34] Add an argument to the callbacks to pass the xevent context, button or key press. This allows to remove a few hacks to duplicate functions only for behaviour changes; now differing behaviours are pushed down to the callback. Also will allow for previously unavailable actions to be bind-able down the road. --- calmwm.h | 74 ++++++++++++++++++++++++++--------------------------- conf.c | 17 +++++------- kbfunc.c | 70 +++++++++++++++++++++++++------------------------- mousefunc.c | 4 +-- xevents.c | 4 +-- 5 files changed, 82 insertions(+), 87 deletions(-) diff --git a/calmwm.h b/calmwm.h index 15fb8b3..6c5dfa3 100644 --- a/calmwm.h +++ b/calmwm.h @@ -74,8 +74,8 @@ #define CWM_GAP 0x0001 #define CWM_NOGAP 0x0002 -#define CWM_KBD 0x0001 -#define CWM_MOUSE 0x0002 +#define CWM_KEY 0x0001 +#define CWM_BTN 0x0002 #define CWM_CONTEXT_NONE 0x0000 #define CWM_CONTEXT_CLIENT 0x0001 @@ -245,7 +245,7 @@ TAILQ_HEAD(screen_ctx_q, screen_ctx); struct binding { TAILQ_ENTRY(binding) entry; - void (*callback)(struct client_ctx *, union arg *); + void (*callback)(struct client_ctx *, union arg *, int); union arg argument; unsigned int modmask; union press press; @@ -457,52 +457,52 @@ void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); void screen_assert_clients_within(struct screen_ctx *); -void kbfunc_client_cycle(struct client_ctx *, union arg *); -void kbfunc_client_delete(struct client_ctx *, union arg *); +void kbfunc_client_cycle(struct client_ctx *, union arg *, int); +void kbfunc_client_delete(struct client_ctx *, union arg *, int); void kbfunc_client_grouptoggle(struct client_ctx *, - union arg *); -void kbfunc_client_hide(struct client_ctx *, union arg *); -void kbfunc_client_label(struct client_ctx *, union arg *); -void kbfunc_client_lower(struct client_ctx *, union arg *); -void kbfunc_client_move(struct client_ctx *, union arg *); + union arg *, int); +void kbfunc_client_hide(struct client_ctx *, union arg *, int); +void kbfunc_client_label(struct client_ctx *, union arg *, int); +void kbfunc_client_lower(struct client_ctx *, union arg *, int); +void kbfunc_client_move(struct client_ctx *, union arg *, int); void kbfunc_client_movetogroup(struct client_ctx *, - union arg *); -void kbfunc_client_raise(struct client_ctx *, union arg *); -void kbfunc_client_rcycle(struct client_ctx *, union arg *); -void kbfunc_client_resize(struct client_ctx *, union arg *); -void kbfunc_client_tile(struct client_ctx *, union arg *); + union arg *, int); +void kbfunc_client_raise(struct client_ctx *, union arg *, int); +void kbfunc_client_rcycle(struct client_ctx *, union arg *, int); +void kbfunc_client_resize(struct client_ctx *, union arg *, int); +void kbfunc_client_tile(struct client_ctx *, union arg *, int); void kbfunc_client_toggle_freeze(struct client_ctx *, - union arg *); + union arg *, int); void kbfunc_client_toggle_fullscreen(struct client_ctx *, - union arg *); + union arg *, int); void kbfunc_client_toggle_hmaximize(struct client_ctx *, - union arg *); + union arg *, int); void kbfunc_client_toggle_maximize(struct client_ctx *, - union arg *); + union arg *, int); void kbfunc_client_toggle_sticky(struct client_ctx *, - union arg *); + union arg *, int); void kbfunc_client_toggle_vmaximize(struct client_ctx *, - union arg *); -void kbfunc_cwm_status(struct client_ctx *, union arg *); -void kbfunc_exec(struct client_ctx *, union arg *); -void kbfunc_exec_lock(struct client_ctx *, union arg *); -void kbfunc_exec_term(struct client_ctx *, union arg *); + union arg *, int); +void kbfunc_cwm_status(struct client_ctx *, union arg *, int); +void kbfunc_exec(struct client_ctx *, union arg *, int); +void kbfunc_exec_lock(struct client_ctx *, union arg *, int); +void kbfunc_exec_term(struct client_ctx *, union arg *, int); void kbfunc_group_alltoggle(struct client_ctx *, - union arg *); -void kbfunc_group_cycle(struct client_ctx *, union arg *); -void kbfunc_group_only(struct client_ctx *, union arg *); -void kbfunc_group_toggle(struct client_ctx *, union arg *); -void kbfunc_menu_exec(struct client_ctx *, union arg *); -void kbfunc_menu_client(struct client_ctx *, union arg *); -void kbfunc_menu_cmd(struct client_ctx *, union arg *); -void kbfunc_menu_group(struct client_ctx *, union arg *); -void kbfunc_menu_ssh(struct client_ctx *, union arg *); -void kbfunc_ptrmove(struct client_ctx *, union arg *); + union arg *, int); +void kbfunc_group_cycle(struct client_ctx *, union arg *, int); +void kbfunc_group_only(struct client_ctx *, union arg *, int); +void kbfunc_group_toggle(struct client_ctx *, union arg *, int); +void kbfunc_menu_exec(struct client_ctx *, union arg *, int); +void kbfunc_menu_client(struct client_ctx *, union arg *, int); +void kbfunc_menu_cmd(struct client_ctx *, union arg *, int); +void kbfunc_menu_group(struct client_ctx *, union arg *, int); +void kbfunc_menu_ssh(struct client_ctx *, union arg *, int); +void kbfunc_ptrmove(struct client_ctx *, union arg *, int); void mousefunc_client_move(struct client_ctx *, - union arg *); + union arg *, int); void mousefunc_client_resize(struct client_ctx *, - union arg *); + union arg *, int); void menu_windraw(struct screen_ctx *, Window, const char *, ...); diff --git a/conf.c b/conf.c index 3ee6467..4d8a643 100644 --- a/conf.c +++ b/conf.c @@ -351,7 +351,7 @@ conf_client(struct client_ctx *cc) static const struct { const char *tag; - void (*handler)(struct client_ctx *, union arg *); + void (*handler)(struct client_ctx *, union arg *, int); int context; union arg argument; } name_to_func[] = { @@ -412,8 +412,7 @@ static const struct { {.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} }, { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT, {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} }, - { "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, - {.i = CWM_KBD}}, + { "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0}}, { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT, {0} }, @@ -489,14 +488,10 @@ static const struct { { "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} }, { "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} }, { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} }, - { "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, - {.i = CWM_MOUSE} }, - { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, - {.i = CWM_MOUSE} }, - { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, - {.i = CWM_MOUSE} }, - { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, - {.i = CWM_MOUSE} }, + { "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0} }, + { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} }, + { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} }, + { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} }, }; static const struct { diff --git a/kbfunc.c b/kbfunc.c index fc2bc8b..1e4f95b 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -41,14 +41,14 @@ extern sig_atomic_t cwm_status; static void kbfunc_amount(int, int, unsigned int *, unsigned int *); void -kbfunc_client_lower(struct client_ctx *cc, union arg *arg) +kbfunc_client_lower(struct client_ctx *cc, union arg *arg, int xev) { client_ptrsave(cc); client_lower(cc); } void -kbfunc_client_raise(struct client_ctx *cc, union arg *arg) +kbfunc_client_raise(struct client_ctx *cc, union arg *arg, int xev) { client_raise(cc); } @@ -78,7 +78,7 @@ kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my) } void -kbfunc_ptrmove(struct client_ctx *cc, union arg *arg) +kbfunc_ptrmove(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; int x, y; @@ -91,7 +91,7 @@ kbfunc_ptrmove(struct client_ctx *cc, union arg *arg) } void -kbfunc_client_move(struct client_ctx *cc, union arg *arg) +kbfunc_client_move(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; struct geom area; @@ -144,7 +144,7 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg) } void -kbfunc_client_resize(struct client_ctx *cc, union arg *arg) +kbfunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) { unsigned int mx = 0, my = 0; int amt = 1; @@ -173,13 +173,13 @@ kbfunc_client_resize(struct client_ctx *cc, union arg *arg) } void -kbfunc_menu_client(struct client_ctx *cc, union arg *arg) +kbfunc_menu_client(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; struct client_ctx *old_cc; struct menu *mi; struct menu_q menuq; - int m = (arg->i == CWM_MOUSE); + int m = (xev == CWM_BTN); old_cc = client_current(); @@ -210,13 +210,13 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg) } void -kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) +kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; struct cmd *cmd; struct menu *mi; struct menu_q menuq; - int m = (arg->i == CWM_MOUSE); + int m = (xev == CWM_BTN); TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { @@ -239,13 +239,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) } void -kbfunc_menu_group(struct client_ctx *cc, union arg *arg) +kbfunc_menu_group(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; struct group_ctx *gc; struct menu *mi; struct menu_q menuq; - int m = (arg->i == CWM_MOUSE); + int m = (xev == CWM_BTN); TAILQ_INIT(&menuq); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -266,25 +266,25 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg) } void -kbfunc_client_cycle(struct client_ctx *cc, union arg *arg) +kbfunc_client_cycle(struct client_ctx *cc, union arg *arg, int xev) { client_cycle(cc->sc, arg->i); } void -kbfunc_client_hide(struct client_ctx *cc, union arg *arg) +kbfunc_client_hide(struct client_ctx *cc, union arg *arg, int xev) { client_hide(cc); } void -kbfunc_exec(struct client_ctx *cc, union arg *arg) +kbfunc_exec(struct client_ctx *cc, union arg *arg, int xev) { u_spawn(arg->c); } void -kbfunc_exec_term(struct client_ctx *cc, union arg *arg) +kbfunc_exec_term(struct client_ctx *cc, union arg *arg, int xev) { struct cmd *cmd; @@ -295,7 +295,7 @@ kbfunc_exec_term(struct client_ctx *cc, union arg *arg) } void -kbfunc_exec_lock(struct client_ctx *cc, union arg *arg) +kbfunc_exec_lock(struct client_ctx *cc, union arg *arg, int xev) { struct cmd *cmd; @@ -306,7 +306,7 @@ kbfunc_exec_lock(struct client_ctx *cc, union arg *arg) } void -kbfunc_menu_exec(struct client_ctx *cc, union arg *arg) +kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev) { #define NPATHS 256 struct screen_ctx *sc = cc->sc; @@ -389,7 +389,7 @@ out: } void -kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg) +kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg, int xev) { struct screen_ctx *sc = cc->sc; struct cmd *cmd; @@ -456,7 +456,7 @@ out: } void -kbfunc_client_label(struct client_ctx *cc, union arg *arg) +kbfunc_client_label(struct client_ctx *cc, union arg *arg, int xev) { struct menu *mi; struct menu_q menuq; @@ -475,39 +475,39 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg) } void -kbfunc_client_delete(struct client_ctx *cc, union arg *arg) +kbfunc_client_delete(struct client_ctx *cc, union arg *arg, int xev) { client_send_delete(cc); } void -kbfunc_group_toggle(struct client_ctx *cc, union arg *arg) +kbfunc_group_toggle(struct client_ctx *cc, union arg *arg, int xev) { group_hidetoggle(cc->sc, arg->i); } void -kbfunc_group_only(struct client_ctx *cc, union arg *arg) +kbfunc_group_only(struct client_ctx *cc, union arg *arg, int xev) { group_only(cc->sc, arg->i); } void -kbfunc_group_cycle(struct client_ctx *cc, union arg *arg) +kbfunc_group_cycle(struct client_ctx *cc, union arg *arg, int xev) { group_cycle(cc->sc, arg->i); } void -kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg) +kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg, int xev) { group_alltoggle(cc->sc); } void -kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg) +kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg, int xev) { - if (arg->i == CWM_KBD) { + if (xev == CWM_KEY) { /* For X apps that steal events. */ XGrabKeyboard(X_Dpy, cc->win, True, GrabModeAsync, GrabModeAsync, CurrentTime); @@ -517,55 +517,55 @@ kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg) } void -kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg) +kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg, int xev) { group_movetogroup(cc, arg->i); } void -kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_sticky(cc); } void -kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_fullscreen(cc); } void -kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_maximize(cc); } void -kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_vmaximize(cc); } void -kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_hmaximize(cc); } void -kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg) +kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg, int xev) { client_toggle_freeze(cc); } void -kbfunc_cwm_status(struct client_ctx *cc, union arg *arg) +kbfunc_cwm_status(struct client_ctx *cc, union arg *arg, int xev) { cwm_status = arg->i; } void -kbfunc_client_tile(struct client_ctx *cc, union arg *arg) +kbfunc_client_tile(struct client_ctx *cc, union arg *arg, int xev) { switch (arg->i) { case CWM_CLIENT_TILE_HORIZ: diff --git a/mousefunc.c b/mousefunc.c index 2bf19db..27b1d65 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -33,7 +33,7 @@ #include "calmwm.h" void -mousefunc_client_resize(struct client_ctx *cc, union arg *arg) +mousefunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) { XEvent ev; Time ltime = 0; @@ -88,7 +88,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) } void -mousefunc_client_move(struct client_ctx *cc, union arg *arg) +mousefunc_client_move(struct client_ctx *cc, union arg *arg, int xev) { XEvent ev; Time ltime = 0; diff --git a/xevents.c b/xevents.c index 3dab168..3388063 100644 --- a/xevents.c +++ b/xevents.c @@ -244,7 +244,7 @@ xev_handle_buttonpress(XEvent *ee) return; } - (*mb->callback)(cc, &mb->argument); + (*mb->callback)(cc, &mb->argument, CWM_BTN); } static void @@ -298,7 +298,7 @@ xev_handle_keypress(XEvent *ee) return; } - (*kb->callback)(cc, &kb->argument); + (*kb->callback)(cc, &kb->argument, CWM_KEY); } /* From 15bf703e1cb65dcad697f7e3637437e1b96169e2 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 6 Oct 2016 14:53:52 +0000 Subject: [PATCH 27/34] Rename 2 kbfunc to match closer to what they do --- calmwm.h | 6 +++--- conf.c | 6 +++--- kbfunc.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/calmwm.h b/calmwm.h index 6c5dfa3..7835448 100644 --- a/calmwm.h +++ b/calmwm.h @@ -459,10 +459,8 @@ void screen_assert_clients_within(struct screen_ctx *); void kbfunc_client_cycle(struct client_ctx *, union arg *, int); void kbfunc_client_delete(struct client_ctx *, union arg *, int); -void kbfunc_client_grouptoggle(struct client_ctx *, - union arg *, int); void kbfunc_client_hide(struct client_ctx *, union arg *, int); -void kbfunc_client_label(struct client_ctx *, union arg *, int); +void kbfunc_menu_client_label(struct client_ctx *, union arg *, int); void kbfunc_client_lower(struct client_ctx *, union arg *, int); void kbfunc_client_move(struct client_ctx *, union arg *, int); void kbfunc_client_movetogroup(struct client_ctx *, @@ -471,6 +469,8 @@ void kbfunc_client_raise(struct client_ctx *, union arg *, int); void kbfunc_client_rcycle(struct client_ctx *, union arg *, int); void kbfunc_client_resize(struct client_ctx *, union arg *, int); void kbfunc_client_tile(struct client_ctx *, union arg *, int); +void kbfunc_client_toggle_group(struct client_ctx *, + union arg *, int); void kbfunc_client_toggle_freeze(struct client_ctx *, union arg *, int); void kbfunc_client_toggle_fullscreen(struct client_ctx *, diff --git a/conf.c b/conf.c index 4d8a643..3d95fea 100644 --- a/conf.c +++ b/conf.c @@ -365,7 +365,7 @@ static const struct { {.i = CWM_CLIENT_CYCLE} }, { "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN, {.i = CWM_CLIENT_RCYCLE} }, - { "label", kbfunc_client_label, CWM_CONTEXT_CLIENT, {0} }, + { "label", kbfunc_menu_client_label, CWM_CONTEXT_CLIENT, {0} }, { "delete", kbfunc_client_delete, CWM_CONTEXT_CLIENT, {0} }, { "group1", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 1} }, { "group2", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 2} }, @@ -412,7 +412,7 @@ static const struct { {.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} }, { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT, {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} }, - { "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0}}, + { "grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CLIENT, {0} }, { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT, {0} }, @@ -488,7 +488,7 @@ static const struct { { "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} }, { "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} }, { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} }, - { "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0} }, + { "window_grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CLIENT, {0} }, { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} }, { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} }, { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} }, diff --git a/kbfunc.c b/kbfunc.c index 1e4f95b..5225e04 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -456,7 +456,7 @@ out: } void -kbfunc_client_label(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_client_label(struct client_ctx *cc, union arg *arg, int xev) { struct menu *mi; struct menu_q menuq; @@ -505,7 +505,7 @@ kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_client_toggle_group(struct client_ctx *cc, union arg *arg, int xev) { if (xev == CWM_KEY) { /* For X apps that steal events. */ From 38eac7d7e9d36243271eb7f968a3152c9eb0cfbc Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 12 Oct 2016 16:11:15 +0000 Subject: [PATCH 28/34] remove another unused proto --- calmwm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index 7835448..c8a7f70 100644 --- a/calmwm.h +++ b/calmwm.h @@ -466,7 +466,6 @@ void kbfunc_client_move(struct client_ctx *, union arg *, int); void kbfunc_client_movetogroup(struct client_ctx *, union arg *, int); void kbfunc_client_raise(struct client_ctx *, union arg *, int); -void kbfunc_client_rcycle(struct client_ctx *, union arg *, int); void kbfunc_client_resize(struct client_ctx *, union arg *, int); void kbfunc_client_tile(struct client_ctx *, union arg *, int); void kbfunc_client_toggle_group(struct client_ctx *, From 0bb1be86c69ea95103e1a6b38c093406a47cdb07 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 18 Oct 2016 17:03:30 +0000 Subject: [PATCH 29/34] Refactor callbacks to take a void * so as to not try and generalize into client_ctx in keypress and buttonpress event handlers; pass appropriate *ctx's based on context. While here, limit some globals, replace defines with appropriate variables and fix some naming. --- calmwm.c | 27 ++-- calmwm.h | 238 +++++++++++++++++------------------ client.c | 12 +- conf.c | 306 ++++++++++++++++++++++----------------------- group.c | 22 ++-- kbfunc.c | 348 ++++++++++++++++++++++++++-------------------------- mousefunc.c | 6 +- screen.c | 8 +- search.c | 4 +- xevents.c | 50 +++++--- 10 files changed, 512 insertions(+), 509 deletions(-) diff --git a/calmwm.c b/calmwm.c index a6c5bc4..25df3b8 100644 --- a/calmwm.c +++ b/calmwm.c @@ -36,18 +36,14 @@ #include "calmwm.h" -Display *X_Dpy; -Time Last_Event_Time = CurrentTime; -Atom cwmh[CWMH_NITEMS]; -Atom ewmh[EWMH_NITEMS]; - -struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq); - -int HasRandr, Randr_ev; -struct conf Conf; -const char *homedir; -char *wm_argv; -volatile sig_atomic_t cwm_status; +Display *X_Dpy; +Time Last_Event_Time = CurrentTime; +Atom cwmh[CWMH_NITEMS]; +Atom ewmh[EWMH_NITEMS]; +struct screen_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq); +struct conf Conf; +const char *homedir; +volatile sig_atomic_t cwm_status; static void sighdlr(int); static int x_errorhandler(Display *, XErrorEvent *); @@ -67,7 +63,7 @@ main(int argc, char **argv) warnx("no locale support"); mbtowc(NULL, NULL, MB_CUR_MAX); - wm_argv = u_argv(argv); + Conf.wm_argv = u_argv(argv); while ((ch = getopt(argc, argv, "c:d:")) != -1) { switch (ch) { case 'c': @@ -107,6 +103,7 @@ main(int argc, char **argv) } conf_init(&Conf); + if (conf_path && (parse_config(conf_path, &Conf) == -1)) warnx("config file %s has errors", conf_path); free(conf_path); @@ -121,7 +118,7 @@ main(int argc, char **argv) xev_process(); x_teardown(); if (cwm_status == CWM_EXEC_WM) - u_exec(wm_argv); + u_exec(Conf.wm_argv); return(0); } @@ -139,7 +136,7 @@ x_init(const char *dpyname) XSync(X_Dpy, False); XSetErrorHandler(x_errorhandler); - HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i); + Conf.xrandr = XRRQueryExtension(X_Dpy, &Conf.xrandr_event_base, &i); conf_atoms(); conf_cursor(&Conf); diff --git a/calmwm.h b/calmwm.h index c8a7f70..f6542a7 100644 --- a/calmwm.h +++ b/calmwm.h @@ -57,41 +57,14 @@ #define CWM_BIGAMOUNT 0x0010 #define DIRECTIONMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT) -#define CWM_CLIENT_CYCLE 0x0001 -#define CWM_CLIENT_RCYCLE 0x0002 -#define CWM_CLIENT_CYCLE_INGRP 0x0004 +#define CWM_CYCLE_FORWARD 0x0001 +#define CWM_CYCLE_REVERSE 0x0002 +#define CWM_CYCLE_INGROUP 0x0004 -#define CWM_CLIENT_TILE_HORIZ 0x0001 -#define CWM_CLIENT_TILE_VERT 0x0002 - -#define CWM_MENU_EXEC 0x0001 -#define CWM_MENU_EXEC_WM 0x0002 - -#define CWM_MENU_DUMMY 0x0001 -#define CWM_MENU_FILE 0x0002 -#define CWM_MENU_LIST 0x0004 - -#define CWM_GAP 0x0001 -#define CWM_NOGAP 0x0002 - -#define CWM_KEY 0x0001 -#define CWM_BTN 0x0002 - -#define CWM_CONTEXT_NONE 0x0000 -#define CWM_CONTEXT_CLIENT 0x0001 -#define CWM_CONTEXT_SCREEN 0x0002 - -#define CWM_QUIT 0x0000 -#define CWM_RUNNING 0x0001 -#define CWM_EXEC_WM 0x0002 - -union arg { - char *c; - int i; -}; -union press { - KeySym keysym; - unsigned int button; +enum cwm_status { + CWM_QUIT, + CWM_RUNNING, + CWM_EXEC_WM }; enum cursor_font { @@ -121,6 +94,10 @@ struct geom { int h; }; +enum apply_gap { + CWM_NOGAP = 0, + CWM_GAP +}; struct gap { int top; int bottom; @@ -132,7 +109,7 @@ struct winname { TAILQ_ENTRY(winname) entry; char *name; }; -TAILQ_HEAD(winname_q, winname); +TAILQ_HEAD(name_q, winname); TAILQ_HEAD(ignore_q, winname); struct client_ctx { @@ -185,31 +162,31 @@ struct client_ctx { #define CLIENT_MAXIMIZED (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED) int flags; int stackingorder; - struct winname_q nameq; + struct name_q nameq; char *name; char *label; char *matchname; XClassHint ch; XWMHints *wmh; }; -TAILQ_HEAD(client_ctx_q, client_ctx); +TAILQ_HEAD(client_q, client_ctx); struct group_ctx { TAILQ_ENTRY(group_ctx) entry; struct screen_ctx *sc; char *name; int num; - struct client_ctx_q clientq; + struct client_q clientq; }; -TAILQ_HEAD(group_ctx_q, group_ctx); +TAILQ_HEAD(group_q, group_ctx); -struct autogroupwin { - TAILQ_ENTRY(autogroupwin) entry; - char *class; - char *name; - int num; +struct autogroup { + TAILQ_ENTRY(autogroup) entry; + char *class; + char *name; + int num; }; -TAILQ_HEAD(autogroupwin_q, autogroupwin); +TAILQ_HEAD(autogroup_q, autogroup); struct region_ctx { TAILQ_ENTRY(region_ctx) entry; @@ -218,7 +195,7 @@ struct region_ctx { struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ }; -TAILQ_HEAD(region_ctx_q, region_ctx); +TAILQ_HEAD(region_q, region_ctx); struct screen_ctx { TAILQ_ENTRY(screen_ctx) entry; @@ -230,9 +207,9 @@ struct screen_ctx { struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ struct gap gap; - struct client_ctx_q clientq; - struct region_ctx_q regionq; - struct group_ctx_q groupq; + struct client_q clientq; + struct region_q regionq; + struct group_q groupq; struct group_ctx *group_active; struct { Window win; @@ -241,25 +218,50 @@ struct screen_ctx { XftColor xftcolor[CWM_COLOR_NITEMS]; XftFont *xftfont; }; -TAILQ_HEAD(screen_ctx_q, screen_ctx); +TAILQ_HEAD(screen_q, screen_ctx); -struct binding { - TAILQ_ENTRY(binding) entry; - void (*callback)(struct client_ctx *, union arg *, int); +enum xev { + CWM_XEV_KEY, + CWM_XEV_BTN +}; +union arg { + char *c; + int i; +}; +union press { + KeySym keysym; + unsigned int button; +}; +enum context { + CWM_CONTEXT_NONE, + CWM_CONTEXT_CC, + CWM_CONTEXT_SC +}; +struct bind_ctx { + TAILQ_ENTRY(bind_ctx) entry; + void (*callback)(void *, union arg *, enum xev); union arg argument; unsigned int modmask; union press press; - int context; + enum context context; }; -TAILQ_HEAD(keybinding_q, binding); -TAILQ_HEAD(mousebinding_q, binding); +TAILQ_HEAD(keybind_q, bind_ctx); +TAILQ_HEAD(mousebind_q, bind_ctx); -struct cmd { - TAILQ_ENTRY(cmd) entry; +struct cmd_ctx { + TAILQ_ENTRY(cmd_ctx) entry; char *name; char path[PATH_MAX]; }; -TAILQ_HEAD(cmd_q, cmd); +TAILQ_HEAD(cmd_q, cmd_ctx); + +enum menu_exec { + CWM_MENU_EXEC_EXEC, + CWM_MENU_EXEC_WM +}; +#define CWM_MENU_DUMMY 0x0001 +#define CWM_MENU_FILE 0x0002 +#define CWM_MENU_LIST 0x0004 struct menu { TAILQ_ENTRY(menu) entry; @@ -274,9 +276,9 @@ struct menu { TAILQ_HEAD(menu_q, menu); struct conf { - struct keybinding_q keybindingq; - struct mousebinding_q mousebindingq; - struct autogroupwin_q autogroupq; + struct keybind_q keybindq; + struct mousebind_q mousebindq; + struct autogroup_q autogroupq; struct ignore_q ignoreq; struct cmd_q cmdq; int ngroups; @@ -291,6 +293,9 @@ struct conf { char *font; char *wmname; Cursor cursor[CF_NITEMS]; + int xrandr; + int xrandr_event_base; + char *wm_argv; }; /* MWM hints */ @@ -321,15 +326,7 @@ struct mwm_hints { unsigned long decorations; }; -extern Display *X_Dpy; -extern Time Last_Event_Time; -extern struct screen_ctx_q Screenq; -extern struct conf Conf; -extern char *wm_argv; -extern const char *homedir; -extern int HasRandr, Randr_ev; - -enum { +enum cwmh { WM_STATE, WM_DELETE_WINDOW, WM_TAKE_FOCUS, @@ -339,7 +336,7 @@ enum { WM_CHANGE_STATE, CWMH_NITEMS }; -enum { +enum ewmh { _NET_SUPPORTED, _NET_SUPPORTING_WM_CHECK, _NET_ACTIVE_WINDOW, @@ -367,13 +364,19 @@ enum { _CWM_WM_STATE_FREEZE, EWMH_NITEMS }; -enum { +enum net_wm_state { _NET_WM_STATE_REMOVE, _NET_WM_STATE_ADD, _NET_WM_STATE_TOGGLE }; + +extern Display *X_Dpy; +extern Time Last_Event_Time; extern Atom cwmh[CWMH_NITEMS]; extern Atom ewmh[EWMH_NITEMS]; +extern struct screen_q Screenq; +extern struct conf Conf; +extern const char *homedir; __dead void usage(void); @@ -451,57 +454,56 @@ void search_print_group(struct menu *, int); struct region_ctx *region_find(struct screen_ctx *, int, int); struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); -struct geom screen_area(struct screen_ctx *, int, int, int); +struct geom screen_area(struct screen_ctx *, int, int, + enum apply_gap); void screen_init(int); void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); void screen_assert_clients_within(struct screen_ctx *); -void kbfunc_client_cycle(struct client_ctx *, union arg *, int); -void kbfunc_client_delete(struct client_ctx *, union arg *, int); -void kbfunc_client_hide(struct client_ctx *, union arg *, int); -void kbfunc_menu_client_label(struct client_ctx *, union arg *, int); -void kbfunc_client_lower(struct client_ctx *, union arg *, int); -void kbfunc_client_move(struct client_ctx *, union arg *, int); -void kbfunc_client_movetogroup(struct client_ctx *, - union arg *, int); -void kbfunc_client_raise(struct client_ctx *, union arg *, int); -void kbfunc_client_resize(struct client_ctx *, union arg *, int); -void kbfunc_client_tile(struct client_ctx *, union arg *, int); -void kbfunc_client_toggle_group(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_freeze(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_fullscreen(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_hmaximize(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_maximize(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_sticky(struct client_ctx *, - union arg *, int); -void kbfunc_client_toggle_vmaximize(struct client_ctx *, - union arg *, int); -void kbfunc_cwm_status(struct client_ctx *, union arg *, int); -void kbfunc_exec(struct client_ctx *, union arg *, int); -void kbfunc_exec_lock(struct client_ctx *, union arg *, int); -void kbfunc_exec_term(struct client_ctx *, union arg *, int); -void kbfunc_group_alltoggle(struct client_ctx *, - union arg *, int); -void kbfunc_group_cycle(struct client_ctx *, union arg *, int); -void kbfunc_group_only(struct client_ctx *, union arg *, int); -void kbfunc_group_toggle(struct client_ctx *, union arg *, int); -void kbfunc_menu_exec(struct client_ctx *, union arg *, int); -void kbfunc_menu_client(struct client_ctx *, union arg *, int); -void kbfunc_menu_cmd(struct client_ctx *, union arg *, int); -void kbfunc_menu_group(struct client_ctx *, union arg *, int); -void kbfunc_menu_ssh(struct client_ctx *, union arg *, int); -void kbfunc_ptrmove(struct client_ctx *, union arg *, int); +void kbfunc_cwm_status(void *, union arg *, enum xev); +void kbfunc_ptrmove(void *, union arg *, enum xev); +void kbfunc_client_move(void *, union arg *, enum xev); +void kbfunc_client_resize(void *, union arg *, enum xev); +void kbfunc_client_delete(void *, union arg *, enum xev); +void kbfunc_client_lower(void *, union arg *, enum xev); +void kbfunc_client_raise(void *, union arg *, enum xev); +void kbfunc_client_hide(void *, union arg *, enum xev); +void kbfunc_client_toggle_freeze(void *, + union arg *, enum xev); +void kbfunc_client_toggle_sticky(void *, + union arg *, enum xev); +void kbfunc_client_toggle_fullscreen(void *, + union arg *, enum xev); +void kbfunc_client_toggle_maximize(void *, + union arg *, enum xev); +void kbfunc_client_toggle_hmaximize(void *, + union arg *, enum xev); +void kbfunc_client_toggle_vmaximize(void *, + union arg *, enum xev); +void kbfunc_client_htile(void *, union arg *, enum xev); +void kbfunc_client_vtile(void *, union arg *, enum xev); +void kbfunc_client_cycle(void *, union arg *, enum xev); +void kbfunc_client_toggle_group(void *, + union arg *, enum xev); +void kbfunc_client_movetogroup(void *, + union arg *, enum xev); +void kbfunc_group_toggle(void *, union arg *, enum xev); +void kbfunc_group_only(void *, union arg *, enum xev); +void kbfunc_group_cycle(void *, union arg *, enum xev); +void kbfunc_group_alltoggle(void *, union arg *, enum xev); +void kbfunc_menu_client(void *, union arg *, enum xev); +void kbfunc_menu_cmd(void *, union arg *, enum xev); +void kbfunc_menu_group(void *, union arg *, enum xev); +void kbfunc_menu_exec(void *, union arg *, enum xev); +void kbfunc_menu_ssh(void *, union arg *, enum xev); +void kbfunc_menu_client_label(void *, union arg *, enum xev); +void kbfunc_exec_cmd(void *, union arg *, enum xev); +void kbfunc_exec_lock(void *, union arg *, enum xev); +void kbfunc_exec_term(void *, union arg *, enum xev); -void mousefunc_client_move(struct client_ctx *, - union arg *, int); -void mousefunc_client_resize(struct client_ctx *, - union arg *, int); +void mousefunc_client_move(void *, union arg *, enum xev); +void mousefunc_client_resize(void *, union arg *, enum xev); void menu_windraw(struct screen_ctx *, Window, const char *, ...); diff --git a/client.c b/client.c index ab84b9a..58d7f88 100644 --- a/client.c +++ b/client.c @@ -653,20 +653,20 @@ client_cycle(struct screen_ctx *sc, int flags) oldcc = client_current(); if (oldcc == NULL) - oldcc = (flags & CWM_CLIENT_RCYCLE) ? - TAILQ_LAST(&sc->clientq, client_ctx_q) : + oldcc = (flags & CWM_CYCLE_REVERSE) ? + TAILQ_LAST(&sc->clientq, client_q) : TAILQ_FIRST(&sc->clientq); newcc = oldcc; while (again) { again = 0; - newcc = (flags & CWM_CLIENT_RCYCLE) ? client_prev(newcc) : + newcc = (flags & CWM_CYCLE_REVERSE) ? client_prev(newcc) : client_next(newcc); /* Only cycle visible and non-ignored windows. */ if ((newcc->flags & (CLIENT_HIDDEN | CLIENT_IGNORE)) - || ((flags & CWM_CLIENT_CYCLE_INGRP) && + || ((flags & CWM_CYCLE_INGROUP) && (newcc->gc != oldcc->gc))) again = 1; @@ -721,8 +721,8 @@ client_prev(struct client_ctx *cc) struct screen_ctx *sc = cc->sc; struct client_ctx *newcc; - return(((newcc = TAILQ_PREV(cc, client_ctx_q, entry)) != NULL) ? - newcc : TAILQ_LAST(&sc->clientq, client_ctx_q)); + return(((newcc = TAILQ_PREV(cc, client_q, entry)) != NULL) ? + newcc : TAILQ_LAST(&sc->clientq, client_q)); } static void diff --git a/conf.c b/conf.c index 3d95fea..156bb71 100644 --- a/conf.c +++ b/conf.c @@ -34,13 +34,13 @@ static const char *conf_bind_getmask(const char *, unsigned int *); static void conf_cmd_remove(struct conf *, const char *); -static void conf_unbind_kbd(struct conf *, struct binding *); -static void conf_unbind_mouse(struct conf *, struct binding *); +static void conf_unbind_kbd(struct conf *, struct bind_ctx *); +static void conf_unbind_mouse(struct conf *, struct bind_ctx *); int conf_cmd_add(struct conf *c, const char *name, const char *path) { - struct cmd *cmd; + struct cmd_ctx *cmd; cmd = xmalloc(sizeof(*cmd)); @@ -61,7 +61,7 @@ conf_cmd_add(struct conf *c, const char *name, const char *path) static void conf_cmd_remove(struct conf *c, const char *name) { - struct cmd *cmd = NULL, *cmdnxt; + struct cmd_ctx *cmd = NULL, *cmdnxt; TAILQ_FOREACH_SAFE(cmd, &c->cmdq, entry, cmdnxt) { if (strcmp(cmd->name, name) == 0) { @@ -74,31 +74,31 @@ conf_cmd_remove(struct conf *c, const char *name) void conf_autogroup(struct conf *c, int num, const char *name, const char *class) { - struct autogroupwin *aw; + struct autogroup *ag; char *p; - aw = xmalloc(sizeof(*aw)); + ag = xmalloc(sizeof(*ag)); if ((p = strchr(class, ',')) == NULL) { if (name == NULL) - aw->name = NULL; + ag->name = NULL; else - aw->name = xstrdup(name); + ag->name = xstrdup(name); - aw->class = xstrdup(class); + ag->class = xstrdup(class); } else { *(p++) = '\0'; if (name == NULL) - aw->name = xstrdup(class); + ag->name = xstrdup(class); else - aw->name = xstrdup(name); + ag->name = xstrdup(name); - aw->class = xstrdup(p); + ag->class = xstrdup(p); } - aw->num = num; + ag->num = num; - TAILQ_INSERT_TAIL(&c->autogroupq, aw, entry); + TAILQ_INSERT_TAIL(&c->autogroupq, ag, entry); } void @@ -264,9 +264,9 @@ conf_init(struct conf *c) TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->cmdq); - TAILQ_INIT(&c->keybindingq); + TAILQ_INIT(&c->keybindq); TAILQ_INIT(&c->autogroupq); - TAILQ_INIT(&c->mousebindingq); + TAILQ_INIT(&c->mousebindq); for (i = 0; i < nitems(kbd_binds); i++) conf_bind_kbd(c, kbd_binds[i].key, kbd_binds[i].func); @@ -290,10 +290,10 @@ conf_init(struct conf *c) void conf_clear(struct conf *c) { - struct autogroupwin *aw; - struct binding *kb, *mb; + struct autogroup *ag; + struct bind_ctx *kb, *mb; struct winname *wn; - struct cmd *cmd; + struct cmd_ctx *cmd; int i; while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) { @@ -302,16 +302,16 @@ conf_clear(struct conf *c) free(cmd); } - while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) { - TAILQ_REMOVE(&c->keybindingq, kb, entry); + while ((kb = TAILQ_FIRST(&c->keybindq)) != NULL) { + TAILQ_REMOVE(&c->keybindq, kb, entry); free(kb); } - while ((aw = TAILQ_FIRST(&c->autogroupq)) != NULL) { - TAILQ_REMOVE(&c->autogroupq, aw, entry); - free(aw->class); - free(aw->name); - free(aw); + while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) { + TAILQ_REMOVE(&c->autogroupq, ag, entry); + free(ag->class); + free(ag->name); + free(ag); } while ((wn = TAILQ_FIRST(&c->ignoreq)) != NULL) { @@ -320,8 +320,8 @@ conf_clear(struct conf *c) free(wn); } - while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) { - TAILQ_REMOVE(&c->mousebindingq, mb, entry); + while ((mb = TAILQ_FIRST(&c->mousebindq)) != NULL) { + TAILQ_REMOVE(&c->mousebindq, mb, entry); free(mb); } @@ -351,147 +351,133 @@ conf_client(struct client_ctx *cc) static const struct { const char *tag; - void (*handler)(struct client_ctx *, union arg *, int); + void (*handler)(void *, union arg *, enum xev); int context; union arg argument; } name_to_func[] = { - { "lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} }, - { "raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} }, - { "search", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} }, - { "menusearch", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} }, - { "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} }, - { "hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} }, - { "cycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN, - {.i = CWM_CLIENT_CYCLE} }, - { "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN, - {.i = CWM_CLIENT_RCYCLE} }, - { "label", kbfunc_menu_client_label, CWM_CONTEXT_CLIENT, {0} }, - { "delete", kbfunc_client_delete, CWM_CONTEXT_CLIENT, {0} }, - { "group1", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 1} }, - { "group2", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 2} }, - { "group3", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 3} }, - { "group4", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 4} }, - { "group5", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 5} }, - { "group6", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 6} }, - { "group7", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 7} }, - { "group8", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 8} }, - { "group9", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 9} }, - { "grouponly1", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 1} }, - { "grouponly2", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 2} }, - { "grouponly3", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 3} }, - { "grouponly4", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 4} }, - { "grouponly5", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 5} }, - { "grouponly6", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 6} }, - { "grouponly7", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 7} }, - { "grouponly8", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 8} }, - { "grouponly9", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 9} }, - { "movetogroup1", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 1} }, - { "movetogroup2", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 2} }, - { "movetogroup3", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 3} }, - { "movetogroup4", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 4} }, - { "movetogroup5", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 5} }, - { "movetogroup6", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 6} }, - { "movetogroup7", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 7} }, - { "movetogroup8", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 8} }, - { "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT, - {.i = 9} }, - { "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SCREEN, {0} }, - { "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN, - {.i = CWM_CLIENT_CYCLE} }, - { "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN, - {.i = CWM_CLIENT_RCYCLE} }, - { "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT, - {.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} }, - { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT, - {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} }, - { "grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CLIENT, {0} }, - { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, - { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT, - {0} }, - { "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CLIENT, {0} }, - { "vmaximize", kbfunc_client_toggle_vmaximize, CWM_CONTEXT_CLIENT, - {0} }, - { "hmaximize", kbfunc_client_toggle_hmaximize, CWM_CONTEXT_CLIENT, - {0} }, - { "freeze", kbfunc_client_toggle_freeze, CWM_CONTEXT_CLIENT, {0} }, - { "restart", kbfunc_cwm_status, CWM_CONTEXT_SCREEN, - {.i = CWM_EXEC_WM} }, - { "quit", kbfunc_cwm_status, CWM_CONTEXT_SCREEN, {.i = CWM_QUIT} }, - { "exec", kbfunc_menu_exec, CWM_CONTEXT_SCREEN, {.i = CWM_MENU_EXEC} }, - { "exec_wm", kbfunc_menu_exec, CWM_CONTEXT_SCREEN, + { "lower", kbfunc_client_lower, CWM_CONTEXT_CC, {0} }, + { "raise", kbfunc_client_raise, CWM_CONTEXT_CC, {0} }, + { "search", kbfunc_menu_client, CWM_CONTEXT_SC, {0} }, + { "menusearch", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} }, + { "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SC, {0} }, + { "hide", kbfunc_client_hide, CWM_CONTEXT_CC, {0} }, + { "cycle", kbfunc_client_cycle, CWM_CONTEXT_SC, + {.i = CWM_CYCLE_FORWARD} }, + { "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SC, + {.i = CWM_CYCLE_REVERSE} }, + { "label", kbfunc_menu_client_label, CWM_CONTEXT_CC, {0} }, + { "delete", kbfunc_client_delete, CWM_CONTEXT_CC, {0} }, + { "group1", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 1} }, + { "group2", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 2} }, + { "group3", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 3} }, + { "group4", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 4} }, + { "group5", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 5} }, + { "group6", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 6} }, + { "group7", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 7} }, + { "group8", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 8} }, + { "group9", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 9} }, + { "grouponly1", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 1} }, + { "grouponly2", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 2} }, + { "grouponly3", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 3} }, + { "grouponly4", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 4} }, + { "grouponly5", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 5} }, + { "grouponly6", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 6} }, + { "grouponly7", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 7} }, + { "grouponly8", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 8} }, + { "grouponly9", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 9} }, + { "movetogroup1", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 1} }, + { "movetogroup2", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 2} }, + { "movetogroup3", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 3} }, + { "movetogroup4", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 4} }, + { "movetogroup5", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 5} }, + { "movetogroup6", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 6} }, + { "movetogroup7", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 7} }, + { "movetogroup8", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 8} }, + { "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 9} }, + { "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SC, {0} }, + { "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC, + {.i = CWM_CYCLE_FORWARD} }, + { "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC, + {.i = CWM_CYCLE_REVERSE} }, + { "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC, + {.i = (CWM_CYCLE_FORWARD | CWM_CYCLE_INGROUP)} }, + { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC, + {.i = (CWM_CYCLE_REVERSE | CWM_CYCLE_INGROUP)} }, + { "grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CC, {0} }, + { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CC, {0} }, + { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CC, {0} }, + { "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CC, {0} }, + { "vmaximize", kbfunc_client_toggle_vmaximize, CWM_CONTEXT_CC, {0} }, + { "hmaximize", kbfunc_client_toggle_hmaximize, CWM_CONTEXT_CC, {0} }, + { "freeze", kbfunc_client_toggle_freeze, CWM_CONTEXT_CC, {0} }, + { "restart", kbfunc_cwm_status, CWM_CONTEXT_SC, {.i = CWM_EXEC_WM} }, + { "quit", kbfunc_cwm_status, CWM_CONTEXT_SC, {.i = CWM_QUIT} }, + { "exec", kbfunc_menu_exec, CWM_CONTEXT_SC, + {.i = CWM_MENU_EXEC_EXEC} }, + { "exec_wm", kbfunc_menu_exec, CWM_CONTEXT_SC, {.i = CWM_MENU_EXEC_WM} }, - { "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SCREEN, {0} }, - { "terminal", kbfunc_exec_term, CWM_CONTEXT_SCREEN, {0} }, - { "lock", kbfunc_exec_lock, CWM_CONTEXT_SCREEN, {0} }, - { "moveup", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SC, {0} }, + { "terminal", kbfunc_exec_term, CWM_CONTEXT_SC, {0} }, + { "lock", kbfunc_exec_lock, CWM_CONTEXT_SC, {0} }, + { "moveup", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_UP)} }, - { "movedown", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "movedown", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_DOWN)} }, - { "moveright", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "moveright", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_RIGHT)} }, - { "moveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "moveleft", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_LEFT)} }, - { "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_UP | CWM_BIGAMOUNT)} }, - { "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} }, - { "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} }, - { "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT, + { "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CC, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} }, - { "resizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "resizeup", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_UP)} }, - { "resizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "resizedown", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_DOWN)} }, - { "resizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "resizeright", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_RIGHT)} }, - { "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_LEFT)} }, - { "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_UP | CWM_BIGAMOUNT)} }, - { "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} }, - { "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} }, - { "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT, + { "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CC, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} }, - { "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_UP)} }, - { "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_DOWN)} }, - { "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_LEFT)} }, - { "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_RIGHT)} }, - { "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_UP | CWM_BIGAMOUNT)} }, - { "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_DOWN | CWM_BIGAMOUNT)} }, - { "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_LEFT | CWM_BIGAMOUNT)} }, - { "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN, + { "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SC, {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} }, - { "htile", kbfunc_client_tile, CWM_CONTEXT_CLIENT, - {.i = CWM_CLIENT_TILE_HORIZ} }, - { "vtile", kbfunc_client_tile, CWM_CONTEXT_CLIENT, - {.i = CWM_CLIENT_TILE_VERT} }, - { "window_lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} }, - { "window_raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} }, - { "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} }, - { "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} }, - { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} }, - { "window_grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CLIENT, {0} }, - { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} }, - { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} }, - { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} }, + { "htile", kbfunc_client_htile, CWM_CONTEXT_CC, {0} }, + { "vtile", kbfunc_client_vtile, CWM_CONTEXT_CC, {0} }, + { "window_lower", kbfunc_client_lower, CWM_CONTEXT_CC, {0} }, + { "window_raise", kbfunc_client_raise, CWM_CONTEXT_CC, {0} }, + { "window_hide", kbfunc_client_hide, CWM_CONTEXT_CC, {0} }, + { "window_move", mousefunc_client_move, CWM_CONTEXT_CC, {0} }, + { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CC, {0} }, + { "window_grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CC, {0} }, + { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SC, {0} }, + { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SC, {0} }, + { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} }, }; static const struct { @@ -526,7 +512,7 @@ conf_bind_getmask(const char *name, unsigned int *mask) int conf_bind_kbd(struct conf *c, const char *bind, const char *cmd) { - struct binding *kb; + struct bind_ctx *kb; const char *key; unsigned int i; @@ -555,28 +541,28 @@ conf_bind_kbd(struct conf *c, const char *bind, const char *cmd) kb->callback = name_to_func[i].handler; kb->context = name_to_func[i].context; kb->argument = name_to_func[i].argument; - TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry); + TAILQ_INSERT_TAIL(&c->keybindq, kb, entry); return(1); } - kb->callback = kbfunc_exec; + kb->callback = kbfunc_exec_cmd; kb->context = CWM_CONTEXT_NONE; kb->argument.c = xstrdup(cmd); - TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry); + TAILQ_INSERT_TAIL(&c->keybindq, kb, entry); return(1); } static void -conf_unbind_kbd(struct conf *c, struct binding *unbind) +conf_unbind_kbd(struct conf *c, struct bind_ctx *unbind) { - struct binding *key = NULL, *keynxt; + struct bind_ctx *key = NULL, *keynxt; - TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) { + TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) { if (key->modmask != unbind->modmask) continue; if (key->press.keysym == unbind->press.keysym) { - TAILQ_REMOVE(&c->keybindingq, key, entry); + TAILQ_REMOVE(&c->keybindq, key, entry); if (key->context == CWM_CONTEXT_NONE) free(key->argument.c); free(key); @@ -587,7 +573,7 @@ conf_unbind_kbd(struct conf *c, struct binding *unbind) int conf_bind_mouse(struct conf *c, const char *bind, const char *cmd) { - struct binding *mb; + struct bind_ctx *mb; const char *button, *errstr; unsigned int i; @@ -616,7 +602,7 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd) mb->callback = name_to_func[i].handler; mb->context = name_to_func[i].context; mb->argument = name_to_func[i].argument; - TAILQ_INSERT_TAIL(&c->mousebindingq, mb, entry); + TAILQ_INSERT_TAIL(&c->mousebindq, mb, entry); return(1); } @@ -624,16 +610,16 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd) } static void -conf_unbind_mouse(struct conf *c, struct binding *unbind) +conf_unbind_mouse(struct conf *c, struct bind_ctx *unbind) { - struct binding *mb = NULL, *mbnxt; + struct bind_ctx *mb = NULL, *mbnxt; - TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) { + TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) { if (mb->modmask != unbind->modmask) continue; if (mb->press.button == unbind->press.button) { - TAILQ_REMOVE(&c->mousebindingq, mb, entry); + TAILQ_REMOVE(&c->mousebindq, mb, entry); free(mb); } } @@ -660,13 +646,13 @@ static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; void conf_grab_mouse(Window win) { - struct binding *mb; + struct bind_ctx *mb; unsigned int i; XUngrabButton(X_Dpy, AnyButton, AnyModifier, win); - TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { - if (mb->context != CWM_CONTEXT_CLIENT) + TAILQ_FOREACH(mb, &Conf.mousebindq, entry) { + if (mb->context != CWM_CONTEXT_CC) continue; for (i = 0; i < nitems(ign_mods); i++) { XGrabButton(X_Dpy, mb->press.button, @@ -681,13 +667,13 @@ conf_grab_mouse(Window win) void conf_grab_kbd(Window win) { - struct binding *kb; + struct bind_ctx *kb; KeyCode kc; unsigned int i; XUngrabKey(X_Dpy, AnyKey, AnyModifier, win); - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) { + TAILQ_FOREACH(kb, &Conf.keybindq, entry) { kc = XKeysymToKeycode(X_Dpy, kb->press.keysym); if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) && (XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym)) diff --git a/group.c b/group.c index 36fd397..ec368de 100644 --- a/group.c +++ b/group.c @@ -265,7 +265,7 @@ group_cycle(struct screen_ctx *sc, int flags) newgc = oldgc; for (;;) { - newgc = (flags & CWM_CLIENT_RCYCLE) ? group_prev(newgc) : + newgc = (flags & CWM_CYCLE_REVERSE) ? group_prev(newgc) : group_next(newgc); if (newgc == oldgc) @@ -304,8 +304,8 @@ group_prev(struct group_ctx *gc) struct screen_ctx *sc = gc->sc; struct group_ctx *newgc; - return(((newgc = TAILQ_PREV(gc, group_ctx_q, entry)) != NULL) ? - newgc : TAILQ_LAST(&sc->groupq, group_ctx_q)); + return(((newgc = TAILQ_PREV(gc, group_q, entry)) != NULL) ? + newgc : TAILQ_LAST(&sc->groupq, group_q)); } void @@ -351,21 +351,21 @@ int group_autogroup(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct autogroupwin *aw; + struct autogroup *ag; struct group_ctx *gc; int num = -1, both_match = 0; if (cc->ch.res_class == NULL || cc->ch.res_name == NULL) return(0); - TAILQ_FOREACH(aw, &Conf.autogroupq, entry) { - if (strcmp(aw->class, cc->ch.res_class) == 0) { - if ((aw->name != NULL) && - (strcmp(aw->name, cc->ch.res_name) == 0)) { - num = aw->num; + TAILQ_FOREACH(ag, &Conf.autogroupq, entry) { + if (strcmp(ag->class, cc->ch.res_class) == 0) { + if ((ag->name != NULL) && + (strcmp(ag->name, cc->ch.res_name) == 0)) { + num = ag->num; both_match = 1; - } else if (aw->name == NULL && !both_match) - num = aw->num; + } else if (ag->name == NULL && !both_match) + num = ag->num; } } diff --git a/kbfunc.c b/kbfunc.c index 5225e04..ef2334f 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -41,16 +41,9 @@ extern sig_atomic_t cwm_status; static void kbfunc_amount(int, int, unsigned int *, unsigned int *); void -kbfunc_client_lower(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_cwm_status(void *ctx, union arg *arg, enum xev xev) { - client_ptrsave(cc); - client_lower(cc); -} - -void -kbfunc_client_raise(struct client_ctx *cc, union arg *arg, int xev) -{ - client_raise(cc); + cwm_status = arg->i; } static void @@ -78,9 +71,9 @@ kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my) } void -kbfunc_ptrmove(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_ptrmove(void *ctx, union arg *arg, enum xev xev) { - struct screen_ctx *sc = cc->sc; + struct screen_ctx *sc = ctx; int x, y; unsigned int mx = 0, my = 0; @@ -91,8 +84,9 @@ kbfunc_ptrmove(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_client_move(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_client_move(void *ctx, union arg *arg, enum xev xev) { + struct client_ctx *cc = ctx; struct screen_ctx *sc = cc->sc; struct geom area; int x, y, px, py; @@ -144,8 +138,9 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_client_resize(void *ctx, union arg *arg, enum xev xev) { + struct client_ctx *cc = ctx; unsigned int mx = 0, my = 0; int amt = 1; @@ -173,13 +168,136 @@ kbfunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_menu_client(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_client_delete(void *ctx, union arg *arg, enum xev xev) { - struct screen_ctx *sc = cc->sc; - struct client_ctx *old_cc; + client_send_delete(ctx); +} + +void +kbfunc_client_lower(void *ctx, union arg *arg, enum xev xev) +{ + client_ptrsave(ctx); + client_lower(ctx); +} + +void +kbfunc_client_raise(void *ctx, union arg *arg, enum xev xev) +{ + client_raise(ctx); +} + +void +kbfunc_client_hide(void *ctx, union arg *arg, enum xev xev) +{ + client_hide(ctx); +} + +void +kbfunc_client_toggle_freeze(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_freeze(ctx); +} + +void +kbfunc_client_toggle_sticky(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_sticky(ctx); +} + +void +kbfunc_client_toggle_fullscreen(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_fullscreen(ctx); +} + +void +kbfunc_client_toggle_maximize(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_maximize(ctx); +} + +void +kbfunc_client_toggle_hmaximize(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_hmaximize(ctx); +} + +void +kbfunc_client_toggle_vmaximize(void *ctx, union arg *arg, enum xev xev) +{ + client_toggle_vmaximize(ctx); +} + +void +kbfunc_client_htile(void *ctx, union arg *arg, enum xev xev) +{ + client_htile(ctx); +} + +void +kbfunc_client_vtile(void *ctx, union arg *arg, enum xev xev) +{ + client_vtile(ctx); +} + +void +kbfunc_client_cycle(void *ctx, union arg *arg, enum xev xev) +{ + client_cycle(ctx, arg->i); +} + +void +kbfunc_client_toggle_group(void *ctx, union arg *arg, enum xev xev) +{ + struct client_ctx *cc = ctx; + + if (xev == CWM_XEV_KEY) { + /* For X apps that steal events. */ + XGrabKeyboard(X_Dpy, cc->win, True, + GrabModeAsync, GrabModeAsync, CurrentTime); + } + + group_toggle_membership_enter(cc); +} + +void +kbfunc_client_movetogroup(void *ctx, union arg *arg, enum xev xev) +{ + group_movetogroup(ctx, arg->i); +} + +void +kbfunc_group_toggle(void *ctx, union arg *arg, enum xev xev) +{ + group_hidetoggle(ctx, arg->i); +} + +void +kbfunc_group_only(void *ctx, union arg *arg, enum xev xev) +{ + group_only(ctx, arg->i); +} + +void +kbfunc_group_cycle(void *ctx, union arg *arg, enum xev xev) +{ + group_cycle(ctx, arg->i); +} + +void +kbfunc_group_alltoggle(void *ctx, union arg *arg, enum xev xev) +{ + group_alltoggle(ctx); +} + +void +kbfunc_menu_client(void *ctx, union arg *arg, enum xev xev) +{ + struct screen_ctx *sc = ctx; + struct client_ctx *cc, *old_cc; struct menu *mi; struct menu_q menuq; - int m = (xev == CWM_BTN); + int m = (xev == CWM_XEV_BTN); old_cc = client_current(); @@ -210,13 +328,13 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_cmd(void *ctx, union arg *arg, enum xev xev) { - struct screen_ctx *sc = cc->sc; - struct cmd *cmd; + struct screen_ctx *sc = ctx; + struct cmd_ctx *cmd; struct menu *mi; struct menu_q menuq; - int m = (xev == CWM_BTN); + int m = (xev == CWM_XEV_BTN); TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { @@ -231,7 +349,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev) (m) ? NULL : "application", NULL, (m) ? CWM_MENU_LIST : 0, search_match_text, search_print_cmd)) != NULL) { - cmd = (struct cmd *)mi->ctx; + cmd = (struct cmd_ctx *)mi->ctx; u_spawn(cmd->path); } @@ -239,13 +357,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_menu_group(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_group(void *ctx, union arg *arg, enum xev xev) { - struct screen_ctx *sc = cc->sc; + struct screen_ctx *sc = ctx; struct group_ctx *gc; struct menu *mi; struct menu_q menuq; - int m = (xev == CWM_BTN); + int m = (xev == CWM_XEV_BTN); TAILQ_INIT(&menuq); TAILQ_FOREACH(gc, &sc->groupq, entry) { @@ -266,50 +384,10 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_client_cycle(struct client_ctx *cc, union arg *arg, int xev) -{ - client_cycle(cc->sc, arg->i); -} - -void -kbfunc_client_hide(struct client_ctx *cc, union arg *arg, int xev) -{ - client_hide(cc); -} - -void -kbfunc_exec(struct client_ctx *cc, union arg *arg, int xev) -{ - u_spawn(arg->c); -} - -void -kbfunc_exec_term(struct client_ctx *cc, union arg *arg, int xev) -{ - struct cmd *cmd; - - TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { - if (strcmp(cmd->name, "term") == 0) - u_spawn(cmd->path); - } -} - -void -kbfunc_exec_lock(struct client_ctx *cc, union arg *arg, int xev) -{ - struct cmd *cmd; - - TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { - if (strcmp(cmd->name, "lock") == 0) - u_spawn(cmd->path); - } -} - -void -kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev) { #define NPATHS 256 - struct screen_ctx *sc = cc->sc; + struct screen_ctx *sc = ctx; char **ap, *paths[NPATHS], *path, *pathcpy; char tpath[PATH_MAX]; const char *label; @@ -320,7 +398,7 @@ kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev) int l, i, cmd = arg->i; switch (cmd) { - case CWM_MENU_EXEC: + case CWM_MENU_EXEC_EXEC: label = "exec"; break; case CWM_MENU_EXEC_WM: @@ -328,7 +406,7 @@ kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev) break; default: errx(1, "kbfunc_menu_exec: invalid cmd %d", cmd); - /*NOTREACHED*/ + /* NOTREACHED */ } TAILQ_INIT(&menuq); @@ -369,17 +447,17 @@ kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev) if (mi->text[0] == '\0') goto out; switch (cmd) { - case CWM_MENU_EXEC: + case CWM_MENU_EXEC_EXEC: u_spawn(mi->text); break; case CWM_MENU_EXEC_WM: cwm_status = CWM_EXEC_WM; - free(wm_argv); - wm_argv = xstrdup(mi->text); + free(Conf.wm_argv); + Conf.wm_argv = xstrdup(mi->text); break; default: errx(1, "kb_func: egad, cmd changed value!"); - break; + /* NOTREACHED */ } } out: @@ -389,10 +467,10 @@ out: } void -kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_ssh(void *ctx, union arg *arg, enum xev xev) { - struct screen_ctx *sc = cc->sc; - struct cmd *cmd; + struct screen_ctx *sc = ctx; + struct cmd_ctx *cmd; struct menu *mi; struct menu_q menuq; FILE *fp; @@ -456,10 +534,11 @@ out: } void -kbfunc_menu_client_label(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_menu_client_label(void *ctx, union arg *arg, enum xev xev) { - struct menu *mi; - struct menu_q menuq; + struct client_ctx *cc = ctx; + struct menu *mi; + struct menu_q menuq; TAILQ_INIT(&menuq); @@ -475,104 +554,29 @@ kbfunc_menu_client_label(struct client_ctx *cc, union arg *arg, int xev) } void -kbfunc_client_delete(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_exec_cmd(void *ctx, union arg *arg, enum xev xev) { - client_send_delete(cc); + u_spawn(arg->c); } void -kbfunc_group_toggle(struct client_ctx *cc, union arg *arg, int xev) +kbfunc_exec_term(void *ctx, union arg *arg, enum xev xev) { - group_hidetoggle(cc->sc, arg->i); -} + struct cmd_ctx *cmd; -void -kbfunc_group_only(struct client_ctx *cc, union arg *arg, int xev) -{ - group_only(cc->sc, arg->i); -} - -void -kbfunc_group_cycle(struct client_ctx *cc, union arg *arg, int xev) -{ - group_cycle(cc->sc, arg->i); -} - -void -kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg, int xev) -{ - group_alltoggle(cc->sc); -} - -void -kbfunc_client_toggle_group(struct client_ctx *cc, union arg *arg, int xev) -{ - if (xev == CWM_KEY) { - /* For X apps that steal events. */ - XGrabKeyboard(X_Dpy, cc->win, True, - GrabModeAsync, GrabModeAsync, CurrentTime); - } - - group_toggle_membership_enter(cc); -} - -void -kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg, int xev) -{ - group_movetogroup(cc, arg->i); -} - -void -kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_sticky(cc); -} - -void -kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_fullscreen(cc); -} - -void -kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_maximize(cc); -} - -void -kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_vmaximize(cc); -} - -void -kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_hmaximize(cc); -} - -void -kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg, int xev) -{ - client_toggle_freeze(cc); -} - -void -kbfunc_cwm_status(struct client_ctx *cc, union arg *arg, int xev) -{ - cwm_status = arg->i; -} - -void -kbfunc_client_tile(struct client_ctx *cc, union arg *arg, int xev) -{ - switch (arg->i) { - case CWM_CLIENT_TILE_HORIZ: - client_htile(cc); - break; - case CWM_CLIENT_TILE_VERT: - client_vtile(cc); - break; + TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { + if (strcmp(cmd->name, "term") == 0) + u_spawn(cmd->path); + } +} + +void +kbfunc_exec_lock(void *ctx, union arg *arg, enum xev xev) +{ + struct cmd_ctx *cmd; + + TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { + if (strcmp(cmd->name, "lock") == 0) + u_spawn(cmd->path); } } diff --git a/mousefunc.c b/mousefunc.c index 27b1d65..23c5c42 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -33,8 +33,9 @@ #include "calmwm.h" void -mousefunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) +mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev) { + struct client_ctx *cc = ctx; XEvent ev; Time ltime = 0; struct screen_ctx *sc = cc->sc; @@ -88,8 +89,9 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg, int xev) } void -mousefunc_client_move(struct client_ctx *cc, union arg *arg, int xev) +mousefunc_client_move(void *ctx, union arg *arg, enum xev xev) { + struct client_ctx *cc = ctx; XEvent ev; Time ltime = 0; struct screen_ctx *sc = cc->sc; diff --git a/screen.c b/screen.c index b9f1ac9..4badf65 100644 --- a/screen.c +++ b/screen.c @@ -84,7 +84,7 @@ screen_init(int which) } screen_updatestackingorder(sc); - if (HasRandr) + if (Conf.xrandr) XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); TAILQ_INSERT_TAIL(&Screenq, sc, entry); @@ -140,7 +140,7 @@ region_find(struct screen_ctx *sc, int x, int y) } struct geom -screen_area(struct screen_ctx *sc, int x, int y, int flags) +screen_area(struct screen_ctx *sc, int x, int y, enum apply_gap apply_gap) { struct region_ctx *rc; struct geom area = sc->work; @@ -152,7 +152,7 @@ screen_area(struct screen_ctx *sc, int x, int y, int flags) break; } } - if (flags & CWM_GAP) + if (apply_gap) area = screen_apply_gap(sc, area); return(area); } @@ -173,7 +173,7 @@ screen_update_geometry(struct screen_ctx *sc) free(rc); } - if (HasRandr) { + if (Conf.xrandr) { XRRScreenResources *sr; XRRCrtcInfo *ci; int i; diff --git a/search.c b/search.c index f52d87d..efc2e73 100644 --- a/search.c +++ b/search.c @@ -72,7 +72,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) /* Then, on window names. */ if (tier < 0) { - TAILQ_FOREACH_REVERSE(wn, &cc->nameq, winname_q, entry) + TAILQ_FOREACH_REVERSE(wn, &cc->nameq, name_q, entry) if (strsubmatch(search, wn->name, 0)) { cc->matchname = wn->name; tier = 2; @@ -126,7 +126,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) void search_print_cmd(struct menu *mi, int i) { - struct cmd *cmd = (struct cmd *)mi->ctx; + struct cmd_ctx *cmd = (struct cmd_ctx *)mi->ctx; (void)snprintf(mi->print, sizeof(mi->print), "%s", cmd->name); } diff --git a/xevents.c b/xevents.c index 3388063..946ea98 100644 --- a/xevents.c +++ b/xevents.c @@ -220,31 +220,37 @@ static void xev_handle_buttonpress(XEvent *ee) { XButtonEvent *e = &ee->xbutton; - struct client_ctx *cc, fakecc; - struct binding *mb; + struct client_ctx *cc; + struct screen_ctx *sc; + struct bind_ctx *mb; e->state &= ~IGNOREMODMASK; - TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { + TAILQ_FOREACH(mb, &Conf.mousebindq, entry) { if (e->button == mb->press.button && e->state == mb->modmask) break; } if (mb == NULL) return; - if (mb->context == CWM_CONTEXT_CLIENT) { + switch (mb->context) { + case CWM_CONTEXT_CC: if (((cc = client_find(e->window)) == NULL) && (cc = client_current()) == NULL) return; - } else { + (*mb->callback)(cc, &mb->argument, CWM_XEV_BTN); + break; + case CWM_CONTEXT_SC: if (e->window != e->root) return; - cc = &fakecc; - if ((cc->sc = screen_find(e->window)) == NULL) + if ((sc = screen_find(e->window)) == NULL) return; + (*mb->callback)(sc, &mb->argument, CWM_XEV_BTN); + break; + case CWM_CONTEXT_NONE: + (*mb->callback)(NULL, &mb->argument, CWM_XEV_BTN); + break; } - - (*mb->callback)(cc, &mb->argument, CWM_BTN); } static void @@ -263,8 +269,9 @@ static void xev_handle_keypress(XEvent *ee) { XKeyEvent *e = &ee->xkey; - struct client_ctx *cc = NULL, fakecc; - struct binding *kb; + struct client_ctx *cc; + struct screen_ctx *sc; + struct bind_ctx *kb; KeySym keysym, skeysym; unsigned int modshift; @@ -273,7 +280,7 @@ xev_handle_keypress(XEvent *ee) e->state &= ~IGNOREMODMASK; - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) { + TAILQ_FOREACH(kb, &Conf.keybindq, entry) { if (keysym != kb->press.keysym && skeysym == kb->press.keysym) modshift = ShiftMask; else @@ -288,17 +295,22 @@ xev_handle_keypress(XEvent *ee) if (kb == NULL) return; - if (kb->context == CWM_CONTEXT_CLIENT) { + switch (kb->context) { + case CWM_CONTEXT_CC: if (((cc = client_find(e->window)) == NULL) && (cc = client_current()) == NULL) return; - } else { - cc = &fakecc; - if ((cc->sc = screen_find(e->window)) == NULL) + (*kb->callback)(cc, &kb->argument, CWM_XEV_KEY); + break; + case CWM_CONTEXT_SC: + if ((sc = screen_find(e->window)) == NULL) return; + (*kb->callback)(sc, &kb->argument, CWM_XEV_KEY); + break; + case CWM_CONTEXT_NONE: + (*kb->callback)(NULL, &kb->argument, CWM_XEV_KEY); + break; } - - (*kb->callback)(cc, &kb->argument, CWM_KEY); } /* @@ -424,7 +436,7 @@ xev_process(void) XEvent e; XNextEvent(X_Dpy, &e); - if (e.type - Randr_ev == RRScreenChangeNotify) + if (e.type - Conf.xrandr_event_base == RRScreenChangeNotify) xev_handle_randr(&e); else if (e.type < LASTEvent && xev_handlers[e.type] != NULL) (*xev_handlers[e.type])(&e); From b1af1bedd009221477e49cc77010ccc37e1ae014 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 22 Oct 2016 19:16:43 +0000 Subject: [PATCH 30/34] clean up search_match_client(); no behaviour change --- search.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/search.c b/search.c index efc2e73..0c57b49 100644 --- a/search.c +++ b/search.c @@ -52,25 +52,17 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) (void)memset(tierp, 0, sizeof(tierp)); - /* - * In order of rank: - * - * 1. Look through labels. - * 2. Look at title history, from present to past. - * 3. Look at window class name. - */ - TAILQ_FOREACH(mi, menuq, entry) { int tier = -1, t; struct client_ctx *cc = (struct client_ctx *)mi->ctx; - /* First, try to match on labels. */ - if (cc->label != NULL && strsubmatch(search, cc->label, 0)) { + /* Match on label. */ + if ((cc->label) && strsubmatch(search, cc->label, 0)) { cc->matchname = cc->label; tier = 0; } - /* Then, on window names. */ + /* Match on window name history, from present to past. */ if (tier < 0) { TAILQ_FOREACH_REVERSE(wn, &cc->nameq, name_q, entry) if (strsubmatch(search, wn->name, 0)) { @@ -80,8 +72,8 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) } } - /* Then if there is a match on the window class name. */ - if (tier < 0 && strsubmatch(search, cc->ch.res_class, 0)) { + /* Match on window class name. */ + if ((tier < 0) && strsubmatch(search, cc->ch.res_class, 0)) { cc->matchname = cc->ch.res_class; tier = 3; } @@ -89,16 +81,12 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) if (tier < 0) continue; - /* - * De-rank a client one tier if it's the current - * window. Furthermore, this is denoted by a "!" when - * printing the window name in the search menu. - */ - if ((cc->flags & CLIENT_ACTIVE) && (tier < nitems(tierp) - 1)) + /* Current window is ranked down. */ + if ((tier < nitems(tierp) - 1) && (cc->flags & CLIENT_ACTIVE)) tier++; - /* Clients that are hidden get ranked one up. */ - if ((cc->flags & CLIENT_HIDDEN) && (tier > 0)) + /* Hidden window is ranked up. */ + if ((tier > 0) && (cc->flags & CLIENT_HIDDEN)) tier--; if (tier >= nitems(tierp)) From ffd60b3cabc361f9432c863ff58e823db5b7aa14 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 24 Oct 2016 17:16:23 +0000 Subject: [PATCH 31/34] Get rid of 'matchname'; it's too surprising to have the menu change during client search as different potential str matches are cycled through. If there's interest, the only string that doesn't exist in the listing is the window's class - that can be added of course, but it makes the line too long imho. --- calmwm.h | 1 - search.c | 14 +++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/calmwm.h b/calmwm.h index f6542a7..d44df66 100644 --- a/calmwm.h +++ b/calmwm.h @@ -165,7 +165,6 @@ struct client_ctx { struct name_q nameq; char *name; char *label; - char *matchname; XClassHint ch; XWMHints *wmh; }; diff --git a/search.c b/search.c index 0c57b49..9ca4e5d 100644 --- a/search.c +++ b/search.c @@ -57,26 +57,21 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) struct client_ctx *cc = (struct client_ctx *)mi->ctx; /* Match on label. */ - if ((cc->label) && strsubmatch(search, cc->label, 0)) { - cc->matchname = cc->label; + if ((cc->label) && strsubmatch(search, cc->label, 0)) tier = 0; - } /* Match on window name history, from present to past. */ if (tier < 0) { TAILQ_FOREACH_REVERSE(wn, &cc->nameq, name_q, entry) if (strsubmatch(search, wn->name, 0)) { - cc->matchname = wn->name; tier = 2; break; } } /* Match on window class name. */ - if ((tier < 0) && strsubmatch(search, cc->ch.res_class, 0)) { - cc->matchname = cc->ch.res_class; + if ((tier < 0) && strsubmatch(search, cc->ch.res_class, 0)) tier = 3; - } if (tier < 0) continue; @@ -140,12 +135,9 @@ search_print_client(struct menu *mi, int list) else if (cc->flags & CLIENT_HIDDEN) flag = '&'; - if ((list) || (cc->matchname == cc->label)) - cc->matchname = cc->name; - (void)snprintf(mi->print, sizeof(mi->print), "(%d) %c[%s] %s", (cc->gc) ? cc->gc->num : 0, flag, - (cc->label) ? cc->label : "", cc->matchname); + (cc->label) ? cc->label : "", cc->name); } static void From eb43101591ca45754f4805dd1f7101c79a487ddb Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 24 Oct 2016 17:39:38 +0000 Subject: [PATCH 32/34] Sprinkle __func__ in appropriate error messages. --- conf.c | 4 ++-- group.c | 6 +++--- kbfunc.c | 6 +++--- screen.c | 2 +- search.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/conf.c b/conf.c index 156bb71..f0f1dde 100644 --- a/conf.c +++ b/conf.c @@ -138,7 +138,7 @@ conf_screen(struct screen_ctx *sc) if (sc->xftfont == NULL) { sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font); if (sc->xftfont == NULL) - errx(1, "XftFontOpenName: %s", Conf.font); + errx(1, "%s: XftFontOpenName: %s", __func__, Conf.font); } for (i = 0; i < nitems(color_binds); i++) { @@ -169,7 +169,7 @@ conf_screen(struct screen_ctx *sc) sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win, visual, colormap); if (sc->menu.xftdraw == NULL) - errx(1, "XftDrawCreate"); + errx(1, "%s: XftDrawCreate", __func__); conf_grab_kbd(sc->rootwin); } diff --git a/group.c b/group.c index ec368de..a26c53d 100644 --- a/group.c +++ b/group.c @@ -155,7 +155,7 @@ group_movetogroup(struct client_ctx *cc, int idx) struct group_ctx *gc; if (idx < 0 || idx >= Conf.ngroups) - errx(1, "group_movetogroup: index out of range (%d)", idx); + errx(1, "%s: index out of range (%d)", __func__, idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { if (gc->num == idx) @@ -223,7 +223,7 @@ group_hidetoggle(struct screen_ctx *sc, int idx) struct group_ctx *gc; if (idx < 0 || idx >= Conf.ngroups) - errx(1, "group_hidetoggle: index out of range (%d)", idx); + errx(1, "%s: index out of range (%d)", __func__, idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { if (gc->num == idx) @@ -246,7 +246,7 @@ group_only(struct screen_ctx *sc, int idx) struct group_ctx *gc; if (idx < 0 || idx >= Conf.ngroups) - errx(1, "group_only: index out of range (%d)", idx); + errx(1, "%s: index out of range (%d)", __func__, idx); TAILQ_FOREACH(gc, &sc->groupq, entry) { if (gc->num == idx) diff --git a/kbfunc.c b/kbfunc.c index ef2334f..c1a1812 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -405,7 +405,7 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev) label = "wm"; break; default: - errx(1, "kbfunc_menu_exec: invalid cmd %d", cmd); + errx(1, "%s: invalid cmd %d", __func__, cmd); /* NOTREACHED */ } @@ -456,7 +456,7 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev) Conf.wm_argv = xstrdup(mi->text); break; default: - errx(1, "kb_func: egad, cmd changed value!"); + errx(1, "%s: egad, cmd changed value!", __func__); /* NOTREACHED */ } } @@ -487,7 +487,7 @@ kbfunc_menu_ssh(void *ctx, union arg *arg, enum xev xev) TAILQ_INIT(&menuq); if ((fp = fopen(Conf.known_hosts, "r")) == NULL) { - warn("kbfunc_menu_ssh: %s", Conf.known_hosts); + warn("%s: %s", __func__, Conf.known_hosts); goto menu; } diff --git a/screen.c b/screen.c index 4badf65..5887784 100644 --- a/screen.c +++ b/screen.c @@ -101,7 +101,7 @@ screen_find(Window win) if (sc->rootwin == win) return(sc); } - warnx("screen_find failure win 0x%lu\n", win); + warnx("%s: failure win 0x%lu\n", __func__, win); return(NULL); } diff --git a/search.c b/search.c index 9ca4e5d..da05ae8 100644 --- a/search.c +++ b/search.c @@ -85,7 +85,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) tier--; if (tier >= nitems(tierp)) - errx(1, "search_match_client: invalid tier"); + errx(1, "%s: invalid tier", __func__); /* * If you have a tierp, insert after it, and make it From 972e28d58cd3a2c4e3bd4cc746cd94f0056cd9a3 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 24 Oct 2016 18:57:12 +0000 Subject: [PATCH 33/34] Remove duplicate check that strsubmatch() already does; while here, fix a comment. --- search.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/search.c b/search.c index da05ae8..89d4911 100644 --- a/search.c +++ b/search.c @@ -57,7 +57,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) struct client_ctx *cc = (struct client_ctx *)mi->ctx; /* Match on label. */ - if ((cc->label) && strsubmatch(search, cc->label, 0)) + if (strsubmatch(search, cc->label, 0)) tier = 0; /* Match on window name history, from present to past. */ @@ -69,7 +69,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) } } - /* Match on window class name. */ + /* Match on window resource class. */ if ((tier < 0) && strsubmatch(search, cc->ch.res_class, 0)) tier = 3; From db93599a0fb302271e10a9dcbcbe6cafdc8aa2cb Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 24 Oct 2016 20:44:08 +0000 Subject: [PATCH 34/34] Make it clear these are flags. --- conf.c | 8 ++++---- kbfunc.c | 12 ++++++------ menu.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/conf.c b/conf.c index f0f1dde..92f166f 100644 --- a/conf.c +++ b/conf.c @@ -362,9 +362,9 @@ static const struct { { "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SC, {0} }, { "hide", kbfunc_client_hide, CWM_CONTEXT_CC, {0} }, { "cycle", kbfunc_client_cycle, CWM_CONTEXT_SC, - {.i = CWM_CYCLE_FORWARD} }, + {.i = (CWM_CYCLE_FORWARD)} }, { "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SC, - {.i = CWM_CYCLE_REVERSE} }, + {.i = (CWM_CYCLE_REVERSE)} }, { "label", kbfunc_menu_client_label, CWM_CONTEXT_CC, {0} }, { "delete", kbfunc_client_delete, CWM_CONTEXT_CC, {0} }, { "group1", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 1} }, @@ -396,9 +396,9 @@ static const struct { { "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 9} }, { "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SC, {0} }, { "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC, - {.i = CWM_CYCLE_FORWARD} }, + {.i = (CWM_CYCLE_FORWARD)} }, { "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC, - {.i = CWM_CYCLE_REVERSE} }, + {.i = (CWM_CYCLE_REVERSE)} }, { "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC, {.i = (CWM_CYCLE_FORWARD | CWM_CYCLE_INGROUP)} }, { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC, diff --git a/kbfunc.c b/kbfunc.c index c1a1812..8edea79 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -312,7 +312,7 @@ kbfunc_menu_client(void *ctx, union arg *arg, enum xev xev) if ((mi = menu_filter(sc, &menuq, (m) ? NULL : "window", NULL, - (m) ? CWM_MENU_LIST : 0, + ((m) ? CWM_MENU_LIST : 0), search_match_client, search_print_client)) != NULL) { cc = (struct client_ctx *)mi->ctx; if (cc->flags & CLIENT_HIDDEN) @@ -347,7 +347,7 @@ kbfunc_menu_cmd(void *ctx, union arg *arg, enum xev xev) if ((mi = menu_filter(sc, &menuq, (m) ? NULL : "application", NULL, - (m) ? CWM_MENU_LIST : 0, + ((m) ? CWM_MENU_LIST : 0), search_match_text, search_print_cmd)) != NULL) { cmd = (struct cmd_ctx *)mi->ctx; u_spawn(cmd->path); @@ -373,7 +373,7 @@ kbfunc_menu_group(void *ctx, union arg *arg, enum xev xev) } if ((mi = menu_filter(sc, &menuq, - (m) ? NULL : "group", NULL, CWM_MENU_LIST, + (m) ? NULL : "group", NULL, (CWM_MENU_LIST), search_match_text, search_print_group)) != NULL) { gc = (struct group_ctx *)mi->ctx; (group_holds_only_hidden(gc)) ? @@ -442,7 +442,7 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev) free(path); if ((mi = menu_filter(sc, &menuq, label, NULL, - CWM_MENU_DUMMY | CWM_MENU_FILE, + (CWM_MENU_DUMMY | CWM_MENU_FILE), search_match_exec_path, NULL)) != NULL) { if (mi->text[0] == '\0') goto out; @@ -517,7 +517,7 @@ kbfunc_menu_ssh(void *ctx, union arg *arg, enum xev xev) free(lbuf); (void)fclose(fp); menu: - if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY, + if ((mi = menu_filter(sc, &menuq, "ssh", NULL, (CWM_MENU_DUMMY), search_match_exec, NULL)) != NULL) { if (mi->text[0] == '\0') goto out; @@ -543,7 +543,7 @@ kbfunc_menu_client_label(void *ctx, union arg *arg, enum xev xev) TAILQ_INIT(&menuq); /* dummy is set, so this will always return */ - mi = menu_filter(cc->sc, &menuq, "label", cc->label, CWM_MENU_DUMMY, + mi = menu_filter(cc->sc, &menuq, "label", cc->label, (CWM_MENU_DUMMY), search_match_text, NULL); if (!mi->abort) { diff --git a/menu.c b/menu.c index 4f91f9a..dd6160e 100644 --- a/menu.c +++ b/menu.c @@ -196,7 +196,7 @@ menu_complete_path(struct menu_ctx *mc) TAILQ_INIT(&menuq); if ((mi = menu_filter(sc, &menuq, mc->searchstr, NULL, - CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) { + (CWM_MENU_DUMMY), search_match_path_any, NULL)) != NULL) { mr->abort = mi->abort; mr->dummy = mi->dummy; if (mi->text[0] != '\0')