This commit is contained in:
emersion 2018-05-02 14:16:15 +00:00 committed by GitHub
commit 918d3fc33f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 37 deletions

View file

@ -18,16 +18,15 @@ struct sway_seat;
* it on this list. * it on this list.
*/ */
enum sway_container_type { enum sway_container_type {
C_ROOT, C_ROOT = 1 << 0,
C_OUTPUT, C_OUTPUT = 1 << 1,
C_WORKSPACE, C_WORKSPACE = 1 << 2,
C_CONTAINER, C_CONTAINER = 1 << 3,
C_VIEW, C_VIEW = 1 << 4,
// Keep last
C_TYPES,
}; };
#define C_ALL (C_ROOT | C_OUTPUT | C_WORKSPACE | C_CONTAINER | C_VIEW)
enum sway_container_layout { enum sway_container_layout {
L_NONE, L_NONE,
L_HORIZ, L_HORIZ,

View file

@ -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, 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) { if (container->type == C_VIEW || container->children->length == 0) {
return container; return container;
} }
struct sway_seat_container *current = NULL; struct sway_seat_container *current = NULL;
wl_list_for_each(current, &seat->focus_stack, link) { wl_list_for_each(current, &seat->focus_stack, link) {
if (current->container->type != type && type != C_TYPES) { if ((current->container->type & types) == 0) {
continue; 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); 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, static void handle_seat_container_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct sway_seat_container *seat_con = struct sway_seat_container *seat_con =
@ -147,7 +152,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
if (set_focus) { if (set_focus) {
struct sway_container *next_focus = NULL; struct sway_container *next_focus = NULL;
while (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) { if (next_focus == NULL && parent->type == C_WORKSPACE) {
next_focus = parent; next_focus = parent;
@ -667,11 +672,6 @@ void seat_set_exclusive_client(struct sway_seat *seat,
seat->exclusive_client = client; 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) { struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
if (!seat->has_focus) { if (!seat->has_focus) {
return NULL; return NULL;

View file

@ -207,9 +207,6 @@ json_object *ipc_json_describe_container(struct sway_container *c) {
case C_WORKSPACE: case C_WORKSPACE:
ipc_json_describe_workspace(c, object); ipc_json_describe_workspace(c, object);
break; break;
case C_TYPES:
default:
break;
} }
return object; return object;

View file

@ -46,8 +46,6 @@ const char *container_type_to_str(enum sway_container_type type) {
return "C_CONTAINER"; return "C_CONTAINER";
case C_VIEW: case C_VIEW:
return "C_VIEW"; return "C_VIEW";
default:
return "C_UNKNOWN";
} }
} }
@ -231,10 +229,6 @@ bool container_reap_empty(struct sway_container *con) {
} }
case C_VIEW: case C_VIEW:
break; break;
case C_TYPES:
sway_assert(false, "container_reap_empty called on an invalid "
"container");
break;
} }
return false; return false;
@ -295,10 +289,6 @@ struct sway_container *container_destroy(struct sway_container *con) {
case C_VIEW: case C_VIEW:
_container_destroy(con); _container_destroy(con);
break; break;
case C_TYPES:
wlr_log(L_ERROR, "container_destroy called on an invalid "
"container");
break;
} }
return container_reap_empty_recursive(parent); 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")) { if (!sway_assert(container, "container is NULL")) {
return NULL; return NULL;
} }
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
return NULL;
}
do { do {
container = container->parent; container = container->parent;
} while (container && container->type != type); } while (container && container->type != type);

View file

@ -410,9 +410,8 @@ void container_move(struct sway_container *container,
current = current->parent; current = current->parent;
} }
break; break;
default: case C_ROOT:
sway_assert(0, "Not expecting to see container of type %s here", sway_assert(false, "Not expecting to see a root container here");
container_type_to_str(current->type));
return; return;
} }
} }
@ -478,8 +477,9 @@ void container_move(struct sway_container *container,
sibling = NULL; sibling = NULL;
} }
break; break;
default: case C_OUTPUT:
sway_assert(0, "Not expecting to see container of type %s here", case C_ROOT:
sway_assert(false, "Not expecting to see container of type %s here",
container_type_to_str(sibling->type)); container_type_to_str(sibling->type));
return; return;
} }