From 055b84f4d47e05031ba03044dfa111d28e52a31d Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 19 Nov 2021 19:13:14 +0000 Subject: [PATCH 1/7] Do not attempt to grab keys without a keycode; this incidentally allows XF86 keys support. found and fix by Luis Henriques --- conf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf.c b/conf.c index a3026cf..246b4b0 100644 --- a/conf.c +++ b/conf.c @@ -669,6 +669,8 @@ conf_grab_kbd(Window win) TAILQ_FOREACH(kb, &Conf.keybindq, entry) { kc = XKeysymToKeycode(X_Dpy, kb->press.keysym); + if (kc == 0) + continue; if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) && (XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym)) kb->modmask |= ShiftMask; From a9eeb04606b8002d41b2ad5bc715ec7253f2e77a Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 22 Nov 2021 00:51:54 +0000 Subject: [PATCH 2/7] sync parse.y changes from base; ok naddy@ original from naddy@: > Don't declare variables as "unsigned char *" that are passed to > functions that take "char *" arguments. Where such chars are > assigned to int or passed to ctype functions, explicitly cast them > to unsigned char. > > For OpenBSD's clang, -Wpointer-sign has been disabled by default, > but when the parse.y code was built elsewhere, the compiler would > complain. > > With help from millert@ > ok benno@ deraadt@ --- parse.y | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/parse.y b/parse.y index 0138fdb..a406f39 100644 --- a/parse.y +++ b/parse.y @@ -361,9 +361,9 @@ lookup(char *s) #define MAXPUSHBACK 128 -u_char *parsebuf; +char *parsebuf; int parseindex; -u_char pushback_buffer[MAXPUSHBACK]; +char pushback_buffer[MAXPUSHBACK]; int pushback_index = 0; int @@ -374,7 +374,7 @@ lgetc(int quotec) if (parsebuf) { /* Read character from the parsebuffer instead of input. */ if (parseindex >= 0) { - c = parsebuf[parseindex++]; + c = (unsigned char)parsebuf[parseindex++]; if (c != '\0') return (c); parsebuf = NULL; @@ -383,7 +383,7 @@ lgetc(int quotec) } if (pushback_index) - return (pushback_buffer[--pushback_index]); + return ((unsigned char)pushback_buffer[--pushback_index]); if (quotec) { if ((c = getc(file->stream)) == EOF) { @@ -424,10 +424,10 @@ lungetc(int c) if (parseindex >= 0) return (c); } - if (pushback_index < MAXPUSHBACK-1) - return (pushback_buffer[pushback_index++] = c); - else + if (pushback_index + 1 >= MAXPUSHBACK) return (EOF); + pushback_buffer[pushback_index++] = c; + return (c); } int @@ -440,7 +440,7 @@ findeol(void) /* skip to either EOF or the first real EOL */ while (1) { if (pushback_index) - c = pushback_buffer[--pushback_index]; + c = (unsigned char)pushback_buffer[--pushback_index]; else c = lgetc(0); if (c == '\n') { @@ -456,8 +456,8 @@ findeol(void) int yylex(void) { - u_char buf[8096]; - u_char *p; + char buf[8096]; + char *p; int quotec, next, c; int token; @@ -514,7 +514,7 @@ yylex(void) if (c == '-' || isdigit(c)) { do { *p++ = c; - if ((unsigned)(p-buf) >= sizeof(buf)) { + if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } @@ -537,8 +537,8 @@ yylex(void) } else { nodigits: while (p > buf + 1) - lungetc(*--p); - c = *--p; + lungetc((unsigned char)*--p); + c = (unsigned char)*--p; if (c == '-') return (c); } @@ -553,7 +553,7 @@ nodigits: if (isalnum(c) || c == ':' || c == '_' || c == '*' || c == '/') { do { *p++ = c; - if ((unsigned)(p-buf) >= sizeof(buf)) { + if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } From 81a08ddb896dacfe2c7b2e9cad43a8f623fadd24 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 24 Dec 2021 16:00:47 +0000 Subject: [PATCH 3/7] Allow bare numbers for key and mouse bindings; taken from similar support in other parse.y's; from Leon Fischer . --- parse.y | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/parse.y b/parse.y index a406f39..a451da5 100644 --- a/parse.y +++ b/parse.y @@ -81,7 +81,7 @@ typedef struct { %token STRING %token NUMBER %type yesno -%type string +%type string numberstring %% grammar : /* empty */ @@ -104,6 +104,17 @@ string : string STRING { | STRING ; +numberstring : NUMBER { + char *s; + if (asprintf(&s, "%lld", $1) == -1) { + yyerror("string: asprintf"); + YYERROR; + } + $$ = s; + } + | STRING + ; + yesno : YES { $$ = 1; } | NO { $$ = 0; } ; @@ -209,7 +220,7 @@ main : FONTNAME STRING { conf->gap.left = $4; conf->gap.right = $5; } - | BINDKEY STRING string { + | BINDKEY numberstring string { if (!conf_bind_key(conf, $2, $3)) { yyerror("invalid bind-key: %s %s", $2, $3); free($2); @@ -219,7 +230,7 @@ main : FONTNAME STRING { free($2); free($3); } - | UNBINDKEY STRING { + | UNBINDKEY numberstring { if (!conf_bind_key(conf, $2, NULL)) { yyerror("invalid unbind-key: %s", $2); free($2); @@ -227,7 +238,7 @@ main : FONTNAME STRING { } free($2); } - | BINDMOUSE STRING string { + | BINDMOUSE numberstring string { if (!conf_bind_mouse(conf, $2, $3)) { yyerror("invalid bind-mouse: %s %s", $2, $3); free($2); @@ -237,7 +248,7 @@ main : FONTNAME STRING { free($2); free($3); } - | UNBINDMOUSE STRING { + | UNBINDMOUSE numberstring { if (!conf_bind_mouse(conf, $2, NULL)) { yyerror("invalid unbind-mouse: %s", $2); free($2); From 7c22b36a230ea740a0fe2b9d089f3b3340dc182b Mon Sep 17 00:00:00 2001 From: op Date: Thu, 27 Jan 2022 18:45:10 +0000 Subject: [PATCH 4/7] Add group-last command that shows only the previously active group; ok okan --- calmwm.h | 2 ++ conf.c | 1 + cwmrc.5 | 2 ++ group.c | 3 +++ kbfunc.c | 8 ++++++++ screen.c | 1 + 6 files changed, 17 insertions(+) diff --git a/calmwm.h b/calmwm.h index 9ae2afe..17bd55a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -214,6 +214,7 @@ struct screen_ctx { struct region_q regionq; struct group_q groupq; struct group_ctx *group_active; + struct group_ctx *group_last; Colormap colormap; Visual *visual; struct { @@ -501,6 +502,7 @@ void kbfunc_client_toggle_group(void *, struct cargs *); void kbfunc_client_movetogroup(void *, struct cargs *); void kbfunc_group_toggle(void *, struct cargs *); void kbfunc_group_only(void *, struct cargs *); +void kbfunc_group_last(void *, struct cargs *); void kbfunc_group_close(void *, struct cargs *); void kbfunc_group_cycle(void *, struct cargs *); void kbfunc_group_toggle_all(void *, struct cargs *); diff --git a/conf.c b/conf.c index 246b4b0..ce8e954 100644 --- a/conf.c +++ b/conf.c @@ -139,6 +139,7 @@ static const struct { { FUNC_SC(group-cycle, group_cycle, (CWM_CYCLE_FORWARD)) }, { FUNC_SC(group-rcycle, group_cycle, (CWM_CYCLE_REVERSE)) }, + { FUNC_SC(group-last, group_last, 0) }, { FUNC_SC(group-toggle-all, group_toggle_all, 0) }, { FUNC_SC(group-toggle-1, group_toggle, 1) }, { FUNC_SC(group-toggle-2, group_toggle, 2) }, diff --git a/cwmrc.5 b/cwmrc.5 index ab70d25..7075288 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -273,6 +273,8 @@ menu. Toggle visibility of group n, where n is 1-9. .It group-only-[n] Show only group n, where n is 1-9, hiding other groups. +.It group-last +Show only the previously active group. .It group-close-[n] Close all windows in group n, where n is 1-9. .It group-toggle-all diff --git a/group.c b/group.c index de55211..3246936 100644 --- a/group.c +++ b/group.c @@ -215,6 +215,9 @@ group_only(struct screen_ctx *sc, int idx) { struct group_ctx *gc; + if (sc->group_last != sc->group_active) + sc->group_last = sc->group_active; + TAILQ_FOREACH(gc, &sc->groupq, entry) { if (gc->num == idx) group_show(gc); diff --git a/kbfunc.c b/kbfunc.c index cbccc56..70eafd6 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -478,6 +478,14 @@ kbfunc_group_only(void *ctx, struct cargs *cargs) group_only(ctx, cargs->flag); } +void +kbfunc_group_last(void *ctx, struct cargs *cargs) +{ + struct screen_ctx *sc = ctx; + + group_only(ctx, sc->group_last->num); +} + void kbfunc_group_toggle(void *ctx, struct cargs *cargs) { diff --git a/screen.c b/screen.c index 373ff71..e880e97 100644 --- a/screen.c +++ b/screen.c @@ -60,6 +60,7 @@ screen_init(int which) xu_ewmh_net_supported_wm_check(sc); conf_group(sc); + sc->group_last = sc->group_active; screen_update_geometry(sc); xu_ewmh_net_desktop_names(sc); From 5e5221d82d1d0c8679329e5bfb5a913e1b543a29 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 26 Feb 2022 15:03:42 +0000 Subject: [PATCH 5/7] Fix spelling of some unused MWM hints; from Sean C. Farley. While here, flesh out the rest of the MWM hints. --- calmwm.h | 45 +++++++++++++++++++++++++++------------------ client.c | 12 +++++++----- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/calmwm.h b/calmwm.h index 17bd55a..5c4e45c 100644 --- a/calmwm.h +++ b/calmwm.h @@ -309,30 +309,39 @@ struct conf { /* MWM hints */ struct mwm_hints { -#define MWM_HINTS_ELEMENTS 3L -#define MWM_FLAGS_STATUS (1<<3) +#define MWM_HINTS_ELEMENTS 5L -#define MWM_FLAGS_FUNCTIONS (1<<0) -#define MWM_FLAGS_DECORATIONS (1<<1) -#define MWM_FLAGS_INPUT_MODE (1<<2) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_STATUS (1L << 3) unsigned long flags; -#define MWM_FUNCS_ALL (1<<0) -#define MWM_FUNCS_RESIZE (1<<1) -#define MWM_FUNCS_MOVE (1<<2) -#define MWM_FUNCS_MINIMIZE (1<<3) -#define MWM_FUNCS_MAXIMIZE (1<<4) -#define MWM_FUNCS_CLOSE (1<<5) +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) unsigned long functions; -#define MWM_DECOR_ALL (1<<0) -#define MWM_DECOR_BORDER (1<<1) -#define MWM_DECOR_RESIZE_HANDLE (1<<2) -#define MWM_DECOR_TITLEBAR (1<<3) -#define MWM_DECOR_MENU (1<<4) -#define MWM_DECOR_MINIMIZE (1<<5) -#define MWM_DECOR_MAXIMIZE (1<<6) +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) unsigned long decorations; + +#define MWM_INPUT_MODELESS 0 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_SYSTEM_MODAL 2 +#define MWM_INPUT_FULL_APPLICATION_MODAL 3 + long inputMode; + +#define MWM_TEAROFF_WINDOW (1L << 0) + unsigned long status; }; enum cwmh { diff --git a/client.c b/client.c index 0d93714..e66ca28 100644 --- a/client.c +++ b/client.c @@ -849,13 +849,15 @@ client_mwm_hints(struct client_ctx *cc) if (xu_get_prop(cc->win, cwmh[_MOTIF_WM_HINTS], cwmh[_MOTIF_WM_HINTS], MWM_HINTS_ELEMENTS, - (unsigned char **)&mwmh) == MWM_HINTS_ELEMENTS) { - if (mwmh->flags & MWM_FLAGS_DECORATIONS && - !(mwmh->decorations & MWM_DECOR_ALL) && - !(mwmh->decorations & MWM_DECOR_BORDER)) + (unsigned char **)&mwmh) <= 0) + return; + + if ((mwmh->flags & MWM_HINTS_DECORATIONS) && + !(mwmh->decorations & MWM_DECOR_ALL)) { + if (!(mwmh->decorations & MWM_DECOR_BORDER)) cc->bwidth = 0; - XFree(mwmh); } + XFree(mwmh); } void From 496bcc879de1186e62bac6fbeff531dbdc9e871c Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 26 Feb 2022 15:19:18 +0000 Subject: [PATCH 6/7] whitespace --- calmwm.c | 2 +- calmwm.h | 4 ++-- client.c | 2 +- conf.c | 2 +- kbfunc.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/calmwm.c b/calmwm.c index af1effb..f81a2f6 100644 --- a/calmwm.c +++ b/calmwm.c @@ -94,7 +94,7 @@ main(int argc, char **argv) signal(SIGINT, sighdlr) == SIG_ERR || signal(SIGTERM, sighdlr) == SIG_ERR) err(1, "signal"); - + if (parse_config(Conf.conf_file, &Conf) == -1) { warnx("error parsing config file"); if (nflag) diff --git a/calmwm.h b/calmwm.h index 5c4e45c..7c428f6 100644 --- a/calmwm.h +++ b/calmwm.h @@ -335,7 +335,7 @@ struct mwm_hints { unsigned long decorations; #define MWM_INPUT_MODELESS 0 -#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 #define MWM_INPUT_SYSTEM_MODAL 2 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 long inputMode; @@ -585,7 +585,7 @@ int xu_ewmh_get_net_wm_desktop(struct client_ctx *, long *); void xu_ewmh_set_net_wm_desktop(struct client_ctx *); Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *, - int, Atom , Atom); + int, Atom, Atom); void xu_ewmh_set_net_wm_state(struct client_ctx *); void xu_ewmh_restore_net_wm_state(struct client_ctx *); diff --git a/client.c b/client.c index e66ca28..9ec2935 100644 --- a/client.c +++ b/client.c @@ -637,7 +637,7 @@ void client_wm_hints(struct client_ctx *cc) { XWMHints *wmh; - + if ((wmh = XGetWMHints(X_Dpy, cc->win)) != NULL) { if ((wmh->flags & InputHint) && (wmh->input)) cc->flags |= CLIENT_INPUT; diff --git a/conf.c b/conf.c index ce8e954..7610400 100644 --- a/conf.c +++ b/conf.c @@ -648,7 +648,7 @@ conf_unbind_mouse(struct conf *c, struct bind_ctx *unbind) struct bind_ctx *mb = NULL, *mbnxt; TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) { - if ((unbind == NULL) || + if ((unbind == NULL) || ((mb->modmask == unbind->modmask) && (mb->press.button == unbind->press.button))) { TAILQ_REMOVE(&c->mousebindq, mb, entry); diff --git a/kbfunc.c b/kbfunc.c index 70eafd6..2f8d95d 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -668,7 +668,7 @@ kbfunc_menu_exec(void *ctx, struct cargs *cargs) /* lstat(2) in case d_type isn't supported. */ if (lstat(tpath, &sb) == -1) continue; - if (!S_ISREG(sb.st_mode) && + if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) continue; } From 4e73ce533c98c54a83fa24c71105bbb1b40a0803 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 27 Feb 2022 14:59:55 +0000 Subject: [PATCH 7/7] cycling fix: when no client is active, warp pointer to last active; from Walter Alejandro Iglesias. --- kbfunc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kbfunc.c b/kbfunc.c index 2f8d95d..f805360 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -450,7 +450,16 @@ kbfunc_client_cycle(void *ctx, struct cargs *cargs) newcc->ptr.x = newcc->geom.w / 2; newcc->ptr.y = newcc->geom.h / 2; } - client_ptr_warp(newcc); + + /* When no client is active, warp pointer to last active. */ + if (oldcc->flags & (CLIENT_ACTIVE)) + client_ptr_warp(newcc); + else if (oldcc->flags & (CLIENT_SKIP_CYCLE)) + client_ptr_warp(newcc); + else { + client_raise(oldcc); + client_ptr_warp(oldcc); + } } void