From c82db690cc0c4624dad4dc6ae899020799ec84db Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 3 Apr 2020 15:36:32 +0200 Subject: [PATCH 1/8] config.mk: fix POSIX_C_SOURCE macro for feature test for snprintf() The feature test was incorrect: _POSIX_C_SOURCE=2 "The value 2 or greater additionally exposes definitions for POSIX.2-1992." http://man7.org/linux/man-pages/man7/feature_test_macros.7.html A higher value is needed (atleast 1995): https://pubs.opengroup.org/onlinepubs/9699919799/functions/snprintf.html FreeBSD feature test macro: on https://github.com/freebsd/freebsd/blob/master/include/stdio.h line 297 This was already fixed in dmenu. This fixes a warning on FreeBSD, reported by Plasmoduck on IRC, thanks. --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 6d36cb7..7084c33 100644 --- a/config.mk +++ b/config.mk @@ -25,7 +25,7 @@ INCS = -I${X11INC} -I${FREETYPEINC} LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} # flags -CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -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} From a8e9513783f335b1ac7255e40a663adfffc4b475 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Mon, 20 Apr 2020 16:41:52 +0100 Subject: [PATCH 2/8] setmfact: Unify bounds for compile-time and runtime mfact There are two places that mfact can be set: - In the mfact global, which is defined at compile time and passed into m->mfact during monitor setup. No bounds checks are performed, but the comment alongside it says that valid values are [0.05..0.95]: static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ - By setmfact, which adjusts m->mfact at runtime. It also does some minimum and maximum bounds checks, allowing [0.1..0.9]. Values outside of that range are ignored, and mfact is not adjusted. These different thresholds mean that one cannot setmfact 0.95 or 0.05, despite the comment above that lists the legal range for mfact. Clarify this by enforcing the same bounds in setmfact at runtime as those listed for mfact at compile time. --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 4465af1..41c6767 100644 --- a/dwm.c +++ b/dwm.c @@ -1520,7 +1520,7 @@ setmfact(const Arg *arg) if (!arg || !selmon->lt[selmon->sellt]->arrange) return; f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; - if (f < 0.1 || f > 0.9) + if (f < 0.05 || f > 0.95) return; selmon->mfact = f; arrange(selmon); From f087d20e6e60a49c756936b4312f5d194d8e63b4 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Wed, 22 Apr 2020 15:48:08 +0100 Subject: [PATCH 3/8] getatomprop: Add forward declaration No functional changes, but for every other function we have a forward declaration here. getatomprop should be no exception. --- dwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dwm.c b/dwm.c index 41c6767..972f261 100644 --- a/dwm.c +++ b/dwm.c @@ -169,6 +169,7 @@ static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); From ed3ab6b4fceded0e9f2d22372df49a2bbd58de66 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Wed, 22 Apr 2020 15:48:27 +0100 Subject: [PATCH 4/8] drawbar: Don't shadow sw global This jarred me a bit while reading the code, since "sw" usually refers to the global screen geometry, but in drawbar() only it refers to text-related geometry. Renaming it makes it more obvious that these are not related. --- dwm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dwm.c b/dwm.c index 972f261..fb1e326 100644 --- a/dwm.c +++ b/dwm.c @@ -696,7 +696,7 @@ dirtomon(int dir) void drawbar(Monitor *m) { - int x, w, sw = 0; + 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; @@ -705,8 +705,8 @@ drawbar(Monitor *m) /* 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]); - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); + tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ + drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); } for (c = m->clients; c; c = c->next) { @@ -729,7 +729,7 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); - if ((w = m->ww - sw - x) > bh) { + if ((w = m->ww - tw - x) > bh) { if (m->sel) { drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); From f09418bbb6651ab4c299cfefbe1d18de401f630e Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 23 Apr 2020 09:50:54 +0200 Subject: [PATCH 5/8] dwm crashes when opening 50+ clients (tile layout) Many users new to dwm find themselves caught out by being kicked out to the login manager (dwm crashing) when they open 50+ clients for demonstration purposes. The number of clients reported varies depending on the resolution of the monitor. The cause of this is due to how the default tile layout calculates the height of the next client based on the position of the previous client. Because clients have a minimum size the (ty) position can exceed that of the window height, resulting in (m->wh - ty) becoming negative. The negative height stored as an unsigned int results in a very large height ultimately resulting in dwm crashing. This patch adds safeguards to prevent the ty and my positions from exceeding that of the window height. --- dwm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index fb1e326..9fd0286 100644 --- a/dwm.c +++ b/dwm.c @@ -1689,11 +1689,13 @@ tile(Monitor *m) if (i < m->nmaster) { h = (m->wh - my) / (MIN(n, m->nmaster) - i); resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); - my += HEIGHT(c); + if (my + HEIGHT(c) < m->wh) + my += HEIGHT(c); } else { h = (m->wh - ty) / (n - i); resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); - ty += HEIGHT(c); + if (ty + HEIGHT(c) < m->wh) + ty += HEIGHT(c); } } From f04cac6d6e39cd9e3fc4fae526e3d1e8df5e34b2 Mon Sep 17 00:00:00 2001 From: Alex Flierl Date: Thu, 11 Jun 2020 15:28:32 +0200 Subject: [PATCH 6/8] Fix memory leaks in drw The function drw_fontset_free in drw.c was never called. --- drw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drw.c b/drw.c index 8fd1ca4..4cdbcbe 100644 --- a/drw.c +++ b/drw.c @@ -95,6 +95,7 @@ drw_free(Drw *drw) { XFreePixmap(drw->dpy, drw->drawable); XFreeGC(drw->dpy, drw->gc); + drw_fontset_free(drw->fonts); free(drw); } From bb2e7222baeec7776930354d0e9f210cc2aaad5f Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 8 Jul 2020 18:05:50 +0200 Subject: [PATCH 7/8] dwm.1: fix wrong text in man page --- dwm.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.1 b/dwm.1 index 13b3729..ddc8321 100644 --- a/dwm.1 +++ b/dwm.1 @@ -33,7 +33,7 @@ dwm draws a small border around windows to indicate the focus state. .SH OPTIONS .TP .B \-v -prints version information to standard output, then exits. +prints version information to stderr, then exits. .SH USAGE .SS Status bar .TP From 61bb8b2241d4db08bea4261c82e27cd9797099e7 Mon Sep 17 00:00:00 2001 From: Ian Remmler Date: Tue, 3 Mar 2020 16:23:53 -0600 Subject: [PATCH 8/8] 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;