Style: use early-return to clarify code

Use an early return to avoid indenting the main logic instead of
wrapping the tail of a function in an if statement.

No functional change, except for a handful of places where printstatus()
was being called spuriously (tag, toggletag, toggleview).

ΔSLOC: 0
This commit is contained in:
Devin J. Pohly 2023-07-21 20:28:12 -04:00 committed by Leonardo Hernández Hernández
parent 4eb54b55f3
commit d7569870b6
No known key found for this signature in database
GPG key ID: E538897EE11B9624

40
dwl.c
View file

@ -1132,7 +1132,9 @@ destroylocksurface(struct wl_listener *listener, void *data)
m->lock_surface = NULL;
wl_list_remove(&m->destroy_lock_surface.link);
if (lock_surface->surface == seat->keyboard_state.focused_surface) {
if (lock_surface->surface != seat->keyboard_state.focused_surface)
return;
if (locked && cur_lock && !wl_list_empty(&cur_lock->surfaces)) {
surface = wl_container_of(cur_lock->surfaces.next, surface, link);
client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat));
@ -1142,7 +1144,6 @@ destroylocksurface(struct wl_listener *listener, void *data)
wlr_seat_keyboard_clear_focus(seat);
}
}
}
void
destroynotify(struct wl_listener *listener, void *data)
@ -1446,13 +1447,14 @@ keypress(struct wl_listener *listener, void *data)
wl_event_source_timer_update(kb->key_repeat_source, 0);
}
if (!handled) {
if (handled)
return;
/* Pass unhandled keycodes along to the client. */
wlr_seat_set_keyboard(seat, kb->wlr_keyboard);
wlr_seat_keyboard_notify_key(seat, event->time_msec,
event->keycode, event->state);
}
}
void
keypressmod(struct wl_listener *listener, void *data)
@ -1477,13 +1479,14 @@ keyrepeat(void *data)
{
Keyboard *kb = data;
int i;
if (kb->nsyms && kb->wlr_keyboard->repeat_info.rate > 0) {
if (!kb->nsyms || kb->wlr_keyboard->repeat_info.rate <= 0)
return 0;
wl_event_source_timer_update(kb->key_repeat_source,
1000 / kb->wlr_keyboard->repeat_info.rate);
for (i = 0; i < kb->nsyms; i++)
keybinding(kb->mods, kb->keysyms[i]);
}
return 0;
}
@ -2332,11 +2335,12 @@ void
tag(const Arg *arg)
{
Client *sel = focustop(selmon);
if (sel && arg->ui & TAGMASK) {
if (!sel || (arg->ui & TAGMASK) == 0)
return;
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
printstatus();
}
@ -2406,11 +2410,12 @@ toggletag(const Arg *arg)
if (!sel)
return;
newtags = sel->tags ^ (arg->ui & TAGMASK);
if (newtags) {
if (!newtags)
return;
sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
printstatus();
}
@ -2419,11 +2424,12 @@ toggleview(const Arg *arg)
{
uint32_t newtagset = selmon ? selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK) : 0;
if (newtagset) {
if (!newtagset)
return;
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
printstatus();
}
@ -2580,11 +2586,12 @@ urgent(struct wl_listener *listener, void *data)
struct wlr_xdg_activation_v1_request_activate_event *event = data;
Client *c = NULL;
toplevel_from_wlr_surface(event->surface, &c, NULL);
if (c && c != focustop(selmon)) {
if (!c || c == focustop(selmon))
return;
c->isurgent = 1;
printstatus();
}
}
void
view(const Arg *arg)
@ -2742,11 +2749,12 @@ void
sethints(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_hints);
if (c != focustop(selmon)) {
if (c == focustop(selmon))
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus();
}
}
void
xwaylandready(struct wl_listener *listener, void *data)