Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Style: use early-return to clarify code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
djpohly committed Jul 22, 2023
1 parent 0a4142b commit 8d71123
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions dwl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,15 +1138,16 @@ 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 (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));
} else if (!locked) {
focusclient(focustop(selmon), 1);
} else {
wlr_seat_keyboard_clear_focus(seat);
}
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));
} else if (!locked) {
focusclient(focustop(selmon), 1);
} else {
wlr_seat_keyboard_clear_focus(seat);
}
}

Expand Down Expand Up @@ -1452,12 +1453,13 @@ keypress(struct wl_listener *listener, void *data)
wl_event_source_timer_update(kb->key_repeat_source, 0);
}

if (!handled) {
/* 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);
}
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
Expand All @@ -1483,13 +1485,14 @@ keyrepeat(void *data)
{
Keyboard *kb = data;
int i;
if (kb->nsyms && kb->wlr_keyboard->repeat_info.rate > 0) {
wl_event_source_timer_update(kb->key_repeat_source,
1000 / kb->wlr_keyboard->repeat_info.rate);
if (!kb->nsyms || kb->wlr_keyboard->repeat_info.rate <= 0)
return 0;

for (i = 0; i < kb->nsyms; i++)
keybinding(kb->mods, kb->keysyms[i]);
}
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;
}
Expand Down Expand Up @@ -2335,11 +2338,12 @@ void
tag(const Arg *arg)
{
Client *sel = focustop(selmon);
if (sel && arg->ui & TAGMASK) {
sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
if (!sel || (arg->ui & TAGMASK) == 0)
return;

sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
}

Expand Down Expand Up @@ -2409,11 +2413,12 @@ toggletag(const Arg *arg)
if (!sel)
return;
newtags = sel->tags ^ (arg->ui & TAGMASK);
if (newtags) {
sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
if (!newtags)
return;

sel->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
}

Expand All @@ -2422,11 +2427,12 @@ toggleview(const Arg *arg)
{
uint32_t newtagset = selmon ? selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK) : 0;

if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
}
if (!newtagset)
return;

selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1);
arrange(selmon);
printstatus();
}

Expand Down Expand Up @@ -2583,10 +2589,11 @@ 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)) {
c->isurgent = 1;
printstatus();
}
if (!c || c == focustop(selmon))
return;

c->isurgent = 1;
printstatus();
}

void
Expand Down Expand Up @@ -2745,10 +2752,11 @@ void
sethints(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_hints);
if (c != focustop(selmon)) {
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus();
}
if (c == focustop(selmon))
return;

c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus();
}

void
Expand Down

0 comments on commit 8d71123

Please sign in to comment.