From aa0d4fb092382f4fb8f1691434c9c3c1cb8b108b Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Fri, 5 May 2023 00:52:35 +0200 Subject: Bump to 6.4 --- dwm.c | 248 +++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 140 insertions(+), 108 deletions(-) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 72282e9..6c3fe93 100644 --- a/dwm.c +++ b/dwm.c @@ -128,7 +128,7 @@ struct Client { float mina, maxa; int x, y, w, h; int oldx, oldy, oldw, oldh; - int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid; int bw, oldbw; unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, @@ -244,7 +244,7 @@ static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); -static void pop(Client *); +static void pop(Client *c); static void propertynotify(XEvent *e); static void pushstack(const Arg *arg); static void quit(const Arg *arg); @@ -322,7 +322,7 @@ static int dwmblockssig; pid_t dwmblockspid = 0; static int screen; static int sw, sh; /* X display screen geometry width, height */ -static int bh, blw = 0; /* bar geometry */ +static int bh; /* bar height */ static int lrpad; /* sum of left and right padding for text */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; @@ -435,6 +435,8 @@ int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) { if (*w < bh) *w = bh; if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { + if (!c->hintsvalid) + updatesizehints(c); /* see last two sentences in ICCCM 4.1.2.3 */ baseismin = c->basew == c->minw && c->baseh == c->minh; if (!baseismin) { /* temporarily remove base dimensions */ @@ -579,9 +581,9 @@ void buttonpress(XEvent *e) { if (i < LENGTH(tags)) { click = ClkTagBar; arg.ui = 1 << i; - } else if (ev->x < x + blw) + } else if (ev->x < x + TEXTW(selmon->ltsymbol)) click = ClkLtSymbol; - else if (ev->x > (x = selmon->ww - TEXTW(stext) + lrpad)) { + else if (ev->x > (x = selmon->ww - (int)TEXTW(stext) + lrpad)) { click = ClkStatusText; char *text = rawstext; @@ -644,6 +646,7 @@ void cleanup(void) { drw_cur_free(drw, cursor[i]); for (i = 0; i < LENGTH(colors); i++) free(scheme[i]); + free(scheme); XDestroyWindow(dpy, wmcheckwin); drw_free(drw); XSync(dpy, False); @@ -727,7 +730,8 @@ void configurenotify(XEvent *e) { } } -void configurerequest(XEvent *e) { +void +configurerequest(XEvent *e) { Client *c; Monitor *m; XConfigureRequestEvent *ev = &e->xconfigurerequest; @@ -778,7 +782,8 @@ void configurerequest(XEvent *e) { XSync(dpy, False); } -void copyvalidchars(char *text, char *rawtext) { +void +copyvalidchars(char *text, char *rawtext) { int i = -1, j = 0; while (rawtext[++i]) { @@ -789,7 +794,8 @@ void copyvalidchars(char *text, char *rawtext) { text[j] = '\0'; } -Monitor *createmon(void) { +Monitor * +createmon(void) { Monitor *m; m = ecalloc(1, sizeof(Monitor)); @@ -808,7 +814,8 @@ Monitor *createmon(void) { return m; } -void destroynotify(XEvent *e) { +void +destroynotify(XEvent *e) { Client *c; XDestroyWindowEvent *ev = &e->xdestroywindow; @@ -819,7 +826,8 @@ void destroynotify(XEvent *e) { unmanage(c->swallowing, 1); } -void detach(Client *c) { +void +detach(Client *c) { Client **tc; for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next) @@ -827,7 +835,8 @@ void detach(Client *c) { *tc = c->next; } -void detachstack(Client *c) { +void +detachstack(Client *c) { Client **tc, *t; for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext) @@ -841,7 +850,8 @@ void detachstack(Client *c) { } } -Monitor *dirtomon(int dir) { +Monitor * +dirtomon(int dir) { Monitor *m = NULL; if (dir > 0) { @@ -856,13 +866,17 @@ Monitor *dirtomon(int dir) { return m; } -void drawbar(Monitor *m) { +void +drawbar(Monitor *m) { int x, w, tw = 0; int boxs = drw->fonts->h / 9; int boxw = drw->fonts->h / 6 + 2; unsigned int i, occ = 0, urg = 0; Client *c; + if(!m->showbar) + return; + /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ drw_setscheme(drw, scheme[SchemeNorm]); @@ -887,7 +901,7 @@ void drawbar(Monitor *m) { drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); x += w; } - w = blw = TEXTW(m->ltsymbol); + w = TEXTW(m->ltsymbol); drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); @@ -905,14 +919,16 @@ void drawbar(Monitor *m) { drw_map(drw, m->barwin, 0, 0, m->ww, bh); } -void drawbars(void) { +void +drawbars(void) { Monitor *m; for (m = mons; m; m = m->next) drawbar(m); } -void enternotify(XEvent *e) { +void +enternotify(XEvent *e) { Client *c; Monitor *m; XCrossingEvent *ev = &e->xcrossing; @@ -930,7 +946,8 @@ void enternotify(XEvent *e) { focus(c); } -void expose(XEvent *e) { +void +expose(XEvent *e) { Monitor *m; XExposeEvent *ev = &e->xexpose; @@ -938,7 +955,8 @@ void expose(XEvent *e) { drawbar(m); } -void focus(Client *c) { +void +focus(Client *c) { if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext) ; @@ -963,14 +981,16 @@ void focus(Client *c) { } /* there are some broken focus acquiring clients needing extra handling */ -void focusin(XEvent *e) { +void +focusin(XEvent *e) { XFocusChangeEvent *ev = &e->xfocus; if (selmon->sel && ev->window != selmon->sel->win) setfocus(selmon->sel); } -void focusmon(const Arg *arg) { +void +focusmon(const Arg *arg) { Monitor *m; if (!mons->next) @@ -982,11 +1002,12 @@ void focusmon(const Arg *arg) { focus(NULL); } -void focusstack(const Arg *arg) { +void +focusstack(const Arg *arg) { int i = stackpos(arg); Client *c, *p; - if (i < 0 || !selmon->sel || selmon->sel->isfullscreen) + if (i < 0 || !selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) return; for (p = NULL, c = selmon->clients; c && (i || !ISVISIBLE(c)); @@ -996,7 +1017,8 @@ void focusstack(const Arg *arg) { restack(selmon); } -Atom getatomprop(Client *c, Atom prop) { +Atom +getatomprop(Client *c, Atom prop) { int di; unsigned long dl; unsigned char *p = NULL; @@ -1012,7 +1034,8 @@ Atom getatomprop(Client *c, Atom prop) { } #ifndef __OpenBSD__ -int getdwmblockspid() { +int +getdwmblockspid() { char buf[16]; FILE *fp = popen("pidof -s dwmblocks", "r"); fgets(buf, sizeof(buf), fp); @@ -1023,7 +1046,8 @@ int getdwmblockspid() { } #endif -int getrootptr(int *x, int *y) { +int +getrootptr(int *x, int *y) { int di; unsigned int dui; Window dummy; @@ -1031,7 +1055,8 @@ int getrootptr(int *x, int *y) { return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui); } -long getstate(Window w) { +long +getstate(Window w) { int format; long result = -1; unsigned char *p = NULL; @@ -1048,7 +1073,8 @@ long getstate(Window w) { return result; } -int gettextprop(Window w, Atom atom, char *text, unsigned int size) { +int +gettextprop(Window w, Atom atom, char *text, unsigned int size) { char **list = NULL; int n; XTextProperty name; @@ -1058,21 +1084,19 @@ int gettextprop(Window w, Atom atom, char *text, unsigned int size) { text[0] = '\0'; if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) return 0; - if (name.encoding == XA_STRING) + if (name.encoding == XA_STRING) { strncpy(text, (char *)name.value, size - 1); - else { - if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && - *list) { - strncpy(text, *list, size - 1); - XFreeStringList(list); - } + } else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { + strncpy(text, *list, size - 1); + XFreeStringList(list); } text[size - 1] = '\0'; XFree(name.value); return 1; } -void grabbuttons(Client *c, int focused) { +void +grabbuttons(Client *c, int focused) { updatenumlockmask(); { unsigned int i, j; @@ -1091,24 +1115,36 @@ void grabbuttons(Client *c, int focused) { } } -void grabkeys(void) { +void +grabkeys(void) { updatenumlockmask(); { - unsigned int i, j; + unsigned int i, j, k; unsigned int modifiers[] = {0, LockMask, numlockmask, numlockmask | LockMask}; - KeyCode code; + int start, end, skip; + KeySym *syms; XUngrabKey(dpy, AnyKey, AnyModifier, root); - for (i = 0; i < LENGTH(keys); i++) - if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) - for (j = 0; j < LENGTH(modifiers); j++) - XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, - GrabModeAsync, GrabModeAsync); + XDisplayKeycodes(dpy, &start, &end); + syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip); + if (!syms) + return; + for (k = start; k <= end; k++) + for (i = 0; i < LENGTH(keys); i++) + /* skip modifier codes, we do that ourselves */ + if (keys[i].keysym == syms[(k - start) * skip]) + for (j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, k, + keys[i].mod | modifiers[j], + root, True, + GrabModeAsync, GrabModeAsync); + XFree(syms); } } -void incnmaster(const Arg *arg) { +void +incnmaster(const Arg *arg) { selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); arrange(selmon); } @@ -1124,7 +1160,8 @@ static int isuniquegeom(XineramaScreenInfo *unique, size_t n, } #endif /* XINERAMA */ -void keypress(XEvent *e) { +void +keypress(XEvent *e) { unsigned int i; KeySym keysym; XKeyEvent *ev; @@ -1137,7 +1174,8 @@ void keypress(XEvent *e) { keys[i].func(&(keys[i].arg)); } -void killclient(const Arg *arg) { +void +killclient(const Arg *arg) { if (!selmon->sel) return; if (!sendevent(selmon->sel, wmatom[WMDelete])) { @@ -1151,7 +1189,8 @@ void killclient(const Arg *arg) { } } -void manage(Window w, XWindowAttributes *wa) { +void +manage(Window w, XWindowAttributes *wa) { Client *c, *t = NULL, *term = NULL; Window trans = None; XWindowChanges wc; @@ -1176,17 +1215,12 @@ void manage(Window w, XWindowAttributes *wa) { term = termforwin(c); } - if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) - c->x = c->mon->mx + c->mon->mw - WIDTH(c); - if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh) - c->y = c->mon->my + c->mon->mh - HEIGHT(c); - c->x = MAX(c->x, c->mon->mx); - /* only fix client y-offset, if the client center might cover the bar */ - c->y = MAX(c->y, - ((c->mon->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx) && - (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) - ? bh - : c->mon->my); + if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww) + c->x = c->mon->wx + c->mon->ww - WIDTH(c); + if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh) + c->y = c->mon->wy + c->mon->wh - HEIGHT(c); + c->x = MAX(c->x, c->mon->wx); + c->y = MAX(c->y, c->mon->wy); c->bw = borderpx; wc.border_width = c->bw; @@ -1223,7 +1257,8 @@ void manage(Window w, XWindowAttributes *wa) { focus(NULL); } -void mappingnotify(XEvent *e) { +void +mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; XRefreshKeyboardMapping(ev); @@ -1231,13 +1266,12 @@ void mappingnotify(XEvent *e) { grabkeys(); } -void maprequest(XEvent *e) { +void +maprequest(XEvent *e) { static XWindowAttributes wa; XMapRequestEvent *ev = &e->xmaprequest; - if (!XGetWindowAttributes(dpy, ev->window, &wa)) - return; - if (wa.override_redirect) + if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect) return; if (!wintoclient(ev->window)) manage(ev->window, &wa); @@ -1704,9 +1738,16 @@ void setup(void) { int i; XSetWindowAttributes wa; Atom utf8string; + struct sigaction sa; - /* clean up any zombies immediately */ - sigchld(0); + /* do not transform children into zombies when they terminate */ + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART; + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); + + /* clean up any zombies (inherited from .xinitrc etc) immediately */ + while (waitpid(-1, NULL, WNOHANG) > 0); signal(SIGHUP, sighup); signal(SIGTERM, sigterm); @@ -1784,7 +1825,8 @@ void seturgent(Client *c, int urg) { XFree(wmh); } -void showhide(Client *c) { +void +showhide(Client *c) { if (!c) return; if (ISVISIBLE(c)) { @@ -1805,14 +1847,8 @@ void showhide(Client *c) { } } -void sigchld(int unused) { - if (signal(SIGCHLD, sigchld) == SIG_ERR) - die("can't install SIGCHLD handler:"); - while (0 < waitpid(-1, NULL, WNOHANG)) - ; -} - -void sighup(int unused) { +void +sighup(int unused) { Arg a = {.i = 1}; quit(&a); } @@ -1845,9 +1881,7 @@ void spawn(const Arg *arg) { close(ConnectionNumber(dpy)); setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); - fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); - perror(" failed"); - exit(EXIT_SUCCESS); + die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); } } @@ -1981,6 +2015,7 @@ void unmanage(Client *c, int destroyed) { wc.border_width = c->oldbw; XGrabServer(dpy); /* avoid race conditions */ XSetErrorHandler(xerrordummy); + XSelectInput(dpy, c->win, NoEventMask); XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ XUngrabButton(dpy, AnyButton, AnyModifier, c->win); setclientstate(c, WithdrawnState); @@ -2070,30 +2105,30 @@ int updategeom(void) { memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); XFree(info); nn = j; - if (n <= nn) { /* new monitors available */ - for (i = 0; i < (nn - n); i++) { - for (m = mons; m && m->next; m = m->next) - ; - if (m) - m->next = createmon(); - else - mons = createmon(); + /* new monitors if nn > n */ + for (i = n; i < nn; i++) { + for (m = mons; m && m->next; m = m->next); + if (m) + m->next = createmon(); + else + mons = createmon(); + } + for (i = 0, m = mons; i < nn && m; m = m->next, i++) + if (i >= n + || unique[i].x_org != m->mx || unique[i].y_org != m->my + || unique[i].width != m->mw || unique[i].height != m->mh) + { + dirty = 1; + m->num = i; + m->mx = m->wx = unique[i].x_org; + m->my = m->wy = unique[i].y_org; + m->mw = m->ww = unique[i].width; + m->mh = m->wh = unique[i].height; + updatebarpos(m); } - for (i = 0, m = mons; i < nn && m; m = m->next, i++) - if (i >= n || unique[i].x_org != m->mx || unique[i].y_org != m->my || - unique[i].width != m->mw || unique[i].height != m->mh) { - dirty = 1; - m->num = i; - m->mx = m->wx = unique[i].x_org; - m->my = m->wy = unique[i].y_org; - m->mw = m->ww = unique[i].width; - m->mh = m->wh = unique[i].height; - updatebarpos(m); - } - } else { /* less monitors available nn < n */ + /* removed monitors if n > nn */ for (i = nn; i < n; i++) { - for (m = mons; m && m->next; m = m->next) - ; + for (m = mons; m && m->next; m = m->next); while ((c = m->clients)) { dirty = 1; m->clients = c->next; @@ -2101,11 +2136,10 @@ int updategeom(void) { c->mon = mons; attach(c); attachstack(c); - } - if (m == selmon) - selmon = mons; - cleanupmon(m); } + if (m == selmon) + selmon = mons; + cleanupmon(m); } free(unique); } else @@ -2390,12 +2424,10 @@ int xerrorstart(Display *dpy, XErrorEvent *ee) { void zoom(const Arg *arg) { Client *c = selmon->sel; - if (!selmon->lt[selmon->sellt]->arrange || - (selmon->sel && selmon->sel->isfloating)) + if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating) + return; + if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) return; - if (c == nexttiled(selmon->clients)) - if (!c || !(c = nexttiled(c->next))) - return; pop(c); } -- cgit v1.2.3-70-g09d2