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

96
dwl.c
View file

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