diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index d092af491..ad7d66428 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -18,16 +18,15 @@ struct sway_seat; * it on this list. */ enum sway_container_type { - C_ROOT, - C_OUTPUT, - C_WORKSPACE, - C_CONTAINER, - C_VIEW, - - // Keep last - C_TYPES, + C_ROOT = 1 << 0, + C_OUTPUT = 1 << 1, + C_WORKSPACE = 1 << 2, + C_CONTAINER = 1 << 3, + C_VIEW = 1 << 4, }; +#define C_ALL (C_ROOT | C_OUTPUT | C_WORKSPACE | C_CONTAINER | C_VIEW) + enum sway_container_layout { L_NONE, L_HORIZ, diff --git a/sway/input/seat.c b/sway/input/seat.c index 8b9817da7..3647c03bf 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -90,14 +90,14 @@ static void seat_send_focus(struct sway_seat *seat, } static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, - struct sway_container *container, enum sway_container_type type) { + struct sway_container *container, unsigned int types) { if (container->type == C_VIEW || container->children->length == 0) { return container; } struct sway_seat_container *current = NULL; wl_list_for_each(current, &seat->focus_stack, link) { - if (current->container->type != type && type != C_TYPES) { + if ((current->container->type & types) == 0) { continue; } @@ -128,6 +128,11 @@ struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, return seat_get_focus_by_type(seat, container, C_VIEW); } +struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, + struct sway_container *container) { + return seat_get_focus_by_type(seat, container, C_ALL); +} + static void handle_seat_container_destroy(struct wl_listener *listener, void *data) { struct sway_seat_container *seat_con = @@ -147,7 +152,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, if (set_focus) { struct sway_container *next_focus = NULL; while (next_focus == NULL) { - next_focus = seat_get_focus_by_type(seat, parent, C_VIEW); + next_focus = seat_get_focus_inactive_view(seat, parent); if (next_focus == NULL && parent->type == C_WORKSPACE) { next_focus = parent; @@ -667,11 +672,6 @@ void seat_set_exclusive_client(struct sway_seat *seat, seat->exclusive_client = client; } -struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, - struct sway_container *container) { - return seat_get_focus_by_type(seat, container, C_TYPES); -} - struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { if (!seat->has_focus) { return NULL; diff --git a/sway/ipc-json.c b/sway/ipc-json.c index ea7fd9ad9..e958728a2 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -207,9 +207,6 @@ json_object *ipc_json_describe_container(struct sway_container *c) { case C_WORKSPACE: ipc_json_describe_workspace(c, object); break; - case C_TYPES: - default: - break; } return object; diff --git a/sway/tree/container.c b/sway/tree/container.c index 6ac595473..9c289b8b0 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -46,8 +46,6 @@ const char *container_type_to_str(enum sway_container_type type) { return "C_CONTAINER"; case C_VIEW: return "C_VIEW"; - default: - return "C_UNKNOWN"; } } @@ -231,10 +229,6 @@ bool container_reap_empty(struct sway_container *con) { } case C_VIEW: break; - case C_TYPES: - sway_assert(false, "container_reap_empty called on an invalid " - "container"); - break; } return false; @@ -295,10 +289,6 @@ struct sway_container *container_destroy(struct sway_container *con) { case C_VIEW: _container_destroy(con); break; - case C_TYPES: - wlr_log(L_ERROR, "container_destroy called on an invalid " - "container"); - break; } return container_reap_empty_recursive(parent); @@ -394,9 +384,6 @@ struct sway_container *container_parent(struct sway_container *container, if (!sway_assert(container, "container is NULL")) { return NULL; } - if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) { - return NULL; - } do { container = container->parent; } while (container && container->type != type); diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ec1c6fe5b..fe273fd5c 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -410,9 +410,8 @@ void container_move(struct sway_container *container, current = current->parent; } break; - default: - sway_assert(0, "Not expecting to see container of type %s here", - container_type_to_str(current->type)); + case C_ROOT: + sway_assert(false, "Not expecting to see a root container here"); return; } } @@ -478,8 +477,9 @@ void container_move(struct sway_container *container, sibling = NULL; } break; - default: - sway_assert(0, "Not expecting to see container of type %s here", + case C_OUTPUT: + case C_ROOT: + sway_assert(false, "Not expecting to see container of type %s here", container_type_to_str(sibling->type)); return; }