From 61bb8b2241d4db08bea4261c82e27cd9797099e7 Mon Sep 17 00:00:00 2001 From: Ian Remmler Date: Tue, 3 Mar 2020 16:23:53 -0600 Subject: Fix x coordinate calculation in buttonpress. --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 9fd0286..664c527 100644 --- a/dwm.c +++ b/dwm.c @@ -440,7 +440,7 @@ buttonpress(XEvent *e) arg.ui = 1 << i; } else if (ev->x < x + blw) click = ClkLtSymbol; - else if (ev->x > selmon->ww - TEXTW(stext)) + else if (ev->x > selmon->ww - (int)TEXTW(stext)) click = ClkStatusText; else click = ClkWinTitle; -- cgit v1.2.3-13-gbd6f From 67d76bdc68102df976177de351f65329d8683064 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Thu, 2 Jul 2020 20:18:30 +0100 Subject: Do not allow focus to drift from fullscreen client via focusstack() It generally doesn't make much sense to allow focusstack() to navigate away from the selected fullscreen client, as you can't even see which client you're selecting behind it. I have had this up for a while on the wiki as a separate patch[0], but it seems reasonable to avoid this behaviour in dwm mainline, since I'm struggling to think of any reason to navigate away from a fullscreen client other than a mistake. 0: https://dwm.suckless.org/patches/alwaysfullscreen/ --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 664c527..b0b3466 100644 --- a/dwm.c +++ b/dwm.c @@ -835,7 +835,7 @@ focusstack(const Arg *arg) { Client *c = NULL, *i; - if (!selmon->sel) + if (!selmon->sel || selmon->sel->isfullscreen) return; if (arg->i > 0) { for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); -- cgit v1.2.3-13-gbd6f From 138b405f0c8aa24d8a040cc1a1cf6e3eb5a0ebc7 Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Mon, 12 Jul 2021 23:44:16 +0200 Subject: Add a configuration option for fullscreen locking Some people are annoyed to have this new behaviour forced for some application which use fake fullscreen. --- config.def.h | 1 + dwm.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 1c0b587..a2ac963 100644 --- a/config.def.h +++ b/config.def.h @@ -35,6 +35,7 @@ static const Rule rules[] = { static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const Layout layouts[] = { /* symbol arrange function */ diff --git a/dwm.c b/dwm.c index b0b3466..5e4d494 100644 --- a/dwm.c +++ b/dwm.c @@ -835,7 +835,7 @@ focusstack(const Arg *arg) { Client *c = NULL, *i; - if (!selmon->sel || selmon->sel->isfullscreen) + if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) return; if (arg->i > 0) { for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); -- cgit v1.2.3-13-gbd6f From 716233534b35f74dba5a46ade8f1a6f8cc72fea4 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Mon, 9 Aug 2021 18:24:14 +0200 Subject: Improve speed of drw_text when provided with large strings Calculates len & ew in drw_font_getexts loop by incrementing instead of decrementing; as such avoids proportional increase in time spent in loop based on provided strings size. --- drw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drw.c b/drw.c index 4cdbcbe..9c39086 100644 --- a/drw.c +++ b/drw.c @@ -310,8 +310,11 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (utf8strlen) { drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); /* shorten text if necessary */ - for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) - drw_font_getexts(usedfont, utf8str, len, &ew, NULL); + if (ew > w) + for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++) + drw_font_getexts(usedfont, utf8str, len, &ew, NULL); + else + len = MIN(utf8strlen, sizeof(buf) - 1); if (len) { memcpy(buf, utf8str, len); -- cgit v1.2.3-13-gbd6f From a786211d6cb794fba0ea406d86002c7618998afc Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 20 Aug 2021 23:09:48 +0200 Subject: Revert "Improve speed of drw_text when provided with large strings" This reverts commit 716233534b35f74dba5a46ade8f1a6f8cc72fea4. It causes issues with truncation of characters when the text does not fit and so on. The patch should be reworked and properly tested. --- drw.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drw.c b/drw.c index 9c39086..4cdbcbe 100644 --- a/drw.c +++ b/drw.c @@ -310,11 +310,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (utf8strlen) { drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); /* shorten text if necessary */ - if (ew > w) - for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++) - drw_font_getexts(usedfont, utf8str, len, &ew, NULL); - else - len = MIN(utf8strlen, sizeof(buf) - 1); + for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) + drw_font_getexts(usedfont, utf8str, len, &ew, NULL); if (len) { memcpy(buf, utf8str, len); -- cgit v1.2.3-13-gbd6f From 8657affa2a61e85ca8df76b62e43cb02897d1d80 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Sat, 18 Dec 2021 16:58:23 +0000 Subject: drawbar: Don't expend effort drawing bar if it is occluded I noticed that a non-trivial amount of dwm's work on my machine was from drw_text, which seemed weird, because I have the bar disabled and we only use drw_text as part of bar drawing. Looking more closely, I realised that while we use m->showbar when updating the monitor bar margins, but don't skip actually drawing the bar if it is hidden. This patch skips drawing it entirely if that is the case. On my machine, this takes 10% of dwm's on-CPU time, primarily from restack() and focus(). When the bar is toggled on again, the X server will generate an Expose event, and we'll redraw the bar as normal as part of expose(). --- dwm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dwm.c b/dwm.c index 5e4d494..a96f33c 100644 --- a/dwm.c +++ b/dwm.c @@ -702,6 +702,9 @@ drawbar(Monitor *m) 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]); -- cgit v1.2.3-13-gbd6f From d39e2f3441fe18aba8d1a62c08918a411ec6f237 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 7 Jan 2022 12:39:18 +0100 Subject: bump version to 6.3 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 7084c33..b6eb7e0 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dwm version -VERSION = 6.2 +VERSION = 6.3 # Customize below to fit your system -- cgit v1.2.3-13-gbd6f From 60e9a14998bfe8666c641f7c27fec18e85ac7494 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 11 Mar 2022 20:40:05 +0600 Subject: fix mem leak in cleanup() maybe leak isn't the best word, given that the object lives for the entire duration of the program's lifetime. however, all elements of scheme are free-ed, can't think of any reason why scheme itself should be an exception. --- dwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dwm.c b/dwm.c index a96f33c..1ee4ea2 100644 --- a/dwm.c +++ b/dwm.c @@ -487,6 +487,7 @@ 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); -- cgit v1.2.3-13-gbd6f From bece862a0fc4fc18ef9065b18cd28e2032d0d975 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Mon, 21 Feb 2022 01:10:56 -0500 Subject: manage: For isfloating/oldstate check/set, ensure trans client actually exists In certain instances trans may be set to a window that doesn't actually map to a client via wintoclient; in this case it doesn't make sense to set isfloating/oldstate since trans is essentially invalid in that case / correlates to the above condition check where trans is set / XGetTransientForHint is called. --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 1ee4ea2..5f16260 100644 --- a/dwm.c +++ b/dwm.c @@ -1064,7 +1064,7 @@ manage(Window w, XWindowAttributes *wa) XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); if (!c->isfloating) - c->isfloating = c->oldstate = trans != None || c->isfixed; + c->isfloating = c->oldstate = t || c->isfixed; if (c->isfloating) XRaiseWindow(dpy, c->win); attach(c); -- cgit v1.2.3-13-gbd6f From 8806b6e2379372900e3d9e0bf6604bc7f727350b Mon Sep 17 00:00:00 2001 From: Chris Down Date: Thu, 17 Mar 2022 15:56:13 +0000 Subject: manage: propertynotify: Reduce cost of unused size hints This patch defers all size hint calculations until they are actually needed, drastically reducing the number of calls to updatesizehints(), which can be expensive when called repeatedly (as it currently is during resizes). In my unscientific testing this reduces calls to updatesizehints() by over 90% during a typical work session. There are no functional changes for users other than an increase in responsiveness after resizes and a reduction in CPU time. In slower environments or X servers, this patch also offers an improvement in responsiveness that is often tangible after resizing a client that changes hints during resizes. There are two main motivations to defer this work to the time of hint application: 1. Some clients, especially terminals using incremental size hints, resend XA_WM_NORMAL_HINTS events on resize to avoid fighting with the WM or mouse resizing. For example, some terminals like urxvt clear PBaseSize and PResizeInc during XResizeWindow and restore them afterwards. For this reason, after the resize is concluded, we typically receive a backlogged XA_WM_NORMAL_HINTS message for each update period with movement, which is useless. In some cases one may get hundreds or thousands of XA_WM_NORMAL_HINTS messages on large resizes, and currently all of these result in a separate updatesizehints() call, of which all but the final one are immediately outdated. (We can't just blindly discard these messages during resizes like we do for EnterNotify, because some of them might actually be for other windows, and may not be XA_WM_NORMAL_HINTS events.) 2. For users which use resizehints=0 most of these updates are unused anyway -- in the normal case where the client is not floating these values won't be used, so there's no need to calculate them up front. A synthetic test using the mouse to resize a floating terminal window from roughly 256x256 to 1024x1024 and back again shows that the number of calls to updatesizehints() goes from over 500 before this patch (one for each update interval with movement) to 2 after this patch (one for each hint application), with no change in user visible behaviour. This also reduces the delay before dwm is ready to process new events again after a large resize on such a client, as it avoids the thundering herd of updatesizehints() calls when hundreds of backlogged XA_WM_NORMAL_HINTS messages appear at once after a resize is finished. --- dwm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dwm.c b/dwm.c index 5f16260..d8075ad 100644 --- a/dwm.c +++ b/dwm.c @@ -89,7 +89,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; @@ -345,6 +345,8 @@ 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 */ @@ -1059,7 +1061,6 @@ manage(Window w, XWindowAttributes *wa) XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); configure(c); /* propagates border_width, if size doesn't change */ updatewindowtype(c); - updatesizehints(c); updatewmhints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); @@ -1233,7 +1234,7 @@ propertynotify(XEvent *e) arrange(c->mon); break; case XA_WM_NORMAL_HINTS: - updatesizehints(c); + c->hintsvalid = 0; break; case XA_WM_HINTS: updatewmhints(c); @@ -1989,6 +1990,7 @@ updatesizehints(Client *c) } else c->maxa = c->mina = 0.0; c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); + c->hintsvalid = 1; } void -- cgit v1.2.3-13-gbd6f From d93ff48803f04f1363bf303af1d7e6ccc5cb8d3f Mon Sep 17 00:00:00 2001 From: Santtu Lakkala Date: Mon, 21 Feb 2022 16:58:28 +0200 Subject: Update monitor positions also on removal When monitors are removed, the coordinates of existing monitors may change, if the removed monitors had smaller coordinates than the remaining ones. Remove special case handling so that the same update-if-necessary loop is run also in the case when monitors are removed. --- dwm.c | 68 +++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/dwm.c b/dwm.c index d8075ad..0fc328a 100644 --- a/dwm.c +++ b/dwm.c @@ -1876,42 +1876,42 @@ 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 */ - for (i = nn; i < n; i++) { - for (m = mons; m && m->next; m = m->next); - while ((c = m->clients)) { - dirty = 1; - m->clients = c->next; - detachstack(c); - c->mon = mons; - attach(c); - attachstack(c); - } - if (m == selmon) - selmon = mons; - cleanupmon(m); + /* removed monitors if n > nn */ + for (i = nn; i < n; i++) { + for (m = mons; m && m->next; m = m->next); + while ((c = m->clients)) { + dirty = 1; + m->clients = c->next; + detachstack(c); + c->mon = mons; + attach(c); + attachstack(c); } + if (m == selmon) + selmon = mons; + cleanupmon(m); } free(unique); } else -- cgit v1.2.3-13-gbd6f From a4771de5ba54a38b062a7d748635f21c141b5c7e Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 26 Apr 2022 10:30:59 +0200 Subject: Revert "manage: For isfloating/oldstate check/set, ensure trans client actually exists" This reverts commit bece862a0fc4fc18ef9065b18cd28e2032d0d975. It caused a regression, for example: https://lists.suckless.org/hackers/2203/18220.html --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 0fc328a..823bf6b 100644 --- a/dwm.c +++ b/dwm.c @@ -1065,7 +1065,7 @@ manage(Window w, XWindowAttributes *wa) XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); if (!c->isfloating) - c->isfloating = c->oldstate = t || c->isfixed; + c->isfloating = c->oldstate = trans != None || c->isfixed; if (c->isfloating) XRaiseWindow(dpy, c->win); attach(c); -- cgit v1.2.3-13-gbd6f From a83dc2031050d786ddf5f329b57d658a931c94b7 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 26 Apr 2022 15:50:32 +0200 Subject: LICENSE: add Chris Down --- LICENSE | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE b/LICENSE index d221f09..995172f 100644 --- a/LICENSE +++ b/LICENSE @@ -17,6 +17,7 @@ MIT/X Consortium License © 2015-2016 Quentin Rameau © 2015-2016 Eric Pruitt © 2016-2017 Markus Teich +© 2020-2022 Chris Down Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), -- cgit v1.2.3-13-gbd6f From 8b48e309735f5fe49d35f86e967f4b5dea2a2f2d Mon Sep 17 00:00:00 2001 From: Chris Down Date: Tue, 26 Apr 2022 09:42:23 +0100 Subject: manage: Make sure c->isfixed is applied before floating checks Commit 8806b6e23793 ("manage: propertynotify: Reduce cost of unused size hints") mistakenly removed an early size hints update that's needed to populate c->isfixed for floating checks at manage() time. This resulted in fixed (size hint min dimensions == max dimensions) subset of windows not floating when they should. See https://lists.suckless.org/dev/2204/34730.html for discussion. --- dwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dwm.c b/dwm.c index 823bf6b..5646a5c 100644 --- a/dwm.c +++ b/dwm.c @@ -1061,6 +1061,7 @@ manage(Window w, XWindowAttributes *wa) XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); configure(c); /* propagates border_width, if size doesn't change */ updatewindowtype(c); + updatesizehints(c); updatewmhints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); -- cgit v1.2.3-13-gbd6f From cd0773cee9bad694dc9a6b1355a32bbe61abadff Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 1 May 2022 18:37:54 +0200 Subject: Makefile: add manual path for OpenBSD Reported by fossy , thanks --- config.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/config.mk b/config.mk index b6eb7e0..81c493e 100644 --- a/config.mk +++ b/config.mk @@ -19,6 +19,7 @@ FREETYPELIBS = -lfontconfig -lXft FREETYPEINC = /usr/include/freetype2 # OpenBSD (uncomment) #FREETYPEINC = ${X11INC}/freetype2 +#MANPREFIX = ${PREFIX}/man # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -- cgit v1.2.3-13-gbd6f From d3f93c7c1a13a2a78f04fb41ad1935525df948db Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 10 May 2022 19:07:56 +0200 Subject: sync latest drw.{c,h} changes from dmenu --- drw.c | 88 ++++++++++++++++++++++++++++++++++++++++++++----------------------- drw.h | 1 + 2 files changed, 59 insertions(+), 30 deletions(-) diff --git a/drw.c b/drw.c index 4cdbcbe..ced7d37 100644 --- a/drw.c +++ b/drw.c @@ -251,12 +251,10 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) { - char buf[1024]; - int ty; - unsigned int ew; + int i, ty, ellipsis_x = 0; + unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; XftDraw *d = NULL; Fnt *usedfont, *curfont, *nextfont; - size_t i, len; int utf8strlen, utf8charlen, render = x || y || w || h; long utf8codepoint = 0; const char *utf8str; @@ -264,13 +262,17 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp FcPattern *fcpattern; FcPattern *match; XftResult result; - int charexists = 0; + int charexists = 0, overflow = 0; + /* keep track of a couple codepoints for which we have no match. */ + enum { nomatches_len = 64 }; + static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches; + static unsigned int ellipsis_width = 0; - if (!drw || (render && !drw->scheme) || !text || !drw->fonts) + if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) return 0; if (!render) { - w = ~w; + w = invert ? invert : ~invert; } else { XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); @@ -282,8 +284,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp } usedfont = drw->fonts; + if (!ellipsis_width && render) + ellipsis_width = drw_fontset_getwidth(drw, "..."); while (1) { - utf8strlen = 0; + ew = ellipsis_len = utf8strlen = 0; utf8str = text; nextfont = NULL; while (*text) { @@ -291,9 +295,27 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp for (curfont = drw->fonts; curfont; curfont = curfont->next) { charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); if (charexists) { - if (curfont == usedfont) { + drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL); + if (ew + ellipsis_width <= w) { + /* keep track where the ellipsis still fits */ + ellipsis_x = x + ew; + ellipsis_w = w - ew; + ellipsis_len = utf8strlen; + } + + if (ew + tmpw > w) { + overflow = 1; + /* called from drw_fontset_getwidth_clamp(): + * it wants the width AFTER the overflow + */ + if (!render) + x += tmpw; + else + utf8strlen = ellipsis_len; + } else if (curfont == usedfont) { utf8strlen += utf8charlen; text += utf8charlen; + ew += tmpw; } else { nextfont = curfont; } @@ -301,36 +323,25 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp } } - if (!charexists || nextfont) + if (overflow || !charexists || nextfont) break; else charexists = 0; } if (utf8strlen) { - drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); - /* shorten text if necessary */ - for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) - drw_font_getexts(usedfont, utf8str, len, &ew, NULL); - - if (len) { - memcpy(buf, utf8str, len); - buf[len] = '\0'; - if (len < utf8strlen) - for (i = len; i && i > len - 3; buf[--i] = '.') - ; /* NOP */ - - if (render) { - ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; - XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], - usedfont->xfont, x, ty, (XftChar8 *)buf, len); - } - x += ew; - w -= ew; + if (render) { + ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; + XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], + usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen); } + x += ew; + w -= ew; } + if (render && overflow) + drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert); - if (!*text) { + if (!*text || overflow) { break; } else if (nextfont) { charexists = 0; @@ -340,6 +351,12 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp * character must be drawn. */ charexists = 1; + for (i = 0; i < nomatches_len; ++i) { + /* avoid calling XftFontMatch if we know we won't find a match */ + if (utf8codepoint == nomatches.codepoint[i]) + goto no_match; + } + fccharset = FcCharSetCreate(); FcCharSetAddChar(fccharset, utf8codepoint); @@ -368,6 +385,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp curfont->next = usedfont; } else { xfont_free(usedfont); + nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint; +no_match: usedfont = drw->fonts; } } @@ -397,6 +416,15 @@ drw_fontset_getwidth(Drw *drw, const char *text) return drw_text(drw, 0, 0, 0, 0, 0, text, 0); } +unsigned int +drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) +{ + unsigned int tmp = 0; + if (drw && drw->fonts && text && n) + tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n); + return MIN(n, tmp); +} + void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) { diff --git a/drw.h b/drw.h index 4bcd5ad..6471431 100644 --- a/drw.h +++ b/drw.h @@ -35,6 +35,7 @@ void drw_free(Drw *drw); Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); void drw_fontset_free(Fnt* set); unsigned int drw_fontset_getwidth(Drw *drw, const char *text); +unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); /* Colorscheme abstraction */ -- cgit v1.2.3-13-gbd6f From 9bffa845faa181fb3afe05f3dc86ad79c80736be Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 14 Jul 2022 07:27:34 +0600 Subject: use named parameter for func prototype all the other prototypes use names. --- dwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index 5646a5c..b3c43ee 100644 --- a/dwm.c +++ b/dwm.c @@ -185,7 +185,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 quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); @@ -209,7 +209,7 @@ static void sigchld(int unused); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); -static void tile(Monitor *); +static void tile(Monitor *m); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); -- cgit v1.2.3-13-gbd6f From 6613d9f9a1a5630bab30bc2b70bdc793977073ee Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 14 Jul 2022 07:26:40 +0600 Subject: do not call signal-unsafe function inside sighanlder die() calls vprintf, fputc and exit; none of these are async-signal-safe, see `man 7 signal-safety`. --- dwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index b3c43ee..7c0f978 100644 --- a/dwm.c +++ b/dwm.c @@ -1541,6 +1541,8 @@ setup(void) Atom utf8string; /* clean up any zombies immediately */ + if (signal(SIGCHLD, sigchld) == SIG_ERR) + die("can't install SIGCHLD handler:"); sigchld(0); /* init screen */ @@ -1638,8 +1640,6 @@ 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)); } -- cgit v1.2.3-13-gbd6f From e03248a4d5feaaacb130416be6e467a04de81f78 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 22 Jul 2022 09:18:52 +0200 Subject: Revert "do not call signal-unsafe function inside sighanlder" This reverts commit 6613d9f9a1a5630bab30bc2b70bdc793977073ee. Discussed on the mailinglist: https://lists.suckless.org/hackers/2207/18405.html --- dwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index 7c0f978..b3c43ee 100644 --- a/dwm.c +++ b/dwm.c @@ -1541,8 +1541,6 @@ setup(void) Atom utf8string; /* clean up any zombies immediately */ - if (signal(SIGCHLD, sigchld) == SIG_ERR) - die("can't install SIGCHLD handler:"); sigchld(0); /* init screen */ @@ -1640,6 +1638,8 @@ 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)); } -- cgit v1.2.3-13-gbd6f From 786f6e2a6f8466ad94706781bc93bc6eb6e69512 Mon Sep 17 00:00:00 2001 From: Stein Date: Mon, 1 Aug 2022 11:42:44 +0200 Subject: unmanage: stop listening for events for unmanaged windows This is in particular to avoid flickering in dwm (and high CPU usage) when hovering the mouse over a tabbed window that was previously managed by dwm. Consider the following two scenarios: 1) We start tabbed (window 0xc000003), tabbed is managed by the window manager. We start st being embedded into tabbed. $ st -w 0xc000003 What happens here is that: - tabbed gets a MapRequest for the st window - tabbed reparents the st window - tabbed will receive X events for the window The window manager will have no awareness of the st window and the X server will not send X events to the window manager relating to the st window. There is no flickering or any other issues relating to focus. 2) We start tabbed (window 0xc000003), tabbed is managed by the window manager. We start st as normal (window 0xd400005). What happens here is that: - the window manager gets a MapRequest for the st window - dwm manages the st window as a normal client - dwm will receive X events for the window Now we use xdotool to trigger a reparenting of the st window into tabbed. $ xdotool windowreparent 0xd400005 0xc000003 What happens here is that: - tabbed gets a MapRequest for the st window - tabbed reparents the st window - the window manager gets an UnmapNotify - the window manager no longer manages the st window - both the window manager and tabbed will receive X events for the st window In dwm move the mouse cursor over the tabbed window. What happens now is that: - dwm will receive a FocusIn event for the tabbed window - dwm will set input focus for the tabbed window - tabbed will receive a FocusIn event for the main window - tabbed will give focus to the window on the currently selected tab - which again triggers a FocusIn event which dwm receives - dwm determines that the window that the FocusIn event is for (0xd400005) is not the currently selected client (tabbed) - dwm sets input focus for the tabbed window - this causes an infinite loop as long as the mouse cursor hovers the tabbed window, resulting in flickering and high CPU usage The fix here is to tell the X server that we are no longer interested in receiving events for this window when the window manager stops managing the window. --- dwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dwm.c b/dwm.c index b3c43ee..c0c3b9b 100644 --- a/dwm.c +++ b/dwm.c @@ -1780,6 +1780,7 @@ 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); -- cgit v1.2.3-13-gbd6f From 5b2e5e7a4001479e4dc3e245f96e49f7ea0da658 Mon Sep 17 00:00:00 2001 From: explosion-mental Date: Fri, 29 Jul 2022 18:26:04 -0500 Subject: spawn: reduce 2 lines, change fprintf() + perror() + exit() to die("... :") when calling die and the last character of the string corresponds to ':', die() will call perror(). See util.c Also change EXIT_SUCCESS to EXIT_FAILURE --- dwm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dwm.c b/dwm.c index c0c3b9b..61713b7 100644 --- a/dwm.c +++ b/dwm.c @@ -1653,9 +1653,7 @@ 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]); } } -- cgit v1.2.3-13-gbd6f From 5e76e7e21da042c493c59235ca82d7275f20a7e4 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 6 Aug 2022 04:27:13 +0600 Subject: code-style: simplify some checks main change here is making the `zoom()` logic saner. the rest of the changes are just small stuff which accumulated on my local branch. pop() must not be called with NULL. and `zoom()` achieves this, but in a very (unnecessarily) complicated way: if c == NULL then nexttiled() will return NULL as well, so we enter this branch: if (c == nexttiled(selmon->clients)) in here the !c check fails and the function returns before calling pop() if (!c || !(c = nexttiled(c->next))) return; however, none of this was needed. we can simply return early if c was NULL. Also `c` is set to `selmon->sel` so we can use `c` in the first check instead which makes things shorter. --- dwm.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/dwm.c b/dwm.c index 61713b7..967c9e8 100644 --- a/dwm.c +++ b/dwm.c @@ -918,13 +918,11 @@ 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); @@ -1099,9 +1097,7 @@ 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); @@ -1603,7 +1599,6 @@ setup(void) focus(NULL); } - void seturgent(Client *c, int urg) { @@ -2124,12 +2119,10 @@ 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-13-gbd6f From e0dee911455cee739a5b05a994828f4a37a2764d Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 8 Aug 2022 10:43:09 +0200 Subject: sync code-style patch from libsl --- util.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/util.c b/util.c index fe044fc..96b82c9 100644 --- a/util.c +++ b/util.c @@ -6,18 +6,9 @@ #include "util.h" -void * -ecalloc(size_t nmemb, size_t size) -{ - void *p; - - if (!(p = calloc(nmemb, size))) - die("calloc:"); - return p; -} - void -die(const char *fmt, ...) { +die(const char *fmt, ...) +{ va_list ap; va_start(ap, fmt); @@ -33,3 +24,13 @@ die(const char *fmt, ...) { exit(1); } + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; +} -- cgit v1.2.3-13-gbd6f From a859676ead17017bbe81b4989b2f2e0b00a0b4ba Mon Sep 17 00:00:00 2001 From: Stein Date: Tue, 9 Aug 2022 10:38:08 +0200 Subject: Simplify client y-offset correction The reasoning behind the original line may be lost to time as it does not make much sense checking the position on the x-axis to determine how to position the client on the y-axis. In the context of multi-monitor setups the monitor y position (m->my) may be greater than 0 (say 500), in which case the window could be placed out of view if: - the window attributes have a 0 value for the y position and - we end up using the y position of bh (e.g. 22) If the aim is to avoid a new floating client covering the bar then restricting y position to be at least that of the window area (m->wy) should cover the two cases of using a top bar and using a bottom bar. --- dwm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dwm.c b/dwm.c index 967c9e8..87d0ada 100644 --- a/dwm.c +++ b/dwm.c @@ -1049,9 +1049,7 @@ manage(Window w, XWindowAttributes *wa) 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); + c->y = MAX(c->y, c->mon->wy); c->bw = borderpx; wc.border_width = c->bw; -- cgit v1.2.3-13-gbd6f From 44adafe0069e73aa03a3829d7bb39591cd8b3f1d Mon Sep 17 00:00:00 2001 From: Stein Date: Thu, 11 Aug 2022 11:15:55 +0200 Subject: Make floating windows spawn within the monitor's window area This is a follow-up on this thread: https://lists.suckless.org/hackers/2208/18462.html The orginal code had constraints such that if a window's starting attributes (position and size) were to place the window outside of the edges of the monitor, then the window would be moved into view at the closest monitor edge. There was an exception to this where if a top bar is used then the window should not obscure the bar if present, which meant to place the window within the window area instead. The proposed change here makes it the general rule that floating windows should spawn within the window area rather than within the monitor area. This makes it simple and consistent with no exceptions and it makes the intention of the code clear. This has the benefit of making the behaviour consistent regardless of whether the user is using a top bar or a bottom bar. Additionally this will have an effect on patches that modify the size of the window area. For example if the insets patch is used to reserve space on the left hand side of the monitor for a dock or a vertical bar then new floating clients will not obscure that area. --- dwm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dwm.c b/dwm.c index 87d0ada..f2bc4ba 100644 --- a/dwm.c +++ b/dwm.c @@ -1044,11 +1044,11 @@ manage(Window w, XWindowAttributes *wa) applyrules(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); + 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; -- cgit v1.2.3-13-gbd6f From 5799dd1fca6576b662d299e210cd5933b29d502d Mon Sep 17 00:00:00 2001 From: Stein Date: Mon, 15 Aug 2022 14:31:22 +0200 Subject: Remove blw variable in favour of calculating the value when needed The purpose and reasoning behind the bar layout width (blw) variable in dwm the way it is today may not be immediately obvious. The use of the variable makes more sense when looking at commit 2ce37bc from 2009 where blw was initialised in the setup function and it represented the maximum of all available layout symbols. for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { w = TEXTW(layouts[i].symbol); blw = MAX(blw, w); } As such the layout symbol back then was fixed in size and both drawbar and buttonpress depended on this variable. The the way the blw variable is set today in drawbar means that it merely caches the size of the layout symbol for the last bar drawn. While unlikely to happen in practice it is possible that the last bar drawn is not that of the currently selected monitor, which can result in misaligned button clicks if there is a difference in layout symbol width between monitors. --- dwm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dwm.c b/dwm.c index f2bc4ba..253aba7 100644 --- a/dwm.c +++ b/dwm.c @@ -240,7 +240,7 @@ static const char broken[] = "broken"; static char stext[256]; 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; @@ -440,7 +440,7 @@ 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 > selmon->ww - (int)TEXTW(stext)) click = ClkStatusText; @@ -731,7 +731,7 @@ drawbar(Monitor *m) 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); -- cgit v1.2.3-13-gbd6f From 84d7322113c2bf023f5eaa8537fb0e72d4105046 Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 18 Aug 2022 22:13:08 +0600 Subject: config.def.h: make keys and buttons const pretty much all other variables are declared as const when they're not modified. --- config.def.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index a2ac963..9efa774 100644 --- a/config.def.h +++ b/config.def.h @@ -60,7 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; -static Key keys[] = { +static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, @@ -99,7 +99,7 @@ static Key keys[] = { /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ -static Button buttons[] = { +static const Button buttons[] = { /* click event mask button function argument */ { ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, -- cgit v1.2.3-13-gbd6f From c2b748e7931e5f28984efc236f9b1a212dbc65e8 Mon Sep 17 00:00:00 2001 From: Stein Date: Fri, 26 Aug 2022 14:48:46 +0200 Subject: Remove dmenumon variable Reasoning: Since 2011 dmenu has been capable of working out which monitor currently has focus in a Xinerama setup, making the use of the -m flag more or less redundant. This is easily demonstrated by using dmenu in any other window manager. There used to be a nodmenu patch that provided these changes: https://git.suckless.org/sites/commit/ed68e3629de4ef2ca2d3f8893a79fb570b4c0cbc.html but this was removed on the basis that it was very easy to work out and apply manually if needed. The proposal here is to remove this dependency from dwm. The mechanism of the dmenumon variable could be provided via a patch if need be. The edge case scenario that dmenu does not handle on its own, and the effect of removing this mechanism, is that if the user trigger focusmon via keybindings to change focus to another monitor that has no clients, then dmenu will open on the monitor containing the window with input focus (or the monitor with the mouse cursor if no windows have input focus). If this edge case is important to cover then this can be addressed by setting input focus to selmon->barwin in the focus function if there is no client to give focus to (rather than giving focus back to the root window). --- config.def.h | 3 +-- dwm.c | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 9efa774..061ad66 100644 --- a/config.def.h +++ b/config.def.h @@ -56,8 +56,7 @@ static const Layout layouts[] = { #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ -static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; static const Key keys[] = { diff --git a/dwm.c b/dwm.c index 253aba7..e5efb6a 100644 --- a/dwm.c +++ b/dwm.c @@ -1639,8 +1639,6 @@ sigchld(int unused) void spawn(const Arg *arg) { - if (arg->v == dmenucmd) - dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); -- cgit v1.2.3-13-gbd6f From 970f37697358574e127019eb0ee2f5725ec05ce0 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 16 Sep 2022 23:06:47 +0200 Subject: remove workaround for a crash with color emojis on some systems, now fixed in libXft 2.3.5 https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/libXft-2.3.5/NEWS --- drw.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drw.c b/drw.c index ced7d37..a58a2b4 100644 --- a/drw.c +++ b/drw.c @@ -133,19 +133,6 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) die("no font specified."); } - /* Do not allow using color fonts. This is a workaround for a BadLength - * error from Xft with color glyphs. Modelled on the Xterm workaround. See - * https://bugzilla.redhat.com/show_bug.cgi?id=1498269 - * https://lists.suckless.org/dev/1701/30932.html - * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 - * and lots more all over the internet. - */ - FcBool iscol; - if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { - XftFontClose(drw->dpy, xfont); - return NULL; - } - font = ecalloc(1, sizeof(Fnt)); font->xfont = xfont; font->pattern = pattern; @@ -368,7 +355,6 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp fcpattern = FcPatternDuplicate(drw->fonts->pattern); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); - FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcDefaultSubstitute(fcpattern); -- cgit v1.2.3-13-gbd6f From 50ad171eea9db5ccb36fce2592e047c3282975ff Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 4 Oct 2022 19:35:13 +0200 Subject: bump version to 6.4 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 81c493e..ef8acf7 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dwm version -VERSION = 6.3 +VERSION = 6.4 # Customize below to fit your system -- cgit v1.2.3-13-gbd6f From ba56fe9fea0a28d8184a727a987836a0903e2682 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 28 Oct 2022 16:37:56 +0200 Subject: Revert "Remove dmenumon variable" This reverts commit c2b748e7931e5f28984efc236f9b1a212dbc65e8. Revert back this change. It seems to not be an edge-case anymore since multiple users have asked about this new behaviour now. --- config.def.h | 3 ++- dwm.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 061ad66..9efa774 100644 --- a/config.def.h +++ b/config.def.h @@ -56,7 +56,8 @@ static const Layout layouts[] = { #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ -static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; static const Key keys[] = { diff --git a/dwm.c b/dwm.c index e5efb6a..253aba7 100644 --- a/dwm.c +++ b/dwm.c @@ -1639,6 +1639,8 @@ sigchld(int unused) void spawn(const Arg *arg) { + if (arg->v == dmenucmd) + dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); -- cgit v1.2.3-13-gbd6f From 89f9905714c1c1b2e8b09986dfbeca15b68d8af8 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Wed, 7 Dec 2022 14:55:08 +0000 Subject: grabkeys: Avoid missing events when a keysym maps to multiple keycodes It's not uncommon for one keysym to map to multiple keycodes. For example, the "play" button on my keyboard sends keycode 172, but my bluetooth headphones send keycode 208, both of which map back to XF86AudioPlay: % xmodmap -pke | grep XF86AudioPlay keycode 172 = XF86AudioPlay XF86AudioPause XF86AudioPlay XF86AudioPause keycode 208 = XF86AudioPlay NoSymbol XF86AudioPlay keycode 215 = XF86AudioPlay NoSymbol XF86AudioPlay This is a problem because the current code only grabs a single one of these keycodes, which means that events for any other keycode also mapping to the bound keysym will not be handled by dwm. In my case, this means that binding XF86AudioPlay does the right thing and correctly handles my keyboard's keys, but does nothing on my headphones. I'm not the only person affected by this, there are other reports[0]. In order to fix this, we look at the mappings between keycodes and keysyms at grabkeys() time and pick out all matching keycodes rather than just the first one. The keypress() side of this doesn't need any changes because the keycode gets converted back to a canonical keysym before any action is taken. 0: https://github.com/cdown/dwm/issues/11 --- dwm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/dwm.c b/dwm.c index 253aba7..03baf42 100644 --- a/dwm.c +++ b/dwm.c @@ -955,16 +955,26 @@ 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); } } -- cgit v1.2.3-13-gbd6f From 712d6639ff8e863560328131bbb92b248dc9cde7 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Sat, 28 Jan 2023 12:53:48 +0100 Subject: Use sigaction(SA_NOCLDWAIT) for SIGCHLD handling signal() semantics are pretty unclearly specified. For example, depending on OS kernel and libc, the handler may be returned to SIG_DFL (hence the inner call to read the signal handler). Moving to sigaction() means the behaviour is consistently defined. Using SA_NOCLDWAIT also allows us to avoid calling the non-reentrant function die() in the handler. Some addditional notes for archival purposes: * NRK pointed out errno of waitpid could also theoretically get clobbered. * The original patch was iterated on and modified by NRK and Hiltjo: * SIG_DFL was changed to SIG_IGN, this is required, atleast on older systems such as tested on Slackware 11. * signals are not blocked using sigprocmask, because in theory it would briefly for example also ignore a SIGTERM signal. It is OK if waitpid() is (in theory interrupted). POSIX reference: "Consequences of Process Termination": https://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html#tag_16_01_03_01 --- dwm.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dwm.c b/dwm.c index 03baf42..c2bd871 100644 --- a/dwm.c +++ b/dwm.c @@ -205,7 +205,6 @@ static void setmfact(const Arg *arg); static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); -static void sigchld(int unused); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -1543,9 +1542,16 @@ 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); /* init screen */ screen = DefaultScreen(dpy); @@ -1638,14 +1644,6 @@ 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 spawn(const Arg *arg) { -- cgit v1.2.3-13-gbd6f From 348f6559ab0d4793db196ffa56ba96ab95a594a6 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 17 Feb 2023 11:05:09 +0600 Subject: config.mk: update to _XOPEN_SOURCE=700L SA_NOCLDWAIT is marked as XSI in the posix spec [0] and FreeBSD and NetBSD seems to more be strict about the feature test macro [1]. so update the macro to use _XOPEN_SOURCE=700L instead, which is equivalent to _POSIX_C_SOURCE=200809L except that it also unlocks the X/Open System Interfaces. [0]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html#tag_13_42 [1]: https://lists.suckless.org/dev/2302/35111.html Tested on: * NetBSD 9.3 (fixed). * FreeBSD 13 (fixed). * Void Linux musl. * Void Linux glibc. * OpenBSD 7.2 (stable). * Slackware 11. Reported-by: beastie --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index ef8acf7..ba64d3d 100644 --- a/config.mk +++ b/config.mk @@ -26,7 +26,7 @@ INCS = -I${X11INC} -I${FREETYPEINC} LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} # flags -CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} -- cgit v1.2.3-13-gbd6f From e81f17d4c196aaed6893fd4beed49991caa3e2a4 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 9 Apr 2023 12:37:14 +0200 Subject: restore SIGCHLD sighandler to default before spawning a program From sigaction(2): A child created via fork(2) inherits a copy of its parent's signal dispositions. During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged. This refused to start directly some programs from configuring in config.h: static Key keys[] = { MODKEY, XK_o, spawn, {.v = cmd } }, }; Some reported programs that didn't start were: mpv, anki, dmenu_extended. Reported by pfx. Initial patch suggestion by Storkman. --- dwm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dwm.c b/dwm.c index c2bd871..f1d86b2 100644 --- a/dwm.c +++ b/dwm.c @@ -1647,12 +1647,20 @@ showhide(Client *c) void spawn(const Arg *arg) { + struct sigaction sa; + if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); setsid(); + + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &sa, NULL); + execvp(((char **)arg->v)[0], (char **)arg->v); die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); } -- cgit v1.2.3-13-gbd6f From 9f8855343c881bdc01b9fff5b956537ba1106b76 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 22 Sep 2023 15:13:29 +0200 Subject: Makefile: remove the options target The Makefile used to suppress output (by using @), so this target made sense at the time. But the Makefile should be simple and make debugging with less abstractions or fancy printing. The Makefile was made verbose and doesn't hide the build output, so remove this target. Prompted by a question on the mailing list about the options target. --- Makefile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 77bcbc0..ffa69b4 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,7 @@ include config.mk SRC = drw.c dwm.c util.c OBJ = ${SRC:.c=.o} -all: options dwm - -options: - @echo dwm build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" +all: dwm .c.o: ${CC} -c ${CFLAGS} $< @@ -48,4 +42,4 @@ uninstall: rm -f ${DESTDIR}${PREFIX}/bin/dwm\ ${DESTDIR}${MANPREFIX}/man1/dwm.1 -.PHONY: all options clean dist install uninstall +.PHONY: all clean dist install uninstall -- cgit v1.2.3-13-gbd6f From 061e9fe9a7db396c0c4f3d996c3908fb43a6d50c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 19 Mar 2024 12:13:16 +0100 Subject: bump version to 6.5 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index ba64d3d..8efca9a 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dwm version -VERSION = 6.4 +VERSION = 6.5 # Customize below to fit your system -- cgit v1.2.3-13-gbd6f