basic focus overhaul

This commit is contained in:
Tony Crisci 2018-02-04 13:39:10 -05:00
parent b28602aa74
commit 5151502298
12 changed files with 224 additions and 39 deletions

View file

@ -158,12 +158,13 @@ swayc_t *new_output(struct sway_output *sway_output) {
// struct instead of trying to do focus semantics like this
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &input_manager->seats, link) {
if (!seat->focus) {
seat->focus = ws;
if (!seat->has_focus) {
sway_seat_set_focus(seat, ws);
}
}
free(ws_name);
wl_signal_emit(&root_container.sway_root->events.new_container, output);
return output;
}
@ -185,6 +186,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
add_child(output, workspace);
sort_workspaces(output);
wl_signal_emit(&root_container.sway_root->events.new_container, workspace);
return workspace;
}
@ -207,9 +209,9 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
add_child(sibling, swayc);
} else {
// Regular case, create as sibling of current container
// TODO WLR
//add_sibling(sibling, swayc);
add_sibling(sibling, swayc);
}
wl_signal_emit(&root_container.sway_root->events.new_container, swayc);
return swayc;
}
@ -378,3 +380,26 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
f(container, data);
}
}
/**
* Get a list of containers that are descendents of the container in rendering
* order
*/
list_t *container_list_children(swayc_t *con) {
list_t *list = create_list();
list_t *queue = create_list();
list_add(queue, con);
swayc_t *current = NULL;
while (queue->length) {
current = queue->items[0];
list_del(queue, 0);
list_add(list, current);
// TODO floating containers
list_cat(queue, current->children);
}
list_free(queue);
return list;
}

View file

@ -48,10 +48,12 @@ void init_layout(void) {
root_container.layout = L_NONE;
root_container.name = strdup("root");
root_container.children = create_list();
wl_signal_init(&root_container.events.destroy);
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
root_container.sway_root->output_layout = wlr_output_layout_create();
wl_list_init(&root_container.sway_root->unmanaged_views);
wl_signal_init(&root_container.sway_root->events.new_container);
root_container.sway_root->output_layout_change.notify =
output_layout_change_notify;
@ -59,6 +61,34 @@ void init_layout(void) {
&root_container.sway_root->output_layout_change);
}
int index_child(const swayc_t *child) {
// TODO handle floating
swayc_t *parent = child->parent;
int i, len;
len = parent->children->length;
for (i = 0; i < len; ++i) {
if (parent->children->items[i] == child) {
break;
}
}
if (!sway_assert(i < len, "Stray container")) {
return -1;
}
return i;
}
swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) {
// TODO handle floating
swayc_t *parent = fixed->parent;
int i = index_child(fixed);
list_insert(parent->children, i + 1, active);
active->parent = parent;
// focus new child
parent->focused = active;
return active->parent;
}
void add_child(swayc_t *parent, swayc_t *child) {
wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
child, child->type, child->width, child->height,

View file

@ -63,9 +63,10 @@ static bool _workspace_by_name(swayc_t *view, void *data) {
swayc_t *workspace_by_name(const char *name) {
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *current_workspace = NULL, *current_output = NULL;
if (seat->focus) {
current_workspace = swayc_parent_by_type(seat->focus, C_WORKSPACE);
current_output = swayc_parent_by_type(seat->focus, C_OUTPUT);
if (seat->has_focus) {
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
current_workspace = swayc_parent_by_type(focus, C_WORKSPACE);
current_output = swayc_parent_by_type(focus, C_OUTPUT);
}
if (strcmp(name, "prev") == 0) {
return workspace_prev(current_workspace);
@ -102,7 +103,8 @@ swayc_t *workspace_create(const char *name) {
}
// Otherwise create a new one
struct sway_seat *seat = input_manager_current_seat(input_manager);
parent = seat->focus;
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
parent = focus;
parent = swayc_parent_by_type(parent, C_OUTPUT);
return new_workspace(parent, name);
}
@ -193,12 +195,13 @@ bool workspace_switch(swayc_t *workspace) {
return false;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
if (!seat || !seat->focus) {
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
if (!seat || !focus) {
return false;
}
swayc_t *active_ws = seat->focus;
swayc_t *active_ws = focus;
if (active_ws->type != C_WORKSPACE) {
swayc_parent_by_type(seat->focus, C_WORKSPACE);
swayc_parent_by_type(focus, C_WORKSPACE);
}
if (config->auto_back_and_forth