From ec4474a33acd02d1bf0df17aee7fb1a490bc9676 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 3 Apr 2013 19:20:50 +0000 Subject: [PATCH 1/5] move XUngrabServer to the end of client_new() to avoid races where clients, such as those using sdl, attempt to manage the clients themselves when the clients aren't fully ready. other wm's grab the xserver during the whole client setup process, so match. behavior found by jsg. --- client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client.c b/client.c index 4895817..0b9f121 100644 --- a/client.c +++ b/client.c @@ -121,9 +121,6 @@ client_new(Window win, struct screen_ctx *sc, int mapped) (state == IconicState) ? client_hide(cc) : client_unhide(cc); xu_setstate(cc, cc->state); - XSync(X_Dpy, False); - XUngrabServer(X_Dpy); - TAILQ_INSERT_TAIL(&sc->mruq, cc, mru_entry); TAILQ_INSERT_TAIL(&Clientq, cc, entry); @@ -135,6 +132,9 @@ client_new(Window win, struct screen_ctx *sc, int mapped) if (mapped) group_autogroup(cc); + XSync(X_Dpy, False); + XUngrabServer(X_Dpy); + return (cc); } From 9cad4c73b36c922d9b251c9fc31eb6e9bee64f4e Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 3 Apr 2013 19:28:00 +0000 Subject: [PATCH 2/5] honor PATH search order for exec; from Andres Perera. --- search.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/search.c b/search.c index 759af5f..53ab8f0 100644 --- a/search.c +++ b/search.c @@ -217,6 +217,7 @@ void search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) { struct menu *mi, *mj; + int r; TAILQ_INIT(resultq); @@ -225,10 +226,11 @@ search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) fnmatch(search, mi->text, 0) == FNM_NOMATCH) continue; TAILQ_FOREACH(mj, resultq, resultentry) { - if (strcasecmp(mi->text, mj->text) < 0) { + r = strcasecmp(mi->text, mj->text); + if (r < 0) TAILQ_INSERT_BEFORE(mj, mi, resultentry); + if (r <= 0) break; - } } if (mj == NULL) TAILQ_INSERT_TAIL(resultq, mi, resultentry); From c5a76f1d5bbde32778859cfd1e190e89fb9a68e2 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 3 Apr 2013 20:22:55 +0000 Subject: [PATCH 3/5] - no reason to breakout ClassHints work, so fold into client_{new,delete}, but keep _MOTIF_WM_HINTS separate. - simplify fetching app/class hint. - fix _MOTIF_WM_HINTS Atom type. --- client.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/client.c b/client.c index 0b9f121..949c4c5 100644 --- a/client.c +++ b/client.c @@ -37,8 +37,7 @@ static void client_mtf(struct client_ctx *); static void client_none(struct screen_ctx *); static void client_placecalc(struct client_ctx *); static void client_update(struct client_ctx *); -static void client_gethints(struct client_ctx *); -static void client_freehints(struct client_ctx *); +static void client_getmwmhints(struct client_ctx *); static int client_inbound(struct client_ctx *, int, int); struct client_ctx *_curcc = NULL; @@ -59,6 +58,7 @@ struct client_ctx * client_new(Window win, struct screen_ctx *sc, int mapped) { struct client_ctx *cc; + XClassHint xch; XWindowAttributes wattr; XWMHints *wmhints; int state; @@ -82,6 +82,12 @@ client_new(Window win, struct screen_ctx *sc, int mapped) conf_client(cc); + if (XGetClassHint(X_Dpy, cc->win, &xch)) { + cc->app_name = xch.res_name; + cc->app_class = xch.res_class; + } + client_getmwmhints(cc); + /* Saved pointer position */ cc->ptr.x = -1; cc->ptr.y = -1; @@ -126,7 +132,6 @@ client_new(Window win, struct screen_ctx *sc, int mapped) xu_ewmh_net_client_list(sc); - client_gethints(cc); client_update(cc); if (mapped) @@ -162,6 +167,10 @@ client_delete(struct client_ctx *cc) client_none(sc); XFree(cc->size); + if (cc->app_name != NULL) + XFree(cc->app_name); + if (cc->app_class != NULL) + XFree(cc->app_class); while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) { TAILQ_REMOVE(&cc->nameq, wn, entry); @@ -169,7 +178,6 @@ client_delete(struct client_ctx *cc) free(wn); } - client_freehints(cc); free(cc); } @@ -789,19 +797,12 @@ client_applysizehints(struct client_ctx *cc) } static void -client_gethints(struct client_ctx *cc) +client_getmwmhints(struct client_ctx *cc) { - XClassHint xch; struct mwm_hints *mwmh; - if (XGetClassHint(X_Dpy, cc->win, &xch)) { - if (xch.res_name != NULL) - cc->app_name = xch.res_name; - if (xch.res_class != NULL) - cc->app_class = xch.res_class; - } - - if (xu_getprop(cc->win, cwmh[_MOTIF_WM_HINTS].atom, _MOTIF_WM_HINTS, + if (xu_getprop(cc->win, + cwmh[_MOTIF_WM_HINTS].atom, cwmh[_MOTIF_WM_HINTS].atom, PROP_MWM_HINTS_ELEMENTS, (u_char **)&mwmh) == MWM_NUMHINTS) if (mwmh->flags & MWM_HINTS_DECORATIONS && !(mwmh->decorations & MWM_DECOR_ALL) && @@ -809,15 +810,6 @@ client_gethints(struct client_ctx *cc) cc->bwidth = 0; } -static void -client_freehints(struct client_ctx *cc) -{ - if (cc->app_name != NULL) - XFree(cc->app_name); - if (cc->app_class != NULL) - XFree(cc->app_class); -} - void client_transient(struct client_ctx *cc) { From 670207f79b2cc8bf4dec97ba404f6922e33dac8e Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 5 Apr 2013 17:07:25 +0000 Subject: [PATCH 4/5] zap stray whitespace --- client.c | 4 ++-- group.c | 2 +- menu.c | 14 +++++++------- search.c | 4 ++-- xevents.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client.c b/client.c index 949c4c5..1750360 100644 --- a/client.c +++ b/client.c @@ -574,7 +574,7 @@ client_cycle(struct screen_ctx *sc, int flags) return; if (oldcc == NULL) - oldcc = (flags & CWM_RCYCLE ? + oldcc = (flags & CWM_RCYCLE ? TAILQ_LAST(&sc->mruq, cycle_entry_q) : TAILQ_FIRST(&sc->mruq)); @@ -606,7 +606,7 @@ client_cycle(struct screen_ctx *sc, int flags) } void -client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) +client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) { sc->cycling = 0; diff --git a/group.c b/group.c index 6644dce..307b5c7 100644 --- a/group.c +++ b/group.c @@ -142,7 +142,7 @@ group_init(struct screen_ctx *sc) TAILQ_INIT(&sc->groupq); sc->group_hideall = 0; - /* + /* * See if any group names have already been set and update the * property with ours if they'll have changed. */ diff --git a/menu.c b/menu.c index b392a08..381da6c 100644 --- a/menu.c +++ b/menu.c @@ -59,8 +59,8 @@ struct menu_ctx { int flags; int x; int y; - void (*match)(struct menu_q *, struct menu_q *, char *); - void (*print)(struct menu *, int); + void (*match)(struct menu_q *, struct menu_q *, char *); + void (*print)(struct menu *, int); }; static struct menu *menu_handle_key(XEvent *, struct menu_ctx *, struct menu_q *, struct menu_q *); @@ -75,7 +75,7 @@ static void menu_draw_entry(struct screen_ctx *, struct menu_ctx *, static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *, int, int); static int menu_keycode(XKeyEvent *, enum ctltype *, - char *); + char *); void menu_init(struct screen_ctx *sc) @@ -88,7 +88,7 @@ menu_init(struct screen_ctx *sc) struct menu * menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, - char *initial, int flags, + char *initial, int flags, void (*match)(struct menu_q *, struct menu_q *, char *), void (*print)(struct menu *, int)) { @@ -217,7 +217,7 @@ menu_complete_path(struct menu_ctx *mc) menuq_clear(&menuq); - if (path[0] != '\0') + if (path[0] != '\0') snprintf(mr->text, sizeof(mr->text), "%s \"%s\"", mc->searchstr, path); else if (!mr->abort) @@ -286,7 +286,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq, break; case CTL_TAB: if ((mi = TAILQ_FIRST(resultq)) != NULL) { - /* + /* * - We are in exec_path menu mode * - It is equal to the input * We got a command, launch the file menu @@ -296,7 +296,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq, strlen(mi->text))) == 0) return (menu_complete_path(mc)); - /* + /* * Put common prefix of the results into searchstr */ (void)strlcpy(mc->searchstr, diff --git a/search.c b/search.c index 53ab8f0..e46077e 100644 --- a/search.c +++ b/search.c @@ -189,13 +189,13 @@ search_match_path(struct menu_q *menuq, struct menu_q *resultq, char *search, in globfree(&g); } -void +void search_match_path_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) { return (search_match_path(menuq, resultq, search, PATH_EXEC)); } -void +void search_match_path_any(struct menu_q *menuq, struct menu_q *resultq, char *search) { return (search_match_path(menuq, resultq, search, 0)); diff --git a/xevents.c b/xevents.c index 421a1b7..f19d10c 100644 --- a/xevents.c +++ b/xevents.c @@ -203,7 +203,7 @@ xev_handle_propertynotify(XEvent *ee) break; } } else { - TAILQ_FOREACH(sc, &Screenq, entry) + TAILQ_FOREACH(sc, &Screenq, entry) if (sc->rootwin == e->window) goto test; return; From f18d2c94c2efe8d580aa9b1cd71f83bfe10474aa Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 5 Apr 2013 17:36:02 +0000 Subject: [PATCH 5/5] add missing proto; replace magic number --- search.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/search.c b/search.c index e46077e..2ee9d26 100644 --- a/search.c +++ b/search.c @@ -33,8 +33,11 @@ #include "calmwm.h" -#define PATH_EXEC 0x1 +#define PATH_ANY 0x0001 +#define PATH_EXEC 0x0002 +static void search_match_path(struct menu_q *, struct menu_q *, + char *, int); static int strsubmatch(char *, char *, int); /* @@ -198,7 +201,7 @@ search_match_path_exec(struct menu_q *menuq, struct menu_q *resultq, char *searc void search_match_path_any(struct menu_q *menuq, struct menu_q *resultq, char *search) { - return (search_match_path(menuq, resultq, search, 0)); + return (search_match_path(menuq, resultq, search, PATH_ANY)); } void