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.
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)
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;
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);
}
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)
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;
}
return 0;
}
+ const char *signame;
switch (info.si_code) {
case CLD_EXITED:
wlr_log(info.si_status == 0 ? WLR_DEBUG : WLR_ERROR,
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,
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;