code-style: simplify some checks
authorNRK <nrk@disroot.org>
Fri, 5 Aug 2022 22:27:13 +0000 (04:27 +0600)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 6 Aug 2022 14:09:01 +0000 (16:09 +0200)
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

diff --git a/dwm.c b/dwm.c
index 61713b733f8e758c3fef6c4187749d7bee5f2ad5..967c9e8bf9c294d27fbb7c252c60483d037ec9e8 100644 (file)
--- 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);
 }