]> git.mdlowis.com Git - proto/labwc.git/commitdiff
treewide: remove empty statements in switch cases
authorJohn Lindgren <john@jlindgren.net>
Thu, 22 May 2025 14:53:58 +0000 (10:53 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 22 May 2025 21:52:43 +0000 (22:52 +0100)
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
src/desktop.c
src/edges.c
src/server.c
src/ssd/resize-indicator.c

index d3241df9627d992515d18292e36035a950424c6f..3e2aaaceb88adb4c918ee15fc941cffb0867d3a1 100644 (file)
@@ -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;
index 226b0225f9e2751aff1cc61a35ce94a9704a7d40..47ae1fb410e398f3337e16632fae0e3750bb4232 100644 (file)
@@ -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);
                }
index e0c6b295a4589ba6876d343b6ad1a8b5f1073e77..6d64c5112c8feb9642e204af422245ccbf68d718 100644 (file)
@@ -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;
        }
 
index 91fa5d0768fbbef6f685841cfe640592a3361c95..572d21719c2c504d367eaaaa3cbb128458e1b0f1 100644 (file)
@@ -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,
index e478a57888597119e57176ceb0c1c79f81cd1269..c30900cfd8c88a672b9cf5e7fa2b6270f4b0d4b7 100644 (file)
@@ -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;