diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-06-01 15:41:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 15:41:49 -0700 |
commit | 96446fdbf748acfdbd4c60fbc0d12e45a27199fe (patch) | |
tree | 6d46cc61a1e7c74efe36565796ccbf8b47e7e4a7 /sway/tree | |
parent | fd885d5779ef9aa408fa856a66fa7343ce01fa19 (diff) | |
parent | 70c2c504452eccbe5a74bc014e99b5b03db14124 (diff) | |
download | sway-96446fdbf748acfdbd4c60fbc0d12e45a27199fe.tar.xz |
Merge pull request #2027 from RyanDwyer/implement-floating
Implement floating
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/arrange.c | 16 | ||||
-rw-r--r-- | sway/tree/container.c | 169 | ||||
-rw-r--r-- | sway/tree/layout.c | 54 | ||||
-rw-r--r-- | sway/tree/view.c | 126 | ||||
-rw-r--r-- | sway/tree/workspace.c | 48 |
5 files changed, 299 insertions, 114 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index bdef56ea..721b557e 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -73,8 +73,8 @@ void arrange_workspace(struct sway_container *workspace) { area->width, area->height, area->x, area->y); workspace->width = area->width; workspace->height = area->height; - workspace->x = area->x; - workspace->y = area->y; + workspace->x = output->x + area->x; + workspace->y = output->y + area->y; wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, workspace->x, workspace->y); arrange_children_of(workspace); @@ -247,6 +247,18 @@ void arrange_children_of(struct sway_container *parent) { arrange_children_of(child); } } + + // If container is a workspace, process floating containers too + if (parent->type == C_WORKSPACE) { + struct sway_workspace *ws = workspace->sway_workspace; + for (int i = 0; i < ws->floating->children->length; ++i) { + struct sway_container *child = ws->floating->children->items[i]; + if (child->type != C_VIEW) { + arrange_children_of(child); + } + } + } + container_damage_whole(parent); update_debug_tree(); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 33d88d7f..9e70da09 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -64,16 +64,6 @@ void container_create_notify(struct sway_container *container) { } } -static void container_close_notify(struct sway_container *container) { - if (container == NULL) { - return; - } - // TODO send ipc event type based on the container type - if (container->type == C_VIEW || container->type == C_WORKSPACE) { - ipc_event_window(container, "close"); - } -} - static void container_update_textures_recursive(struct sway_container *con) { container_update_title_textures(con); @@ -143,7 +133,6 @@ static void _container_destroy(struct sway_container *cont) { } wl_signal_emit(&cont->events.destroy, cont); - container_close_notify(cont); struct sway_container *parent = cont->parent; if (cont->children != NULL && cont->children->length) { @@ -151,6 +140,7 @@ static void _container_destroy(struct sway_container *cont) { // container_remove_child, which removes child from this container while (cont->children != NULL && cont->children->length > 0) { struct sway_container *child = cont->children->items[0]; + ipc_event_window(child, "close"); container_remove_child(child); _container_destroy(child); } @@ -188,15 +178,13 @@ static struct sway_container *container_workspace_destroy( return NULL; } + wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); + ipc_event_window(workspace, "close"); + struct sway_container *parent = workspace->parent; - if (workspace->children->length == 0) { - // 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 if (output) { + if (!workspace_is_empty(workspace) && output) { // Move children to a different workspace on this output struct sway_container *new_workspace = NULL; - // TODO move floating for (int i = 0; i < output->children->length; i++) { if (output->children->items[i] != workspace) { new_workspace = output->children->items[i]; @@ -209,6 +197,11 @@ static struct sway_container *container_workspace_destroy( for (int i = 0; i < workspace->children->length; i++) { container_move_to(workspace->children->items[i], new_workspace); } + struct sway_container *floating = workspace->sway_workspace->floating; + for (int i = 0; i < floating->children->length; i++) { + container_move_to(floating->children->items[i], + new_workspace->sway_workspace->floating); + } } free(workspace->sway_workspace); @@ -275,13 +268,17 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { + if (con->layout == L_FLOATING) { + // Don't reap the magical floating container that each workspace has + return false; + } switch (con->type) { case C_ROOT: case C_OUTPUT: // dont reap these break; case C_WORKSPACE: - if (!workspace_is_visible(con) && con->children->length == 0) { + if (!workspace_is_visible(con) && workspace_is_empty(con)) { wlr_log(L_DEBUG, "Destroying workspace via reaper"); container_workspace_destroy(con); return true; @@ -349,10 +346,12 @@ struct sway_container *container_destroy(struct sway_container *con) { if (con->children->length) { for (int i = 0; i < con->children->length; ++i) { struct sway_container *child = con->children->items[0]; + ipc_event_window(child, "close"); container_remove_child(child); container_add_child(parent, child); } } + ipc_event_window(con, "close"); _container_destroy(con); break; case C_VIEW: @@ -436,7 +435,6 @@ struct sway_container *container_find(struct sway_container *container, if (!container->children) { return NULL; } - // TODO: floating windows for (int i = 0; i < container->children->length; ++i) { struct sway_container *child = container->children->items[i]; if (test(child, data)) { @@ -448,6 +446,9 @@ struct sway_container *container_find(struct sway_container *container, } } } + if (container->type == C_WORKSPACE) { + return container_find(container->sway_workspace->floating, test, data); + } return NULL; } @@ -466,14 +467,14 @@ struct sway_container *container_parent(struct sway_container *container, } static struct sway_container *container_at_view(struct sway_container *swayc, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) { return NULL; } struct sway_view *sview = swayc->sway_view; - double view_sx = ox - sview->x; - double view_sy = oy - sview->y; + double view_sx = lx - sview->x; + double view_sy = ly - sview->y; double _sx, _sy; struct wlr_surface *_surface = NULL; @@ -515,18 +516,18 @@ static struct sway_container *container_at_view(struct sway_container *swayc, * container_at for a container with layout L_TABBED. */ static struct sway_container *container_at_tabbed(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - if (oy < parent->y || oy > parent->y + parent->height) { + if (ly < parent->y || ly > parent->y + parent->height) { return NULL; } struct sway_seat *seat = input_manager_current_seat(input_manager); // Tab titles int title_height = container_titlebar_height(); - if (oy < parent->y + title_height) { + if (ly < parent->y + title_height) { int tab_width = parent->width / parent->children->length; - int child_index = (ox - parent->x) / tab_width; + int child_index = (lx - parent->x) / tab_width; if (child_index >= parent->children->length) { child_index = parent->children->length - 1; } @@ -537,23 +538,23 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent, // Surfaces struct sway_container *current = seat_get_active_child(seat, parent); - return container_at(current, ox, oy, surface, sx, sy); + return container_at(current, lx, ly, surface, sx, sy); } /** * container_at for a container with layout L_STACKED. */ static struct sway_container *container_at_stacked( - struct sway_container *parent, double ox, double oy, + struct sway_container *parent, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - if (oy < parent->y || oy > parent->y + parent->height) { + if (ly < parent->y || ly > parent->y + parent->height) { return NULL; } struct sway_seat *seat = input_manager_current_seat(input_manager); // Title bars int title_height = container_titlebar_height(); - int child_index = (oy - parent->y) / title_height; + int child_index = (ly - parent->y) / title_height; if (child_index < parent->children->length) { struct sway_container *child = parent->children->items[child_index]; return seat_get_focus_inactive(seat, child); @@ -562,14 +563,14 @@ static struct sway_container *container_at_stacked( // Surfaces struct sway_container *current = seat_get_active_child(seat, parent); - return container_at(current, ox, oy, surface, sx, sy); + return container_at(current, lx, ly, surface, sx, sy); } /** * container_at for a container with layout L_HORIZ or L_VERT. */ static struct sway_container *container_at_linear(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { for (int i = 0; i < parent->children->length; ++i) { struct sway_container *child = parent->children->items[i]; @@ -579,22 +580,22 @@ static struct sway_container *container_at_linear(struct sway_container *parent, .width = child->width, .height = child->height, }; - if (wlr_box_contains_point(&box, ox, oy)) { - return container_at(child, ox, oy, surface, sx, sy); + if (wlr_box_contains_point(&box, lx, ly)) { + return container_at(child, lx, ly, surface, sx, sy); } } return NULL; } struct sway_container *container_at(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (!sway_assert(parent->type >= C_WORKSPACE, "Expected workspace or deeper")) { return NULL; } if (parent->type == C_VIEW) { - return container_at_view(parent, ox, oy, surface, sx, sy); + return container_at_view(parent, lx, ly, surface, sx, sy); } if (!parent->children->length) { return NULL; @@ -603,13 +604,14 @@ struct sway_container *container_at(struct sway_container *parent, switch (parent->layout) { case L_HORIZ: case L_VERT: - return container_at_linear(parent, ox, oy, surface, sx, sy); + return container_at_linear(parent, lx, ly, surface, sx, sy); case L_TABBED: - return container_at_tabbed(parent, ox, oy, surface, sx, sy); + return container_at_tabbed(parent, lx, ly, surface, sx, sy); case L_STACKED: - return container_at_stacked(parent, ox, oy, surface, sx, sy); + return container_at_stacked(parent, lx, ly, surface, sx, sy); case L_FLOATING: - return NULL; // TODO + sway_assert(false, "Didn't expect to see floating here"); + return NULL; case L_NONE: return NULL; } @@ -617,6 +619,34 @@ struct sway_container *container_at(struct sway_container *parent, return NULL; } +struct sway_container *floating_container_at(double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *output = root_container.children->items[i]; + for (int j = 0; j < output->children->length; ++j) { + struct sway_container *workspace = output->children->items[j]; + struct sway_workspace *ws = workspace->sway_workspace; + if (!workspace_is_visible(workspace)) { + continue; + } + for (int k = 0; k < ws->floating->children->length; ++k) { + struct sway_container *floater = + ws->floating->children->items[k]; + struct wlr_box box = { + .x = floater->x, + .y = floater->y, + .width = floater->width, + .height = floater->height, + }; + if (wlr_box_contains_point(&box, lx, ly)) { + return container_at(floater, lx, ly, surface, sx, sy); + } + } + } + } + return NULL; +} + void container_for_each_descendant_dfs(struct sway_container *container, void (*f)(struct sway_container *container, void *data), void *data) { @@ -674,7 +704,7 @@ static bool find_child_func(struct sway_container *con, void *data) { bool container_has_child(struct sway_container *con, struct sway_container *child) { - if (con == NULL || con->type == C_VIEW || con->children->length == 0) { + if (con == NULL || con->type == C_VIEW) { return false; } return container_find(con, find_child_func, child); @@ -866,3 +896,60 @@ void container_notify_subtree_changed(struct sway_container *container) { size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } + +void container_set_floating(struct sway_container *container, bool enable) { + if (container_is_floating(container) == enable) { + return; + } + + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + struct sway_seat *seat = input_manager_current_seat(input_manager); + container_damage_whole(container); + + if (enable) { + container_remove_child(container); + container_add_child(workspace->sway_workspace->floating, container); + if (container->type == C_VIEW) { + view_autoconfigure(container->sway_view); + } + seat_set_focus(seat, seat_get_focus_inactive(seat, container)); + container_reap_empty_recursive(workspace); + } else { + // Returning to tiled + container_remove_child(container); + container_add_child(workspace, container); + container->width = container->parent->width; + container->height = container->parent->height; + container->is_sticky = false; + container_reap_empty_recursive(workspace->sway_workspace->floating); + } + arrange_workspace(workspace); + container_damage_whole(container); +} + +void container_set_geometry_from_floating_view(struct sway_container *con) { + if (!sway_assert(con->type == C_VIEW, "Expected a view")) { + return; + } + if (!sway_assert(container_is_floating(con), + "Expected a floating view")) { + return; + } + struct sway_view *view = con->sway_view; + size_t border_width = view->border_thickness * (view->border != B_NONE); + size_t top = + view->border == B_NORMAL ? container_titlebar_height() : border_width; + + con->x = view->x - border_width; + con->y = view->y - top; + con->width = view->width + border_width * 2; + con->height = top + view->height + border_width; +} + +bool container_is_floating(struct sway_container *container) { + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + if (!workspace) { + return false; + } + return container->parent == workspace->sway_workspace->floating; +} diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 2f4ae667..d88948dc 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -45,20 +45,14 @@ void layout_init(void) { } static int index_child(const struct sway_container *child) { - // TODO handle floating struct sway_container *parent = child->parent; - int i, len; - len = parent->children->length; - for (i = 0; i < len; ++i) { + for (int i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { - break; + return i; } } - - if (!sway_assert(i < len, "Stray container")) { - return -1; - } - return i; + // This happens if the child is a floating container + return -1; } static void container_handle_fullscreen_reparent(struct sway_container *viewcon, @@ -160,6 +154,10 @@ void container_move_to(struct sway_container *container, || container_has_ancestor(container, destination)) { return; } + if (container_is_floating(container)) { + // TODO + return; + } struct sway_container *old_parent = container_remove_child(container); container->width = container->height = 0; container->saved_width = container->saved_height = 0; @@ -172,8 +170,9 @@ void container_move_to(struct sway_container *container, } wl_signal_emit(&container->events.reparent, old_parent); if (container->type == C_WORKSPACE) { - struct sway_seat *seat = input_manager_get_default_seat( - input_manager); + // If moving a workspace to a new output, maybe create a new workspace + // on the previous output + struct sway_seat *seat = input_manager_get_default_seat(input_manager); if (old_parent->children->length == 0) { char *ws_name = workspace_next_name(old_parent->name); struct sway_container *ws = @@ -681,26 +680,6 @@ static struct sway_container *get_swayc_in_output_direction( return ws; } -static void get_layout_center_position(struct sway_container *container, - int *x, int *y) { - // FIXME view coords are inconsistently referred to in layout/output systems - if (container->type == C_OUTPUT) { - *x = container->x + container->width/2; - *y = container->y + container->height/2; - } else { - struct sway_container *output = container_parent(container, C_OUTPUT); - if (container->type == C_WORKSPACE) { - // Workspace coordinates are actually wrong/arbitrary, but should - // be same as output. - *x = output->x; - *y = output->y; - } else { - *x = output->x + container->x; - *y = output->y + container->y; - } - } -} - static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { if (output == NULL) { return NULL; @@ -719,6 +698,10 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; + if (container_is_floating(container)) { + return NULL; + } + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { if (dir == MOVE_PARENT || dir == MOVE_CHILD) { return NULL; @@ -743,14 +726,17 @@ struct sway_container *container_get_in_direction( bool can_move = false; int desired; int idx = index_child(container); + if (idx == -1) { + return NULL; + } if (parent->type == C_ROOT) { enum wlr_direction wlr_dir = 0; if (!sway_assert(sway_dir_to_wlr(dir, &wlr_dir), "got invalid direction: %d", dir)) { return NULL; } - int lx, ly; - get_layout_center_position(container, &lx, &ly); + int lx = container->x + container->width / 2; + int ly = container->y + container->height / 2; struct wlr_output_layout *layout = root_container.sway_root->output_layout; struct wlr_output *wlr_adjacent = diff --git a/sway/tree/view.c b/sway/tree/view.c index 26ff1e8d..3117ded6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -119,13 +119,28 @@ const char *view_get_shell(struct sway_view *view) { return "unknown"; } -void view_configure(struct sway_view *view, double ox, double oy, int width, +void view_configure(struct sway_view *view, double lx, double ly, int width, int height) { if (view->impl->configure) { - view->impl->configure(view, ox, oy, width, height); + view->impl->configure(view, lx, ly, width, height); } } +static void view_autoconfigure_floating(struct sway_view *view) { + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + int max_width = ws->width * 0.6666; + int max_height = ws->height * 0.6666; + int width = + view->natural_width > max_width ? max_width : view->natural_width; + int height = + view->natural_height > max_height ? max_height : view->natural_height; + int lx = ws->x + (ws->width - width) / 2; + int ly = ws->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_configure(view, lx, ly, width, height); +} + void view_autoconfigure(struct sway_view *view) { if (!sway_assert(view->swayc, "Called view_autoconfigure() on a view without a swayc")) { @@ -135,8 +150,12 @@ void view_autoconfigure(struct sway_view *view) { struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (view->is_fullscreen) { - view_configure(view, 0, 0, output->width, output->height); - view->x = view->y = 0; + view_configure(view, output->x, output->y, output->width, output->height); + return; + } + + if (container_is_floating(view->swayc)) { + view_autoconfigure_floating(view); return; } @@ -158,21 +177,19 @@ void view_autoconfigure(struct sway_view *view) { view->border_top = view->border_bottom = true; view->border_left = view->border_right = true; - if (view->swayc->layout != L_FLOATING) { - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_VERTICAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_left = view->swayc->x != ws->x; - int right_x = view->swayc->x + view->swayc->width; - view->border_right = right_x != ws->x + ws->width; - } - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_HORIZONTAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_top = view->swayc->y != ws->y; - int bottom_y = view->swayc->y + view->swayc->height; - view->border_bottom = bottom_y != ws->y + ws->height; - } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_VERTICAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_left = view->swayc->x != ws->x; + int right_x = view->swayc->x + view->swayc->width; + view->border_right = right_x != ws->x + ws->width; + } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_HORIZONTAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_top = view->swayc->y != ws->y; + int bottom_y = view->swayc->y + view->swayc->height; + view->border_bottom = bottom_y != ws->y + ws->height; } double x, y, width, height; @@ -184,11 +201,11 @@ void view_autoconfigure(struct sway_view *view) { // disable any top border because we'll always have the title bar. if (view->swayc->parent->layout == L_TABBED) { y_offset = container_titlebar_height(); - view->border_top = 0; + view->border_top = false; } else if (view->swayc->parent->layout == L_STACKED) { y_offset = container_titlebar_height() * view->swayc->parent->children->length; - view->border_top = 0; + view->border_top = false; } switch (view->border) { @@ -257,6 +274,12 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { view_set_fullscreen(workspace->sway_workspace->fullscreen, false); } workspace->sway_workspace->fullscreen = view; + view->saved_x = view->x; + view->saved_y = view->y; + view->saved_width = view->width; + view->saved_height = view->height; + view->swayc->saved_x = view->swayc->x; + view->swayc->saved_y = view->swayc->y; view->swayc->saved_width = view->swayc->width; view->swayc->saved_height = view->swayc->height; @@ -277,8 +300,14 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { } } else { workspace->sway_workspace->fullscreen = NULL; - view->swayc->width = view->swayc->saved_width; - view->swayc->height = view->swayc->saved_height; + if (container_is_floating(view->swayc)) { + view_configure(view, view->saved_x, view->saved_y, + view->saved_width, view->saved_height); + } else { + view->swayc->width = view->swayc->saved_width; + view->swayc->height = view->swayc->saved_height; + view_autoconfigure(view); + } } } @@ -452,6 +481,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { // TODO: CT_ASSIGN_OUTPUT } } + // If we're about to launch the view into the floating container, then + // launch it as a tiled view in the root of the workspace instead. + if (container_is_floating(focus)) { + focus = focus->parent->parent; + } free(criterias); cont = container_view_create(focus, view); @@ -468,7 +502,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { wl_signal_add(&view->swayc->events.reparent, &view->container_reparent); view->container_reparent.notify = view_handle_container_reparent; - arrange_children_of(cont->parent); + if (view->impl->wants_floating && view->impl->wants_floating(view)) { + container_set_floating(view->swayc, true); + } else { + arrange_children_of(cont->parent); + } + input_manager_set_focus(input_manager, cont); if (workspace) { workspace_switch(workspace); @@ -516,16 +555,16 @@ void view_unmap(struct sway_view *view) { } } -void view_update_position(struct sway_view *view, double ox, double oy) { - if (view->swayc->x == ox && view->swayc->y == oy) { +void view_update_position(struct sway_view *view, double lx, double ly) { + if (view->x == lx && view->y == ly) { return; } - - // TODO: Only allow this if the view is floating (this function will only be - // called in response to wayland clients wanting to reposition themselves). container_damage_whole(view->swayc); - view->swayc->x = ox; - view->swayc->y = oy; + view->x = lx; + view->y = ly; + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } @@ -533,15 +572,15 @@ void view_update_size(struct sway_view *view, int width, int height) { if (view->width == width && view->height == height) { return; } - container_damage_whole(view->swayc); - // Should we update the swayc width/height here too? view->width = width; view->height = height; + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } - static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); @@ -888,6 +927,19 @@ bool view_is_visible(struct sway_view *view) { if (!view->swayc) { return false; } + struct sway_container *workspace = + container_parent(view->swayc, C_WORKSPACE); + // Determine if view is nested inside a floating container which is sticky. + // A simple floating view will have this ancestry: + // C_VIEW -> floating -> workspace + // A more complex ancestry could be: + // C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace + struct sway_container *floater = view->swayc; + while (floater->parent->type != C_WORKSPACE + && floater->parent->parent->type != C_WORKSPACE) { + floater = floater->parent; + } + bool is_sticky = container_is_floating(floater) && floater->is_sticky; // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; @@ -901,10 +953,12 @@ bool view_is_visible(struct sway_view *view) { container = container->parent; } // Check view isn't hidden by another fullscreen view - struct sway_container *workspace = container; if (workspace->sway_workspace->fullscreen && !view->is_fullscreen) { return false; } // Check the workspace is visible - return workspace_is_visible(workspace); + if (!is_sticky) { + return workspace_is_visible(workspace); + } + return true; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index f34baa9e..f78ae9a5 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -12,6 +12,7 @@ #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/workspace.h" +#include "list.h" #include "log.h" #include "util.h" @@ -64,6 +65,9 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; + swayws->floating = container_create(C_CONTAINER); + swayws->floating->parent = swayws->swayc; + swayws->floating->layout = L_FLOATING; workspace->sway_workspace = swayws; container_add_child(output, workspace); @@ -383,7 +387,21 @@ bool workspace_switch(struct sway_container *workspace) { strcpy(prev_workspace_name, active_ws->name); } - // TODO: Deal with sticky containers + // Move sticky containers to new workspace + struct sway_container *next_output = workspace->parent; + struct sway_container *next_output_prev_ws = + seat_get_active_child(seat, next_output); + struct sway_container *floating = + next_output_prev_ws->sway_workspace->floating; + bool has_sticky = false; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *floater = floating->children->items[i]; + if (floater->is_sticky) { + has_sticky = true; + container_remove_child(floater); + container_add_child(workspace->sway_workspace->floating, floater); + } + } wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); @@ -391,6 +409,16 @@ bool workspace_switch(struct sway_container *workspace) { if (next == NULL) { next = workspace; } + if (has_sticky) { + // If there's a sticky container, we might be setting focus to the same + // container that's already focused, so seat_set_focus is effectively a + // no op. We therefore need to send the IPC event and clean up the old + // workspace here. + ipc_event_workspace(active_ws, workspace, "focus"); + if (!workspace_is_visible(active_ws) && workspace_is_empty(active_ws)) { + container_destroy(active_ws); + } + } seat_set_focus(seat, next); struct sway_container *output = container_parent(workspace, C_OUTPUT); arrange_output(output); @@ -406,3 +434,21 @@ bool workspace_is_visible(struct sway_container *ws) { } return focus == ws; } + +bool workspace_is_empty(struct sway_container *ws) { + if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { + return false; + } + if (ws->children->length) { + return false; + } + // Sticky views are not considered to be part of this workspace + struct sway_container *floating = ws->sway_workspace->floating; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *floater = floating->children->items[i]; + if (!floater->is_sticky) { + return false; + } + } + return true; +} |