aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2026-10-29 10:00:12 +0800
committerXiao Pan <xyz@flylightning.xyz>2026-10-29 10:00:12 +0800
commit454776052281461f8df8a6a998a96aeab72c5fa9 (patch)
tree399cd2ff908906b6dbb983dded61c2afdfb81bd6
parent641403d9c13c4111db4c80ea103febde82818905 (diff)
parentf08763b74e32d83dd5d706ce2090b235ed518a89 (diff)
Merge branch 'master' into flyfly
-rw-r--r--config.def.h2
-rw-r--r--dwm.c56
2 files changed, 36 insertions, 22 deletions
diff --git a/config.def.h b/config.def.h
index eb617a3..8bdc2c9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -69,7 +69,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 char dmenumon[8]; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_base01, "-nf", col_base04, "-sb", col_base0D, "-sf", col_base00, NULL };
static const char *termcmd[] = { "alacritty", NULL };
static const char *lower_volume_cmd[] = { "/bin/sh", "-c", "amixer set Master 5%-; kill -RTMIN+1 $(pidof -x sbar)", NULL };
diff --git a/dwm.c b/dwm.c
index fb42e95..9d29547 100644
--- a/dwm.c
+++ b/dwm.c
@@ -396,7 +396,8 @@ arrange(Monitor *m)
void
arrangemon(Monitor *m)
{
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol) - 1);
+ m->ltsymbol[sizeof(m->ltsymbol) - 1] = '\0';
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
}
@@ -560,6 +561,9 @@ configurenotify(XEvent *e)
/* TODO: updategeom handling sucks, needs to be simplified */
if (ev->window == root) {
+ if (ev->width <= 0 || ev->height <= 0)
+ return;
+
dirty = (sw != ev->width || sh != ev->height);
sw = ev->width;
sh = ev->height;
@@ -643,7 +647,8 @@ createmon(void)
m->topbar = topbar;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
- strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof(m->ltsymbol) - 1);
+ m->ltsymbol[sizeof(m->ltsymbol) - 1] = '\0';
return m;
}
@@ -920,8 +925,9 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
return 0;
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);
+ } else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success) {
+ if (n > 0 && *list)
+ strncpy(text, *list, size - 1);
XFreeStringList(list);
}
text[size - 1] = '\0';
@@ -1515,7 +1521,8 @@ setlayout(const Arg *arg)
selmon->sellt ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol) - 1);
+ selmon->ltsymbol[sizeof(selmon->ltsymbol) - 1] = '\0';
if (selmon->sel)
arrange(selmon);
else
@@ -1649,10 +1656,16 @@ void
spawn(const Arg *arg)
{
struct sigaction sa;
+ pid_t pid;
if (arg->v == dmenucmd)
- dmenumon[0] = '0' + selmon->num;
- if (fork() == 0) {
+ snprintf(dmenumon, sizeof(dmenumon), "%d", selmon->num);
+
+ if ((pid = fork()) == -1) {
+ fprintf(stderr, "dwm: fork failed: %s\n", strerror(errno));
+ return;
+ }
+ if (pid == 0) {
if (dpy)
close(ConnectionNumber(dpy));
setsid();
@@ -1957,7 +1970,8 @@ updatenumlockmask(void)
XModifierKeymap *modmap;
numlockmask = 0;
- modmap = XGetModifierMapping(dpy);
+ if (!(modmap = XGetModifierMapping(dpy)))
+ return;
for (i = 0; i < 8; i++)
for (j = 0; j < modmap->max_keypermod; j++)
if (modmap->modifiermap[i * modmap->max_keypermod + j]
@@ -1976,32 +1990,32 @@ updatesizehints(Client *c)
/* size is uninitialized, ensure that size.flags aren't used */
size.flags = PSize;
if (size.flags & PBaseSize) {
- c->basew = size.base_width;
- c->baseh = size.base_height;
+ c->basew = MAX(0, size.base_width);
+ c->baseh = MAX(0, size.base_height);
} else if (size.flags & PMinSize) {
- c->basew = size.min_width;
- c->baseh = size.min_height;
+ c->basew = MAX(0, size.min_width);
+ c->baseh = MAX(0, size.min_height);
} else
c->basew = c->baseh = 0;
if (size.flags & PResizeInc) {
- c->incw = size.width_inc;
- c->inch = size.height_inc;
+ c->incw = MAX(0, size.width_inc);
+ c->inch = MAX(0, size.height_inc);
} else
c->incw = c->inch = 0;
if (size.flags & PMaxSize) {
- c->maxw = size.max_width;
- c->maxh = size.max_height;
+ c->maxw = MAX(0, size.max_width);
+ c->maxh = MAX(0, size.max_height);
} else
c->maxw = c->maxh = 0;
if (size.flags & PMinSize) {
- c->minw = size.min_width;
- c->minh = size.min_height;
+ c->minw = MAX(0, size.min_width);
+ c->minh = MAX(0, size.min_height);
} else if (size.flags & PBaseSize) {
- c->minw = size.base_width;
- c->minh = size.base_height;
+ c->minw = MAX(0, size.base_width);
+ c->minh = MAX(0, size.base_height);
} else
c->minw = c->minh = 0;
- if (size.flags & PAspect) {
+ if ((size.flags & PAspect) && size.min_aspect.x > 0 && size.max_aspect.y > 0) {
c->mina = (float)size.min_aspect.y / size.min_aspect.x;
c->maxa = (float)size.max_aspect.x / size.max_aspect.y;
} else