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; 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)
return;
if (locked && cur_lock && !wl_list_empty(&cur_lock->surfaces)) { if (locked && cur_lock && !wl_list_empty(&cur_lock->surfaces)) {
surface = wl_container_of(cur_lock->surfaces.next, surface, link); surface = wl_container_of(cur_lock->surfaces.next, surface, link);
client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat)); client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat));
@ -1141,7 +1143,6 @@ destroylocksurface(struct wl_listener *listener, void *data)
} else { } else {
wlr_seat_keyboard_clear_focus(seat); wlr_seat_keyboard_clear_focus(seat);
} }
}
} }
void void
@ -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)
return;
/* Pass unhandled keycodes along to the client. */ /* Pass unhandled keycodes along to the client. */
wlr_seat_set_keyboard(seat, kb->wlr_keyboard); wlr_seat_set_keyboard(seat, kb->wlr_keyboard);
wlr_seat_keyboard_notify_key(seat, event->time_msec, wlr_seat_keyboard_notify_key(seat, event->time_msec,
event->keycode, event->state); 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)
return 0;
wl_event_source_timer_update(kb->key_repeat_source, wl_event_source_timer_update(kb->key_repeat_source,
1000 / kb->wlr_keyboard->repeat_info.rate); 1000 / kb->wlr_keyboard->repeat_info.rate);
for (i = 0; i < kb->nsyms; i++) for (i = 0; i < kb->nsyms; i++)
keybinding(kb->mods, kb->keysyms[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)
return;
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon); 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)
return;
sel->tags = newtags; sel->tags = newtags;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon); 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)
return;
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon); 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))
return;
c->isurgent = 1; c->isurgent = 1;
printstatus(); 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))
return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus(); printstatus();
}
} }
void void