diff options
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 94 | ||||
-rw-r--r-- | sway/tree/layout.c | 124 | ||||
-rw-r--r-- | sway/tree/view.c | 10 |
3 files changed, 185 insertions, 43 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index f29a9adc..a4798c7e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -176,45 +176,6 @@ static void _container_destroy(struct sway_container *cont) { free(cont); } -static struct sway_container *container_output_destroy( - struct sway_container *output) { - if (!sway_assert(output, "cannot destroy null output")) { - return NULL; - } - - if (output->children->length > 0) { - // TODO save workspaces when there are no outputs. - // TODO also check if there will ever be no outputs except for exiting - // program - if (root_container.children->length > 1) { - int p = root_container.children->items[0] == output; - // Move workspace from this output to another output - while (output->children->length) { - struct sway_container *child = output->children->items[0]; - container_remove_child(child); - container_add_child(root_container.children->items[p], child); - } - container_sort_workspaces(root_container.children->items[p]); - arrange_output(root_container.children->items[p]); - } - } - - wl_list_remove(&output->sway_output->destroy.link); - wl_list_remove(&output->sway_output->mode.link); - wl_list_remove(&output->sway_output->transform.link); - wl_list_remove(&output->sway_output->scale.link); - - wl_list_remove(&output->sway_output->damage_destroy.link); - wl_list_remove(&output->sway_output->damage_frame.link); - - // clear the wlr_output reference to this container - output->sway_output->wlr_output->data = NULL; - - wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); - _container_destroy(output); - return &root_container; -} - static struct sway_container *container_workspace_destroy( struct sway_container *workspace) { if (!sway_assert(workspace, "cannot destroy null workspace")) { @@ -232,7 +193,7 @@ static struct sway_container *container_workspace_destroy( // destroy the WS if there are no children (TODO check for floating) wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); ipc_event_workspace(workspace, NULL, "empty"); - } else { + } else if (output) { // Move children to a different workspace on this output struct sway_container *new_workspace = NULL; // TODO move floating @@ -253,11 +214,62 @@ static struct sway_container *container_workspace_destroy( free(workspace->sway_workspace); _container_destroy(workspace); - output_damage_whole(output->sway_output); + if (output) { + output_damage_whole(output->sway_output); + } return parent; } +static struct sway_container *container_output_destroy( + struct sway_container *output) { + if (!sway_assert(output, "cannot destroy null output")) { + return NULL; + } + + if (output->children->length > 0) { + // TODO save workspaces when there are no outputs. + // TODO also check if there will ever be no outputs except for exiting + // program + if (root_container.children->length > 1) { + // Move workspace from this output to another output + struct sway_container *other_output = + root_container.children->items[0]; + if (other_output == output) { + other_output = root_container.children->items[1]; + } + + while (output->children->length) { + struct sway_container *workspace = output->children->items[0]; + container_remove_child(workspace); + if (workspace->children->length > 0) { + container_add_child(other_output, workspace); + ipc_event_workspace(workspace, NULL, "move"); + } else { + container_workspace_destroy(workspace); + } + } + container_sort_workspaces(other_output); + arrange_output(other_output); + } + } + + wl_list_remove(&output->sway_output->destroy.link); + wl_list_remove(&output->sway_output->mode.link); + wl_list_remove(&output->sway_output->transform.link); + wl_list_remove(&output->sway_output->scale.link); + + wl_list_remove(&output->sway_output->damage_destroy.link); + wl_list_remove(&output->sway_output->damage_frame.link); + + // clear the wlr_output reference to this container + output->sway_output->wlr_output->data = NULL; + + wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); + _container_destroy(output); + return &root_container; +} + static void container_root_finish(struct sway_container *con) { wlr_log(L_ERROR, "TODO: destroy the root container"); } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 21cec529..624d5516 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -882,3 +882,127 @@ void container_recursive_resize(struct sway_container *container, } } } + +static void swap_places(struct sway_container *con1, + struct sway_container *con2) { + struct sway_container *temp = malloc(sizeof(struct sway_container)); + temp->x = con1->x; + temp->y = con1->y; + temp->width = con1->width; + temp->height = con1->height; + temp->parent = con1->parent; + + con1->x = con2->x; + con1->y = con2->y; + con1->width = con2->width; + con1->height = con2->height; + + con2->x = temp->x; + con2->y = temp->y; + con2->width = temp->width; + con2->height = temp->height; + + int temp_index = index_child(con1); + container_insert_child(con2->parent, con1, index_child(con2)); + container_insert_child(temp->parent, con2, temp_index); + + free(temp); +} + +static void swap_focus(struct sway_container *con1, + struct sway_container *con2, struct sway_seat *seat, + struct sway_container *focus) { + if (focus == con1 || focus == con2) { + struct sway_container *ws1 = container_parent(con1, C_WORKSPACE); + struct sway_container *ws2 = container_parent(con2, C_WORKSPACE); + if (focus == con1 && (con2->parent->layout == L_TABBED + || con2->parent->layout == L_STACKED)) { + if (workspace_is_visible(ws2)) { + seat_set_focus_warp(seat, con2, false); + } + seat_set_focus(seat, ws1 != ws2 ? con2 : con1); + } else if (focus == con2 && (con1->parent->layout == L_TABBED + || con1->parent->layout == L_STACKED)) { + if (workspace_is_visible(ws1)) { + seat_set_focus_warp(seat, con1, false); + } + seat_set_focus(seat, ws1 != ws2 ? con1 : con2); + } else if (ws1 != ws2) { + seat_set_focus(seat, focus == con1 ? con2 : con1); + } else { + seat_set_focus(seat, focus); + } + } else { + seat_set_focus(seat, focus); + } +} + +void container_swap(struct sway_container *con1, struct sway_container *con2) { + if (!sway_assert(con1 && con2, "Cannot swap with nothing")) { + return; + } + if (!sway_assert(con1->type >= C_CONTAINER && con2->type >= C_CONTAINER, + "Can only swap containers and views")) { + return; + } + if (!sway_assert(!container_has_anscestor(con1, con2) + && !container_has_anscestor(con2, con1), + "Cannot swap anscestor and descendant")) { + return; + } + if (!sway_assert(con1->layout != L_FLOATING && con2->layout != L_FLOATING, + "Swapping with floating containers is not supported")) { + return; + } + + wlr_log(L_DEBUG, "Swapping containers %zu and %zu", con1->id, con2->id); + + int fs1 = con1->type == C_VIEW && con1->sway_view->is_fullscreen; + int fs2 = con2->type == C_VIEW && con2->sway_view->is_fullscreen; + if (fs1) { + view_set_fullscreen(con1->sway_view, false); + } + if (fs2) { + view_set_fullscreen(con2->sway_view, false); + } + + struct sway_seat *seat = input_manager_get_default_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + struct sway_container *vis1 = container_parent( + seat_get_focus_inactive(seat, container_parent(con1, C_OUTPUT)), + C_WORKSPACE); + struct sway_container *vis2 = container_parent( + seat_get_focus_inactive(seat, container_parent(con2, C_OUTPUT)), + C_WORKSPACE); + + char *stored_prev_name = NULL; + if (prev_workspace_name) { + stored_prev_name = strdup(prev_workspace_name); + } + + swap_places(con1, con2); + + if (!workspace_is_visible(vis1)) { + seat_set_focus(seat, seat_get_focus_inactive(seat, vis1)); + } + if (!workspace_is_visible(vis2)) { + seat_set_focus(seat, seat_get_focus_inactive(seat, vis2)); + } + + swap_focus(con1, con2, seat, focus); + + if (stored_prev_name) { + free(prev_workspace_name); + prev_workspace_name = stored_prev_name; + } + + arrange_children_of(con1->parent); + arrange_children_of(con2->parent); + + if (fs1 && con2->type == C_VIEW) { + view_set_fullscreen(con2->sway_view, true); + } + if (fs2 && con1->type == C_VIEW) { + view_set_fullscreen(con1->sway_view, true); + } +} diff --git a/sway/tree/view.c b/sway/tree/view.c index 812d7740..d91182ed 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -107,7 +107,7 @@ uint32_t view_get_window_type(struct sway_view *view) { return 0; } -const char *view_get_type(struct sway_view *view) { +const char *view_get_shell(struct sway_view *view) { switch(view->type) { case SWAY_VIEW_XDG_SHELL_V6: return "xdg_shell_v6"; @@ -654,10 +654,12 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) { return title ? strlen(title) : 0; } const char *title = view_get_title(view); + const char *app_id = view_get_app_id(view); const char *class = view_get_class(view); const char *instance = view_get_instance(view); - const char *shell = view_get_type(view); + const char *shell = view_get_shell(view); size_t title_len = title ? strlen(title) : 0; + size_t app_id_len = app_id ? strlen(app_id) : 0; size_t class_len = class ? strlen(class) : 0; size_t instance_len = instance ? strlen(instance) : 0; size_t shell_len = shell ? strlen(shell) : 0; @@ -675,6 +677,10 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) { lenient_strcat(buffer, title); len += title_len; format += 6; + } else if (strncmp(next, "%app_id", 7) == 0) { + lenient_strcat(buffer, app_id); + len += app_id_len; + format += 7; } else if (strncmp(next, "%class", 6) == 0) { lenient_strcat(buffer, class); len += class_len; |