code-style: simplify some checks 5e76e7e2
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.
NRK · 2022-08-06 04:27 1 file(s) · +8 −15
dwm.c +8 −15
918 918
	text[0] = '\0';
919 919
	if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems)
920 920
		return 0;
921 -
	if (name.encoding == XA_STRING)
921 +
	if (name.encoding == XA_STRING) {
922 922
		strncpy(text, (char *)name.value, size - 1);
923 -
	else {
924 -
		if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
925 -
			strncpy(text, *list, size - 1);
926 -
			XFreeStringList(list);
927 -
		}
923 +
	} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
924 +
		strncpy(text, *list, size - 1);
925 +
		XFreeStringList(list);
928 926
	}
929 927
	text[size - 1] = '\0';
930 928
	XFree(name.value);
1099 1097
	static XWindowAttributes wa;
1100 1098
	XMapRequestEvent *ev = &e->xmaprequest;
1101 1099
1102 -
	if (!XGetWindowAttributes(dpy, ev->window, &wa))
1103 -
		return;
1104 -
	if (wa.override_redirect)
1100 +
	if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect)
1105 1101
		return;
1106 1102
	if (!wintoclient(ev->window))
1107 1103
		manage(ev->window, &wa);
1602 1598
	grabkeys();
1603 1599
	focus(NULL);
1604 1600
}
1605 -
1606 1601
1607 1602
void
1608 1603
seturgent(Client *c, int urg)
2124 2119
{
2125 2120
	Client *c = selmon->sel;
2126 2121
2127 -
	if (!selmon->lt[selmon->sellt]->arrange
2128 -
	|| (selmon->sel && selmon->sel->isfloating))
2122 +
	if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
2129 2123
		return;
2130 -
	if (c == nexttiled(selmon->clients))
2131 -
		if (!c || !(c = nexttiled(c->next)))
2132 -
			return;
2124 +
	if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
2125 +
		return;
2133 2126
	pop(c);
2134 2127
}
2135 2128