From a3d62267282da2cc067992258983d9e876eaf267 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Thu, 22 May 2025 10:53:58 -0400 Subject: [PATCH] treewide: remove empty statements in switch cases For longer cases, factor out the logic to new functions. For very short cases, just move the declaration before the switch. v2: in one case, replace the switch with if/else. --- src/action.c | 28 ++++++++++------- src/desktop.c | 3 +- src/edges.c | 63 ++++++++++++++++++++++---------------- src/server.c | 4 +-- src/ssd/resize-indicator.c | 11 ++----- 5 files changed, 59 insertions(+), 50 deletions(-) diff --git a/src/action.c b/src/action.c index d3241df9..3e2aaace 100644 --- a/src/action.c +++ b/src/action.c @@ -557,6 +557,22 @@ action_list_is_valid(struct wl_list *actions) return true; } +static bool +action_branches_are_valid(struct action *action) +{ + static const char * const branches[] = { "then", "else", "none" }; + for (size_t i = 0; i < ARRAY_SIZE(branches); i++) { + struct wl_list *children = + action_get_actionlist(action, branches[i]); + if (children && !action_list_is_valid(children)) { + wlr_log(WLR_ERROR, "Invalid action in %s '%s' branch", + action_names[action->type], branches[i]); + return false; + } + } + return true; +} + /* Checks for *required* arguments */ bool action_is_valid(struct action *action) @@ -589,17 +605,7 @@ action_is_valid(struct action *action) break; case ACTION_TYPE_IF: case ACTION_TYPE_FOR_EACH: - ; /* works around "a label can only be part of a statement" */ - static const char * const branches[] = { "then", "else", "none" }; - for (size_t i = 0; i < ARRAY_SIZE(branches); i++) { - struct wl_list *children = action_get_actionlist(action, branches[i]); - if (children && !action_list_is_valid(children)) { - wlr_log(WLR_ERROR, "Invalid action in %s '%s' branch", - action_names[action->type], branches[i]); - return false; - } - } - return true; + return action_branches_are_valid(action); default: /* No arguments required */ return true; diff --git a/src/desktop.c b/src/desktop.c index 226b0225..47ae1fb4 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -77,10 +77,9 @@ desktop_focus_view(struct view *view, bool raise) workspaces_switch_to(view->workspace, /*update_focus*/ false); } + struct seat *seat = &view->server->seat; switch (view_wants_focus(view)) { case VIEW_WANTS_FOCUS_ALWAYS: - ; /* works around "a label can only be part of a statement" */ - struct seat *seat = &view->server->seat; if (view->surface != seat->seat->keyboard_state.focused_surface) { seat_focus_surface(seat, view->surface); } diff --git a/src/edges.c b/src/edges.c index e0c6b295..6d64c511 100644 --- a/src/edges.c +++ b/src/edges.c @@ -242,6 +242,40 @@ validate_output_edges(struct border *valid_edges, view, target, output, validator, WLR_EDGE_BOTTOM); } +static uint32_t +compute_edges_visible(const struct wlr_box *view_size, + const pixman_box32_t *view_rect, + const pixman_region32_t *available) +{ + pixman_region32_t intersection; + pixman_region32_init(&intersection); + pixman_region32_intersect_rect(&intersection, available, + view_size->x, view_size->y, + view_size->width, view_size->height); + + int nrects; + const pixman_box32_t *rects = + pixman_region32_rectangles(&intersection, &nrects); + + uint32_t edges_visible = 0; + for (int i = 0; i < nrects; i++) { + if (rects[i].x1 == view_rect->x1) { + edges_visible |= WLR_EDGE_LEFT; + } + if (rects[i].y1 == view_rect->y1) { + edges_visible |= WLR_EDGE_TOP; + } + if (rects[i].x2 == view_rect->x2) { + edges_visible |= WLR_EDGE_RIGHT; + } + if (rects[i].y2 == view_rect->y2) { + edges_visible |= WLR_EDGE_BOTTOM; + } + } + pixman_region32_fini(&intersection); + return edges_visible; +} + /* Test if parts of the current view is covered by the remaining space in the region */ static void subtract_view_from_space(struct view *view, pixman_region32_t *available) @@ -266,33 +300,8 @@ subtract_view_from_space(struct view *view, pixman_region32_t *available) view->edges_visible = 0; return; case PIXMAN_REGION_PART: - ; /* works around "a label can only be part of a statement" */ - pixman_region32_t intersection; - pixman_region32_init(&intersection); - pixman_region32_intersect_rect(&intersection, available, - view_size.x, view_size.y, - view_size.width, view_size.height); - - int nrects; - const pixman_box32_t *rects = - pixman_region32_rectangles(&intersection, &nrects); - - view->edges_visible = 0; - for (int i = 0; i < nrects; i++) { - if (rects[i].x1 == view_rect.x1) { - view->edges_visible |= WLR_EDGE_LEFT; - } - if (rects[i].y1 == view_rect.y1) { - view->edges_visible |= WLR_EDGE_TOP; - } - if (rects[i].x2 == view_rect.x2) { - view->edges_visible |= WLR_EDGE_RIGHT; - } - if (rects[i].y2 == view_rect.y2) { - view->edges_visible |= WLR_EDGE_BOTTOM; - } - } - pixman_region32_fini(&intersection); + view->edges_visible = compute_edges_visible( + &view_size, &view_rect, available); break; } diff --git a/src/server.c b/src/server.c index 91fa5d07..572d2171 100644 --- a/src/server.c +++ b/src/server.c @@ -147,6 +147,7 @@ handle_sigchld(int signal, void *data) return 0; } + const char *signame; switch (info.si_code) { case CLD_EXITED: wlr_log(info.si_status == 0 ? WLR_DEBUG : WLR_ERROR, @@ -155,8 +156,7 @@ handle_sigchld(int signal, void *data) break; case CLD_KILLED: case CLD_DUMPED: - ; /* works around "a label can only be part of a statement" */ - const char *signame = strsignal(info.si_status); + signame = strsignal(info.si_status); wlr_log(WLR_ERROR, "spawned child %ld terminated with signal %d (%s)", (long)info.si_pid, info.si_status, diff --git a/src/ssd/resize-indicator.c b/src/ssd/resize-indicator.c index e478a578..c30900cf 100644 --- a/src/ssd/resize-indicator.c +++ b/src/ssd/resize-indicator.c @@ -168,24 +168,19 @@ resize_indicator_update(struct view *view) view_box.height = view_effective_height(view, /* use_pending */ false); } - switch (view->server->input_mode) { - case LAB_INPUT_STATE_RESIZE: - ; /* works around "a label can only be part of a statement" */ + if (view->server->input_mode == LAB_INPUT_STATE_RESIZE) { struct view_size_hints hints = view_get_size_hints(view); snprintf(text, sizeof(text), "%d x %d", MAX(0, view_box.width - hints.base_width) / MAX(1, hints.width_inc), MAX(0, view_box.height - hints.base_height) / MAX(1, hints.height_inc)); - break; - case LAB_INPUT_STATE_MOVE: - ; /* works around "a label can only be part of a statement" */ + } else if (view->server->input_mode == LAB_INPUT_STATE_MOVE) { struct border margin = ssd_get_margin(view->ssd); snprintf(text, sizeof(text), "%d , %d", view_box.x - margin.left, view_box.y - margin.top); - break; - default: + } else { wlr_log(WLR_ERROR, "Invalid input mode for indicator update %u", view->server->input_mode); return; -- 2.52.0