From f3ab895916ca1a0f004b5ceaefa90eee90676532 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:24:25 -0400 Subject: Implement `floating enable` --- sway/tree/layout.c | 43 +++++++++++++++++++++++++++++++++++++++---- sway/tree/workspace.c | 2 ++ 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 2f4ae667..7bbeb4b1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -142,11 +142,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { } struct sway_container *parent = child->parent; - for (int i = 0; i < parent->children->length; ++i) { - if (parent->children->items[i] == child) { - list_del(parent->children, i); - break; + if (!child->is_floating) { + for (int i = 0; i < parent->children->length; ++i) { + if (parent->children->items[i] == child) { + list_del(parent->children, i); + break; + } + } + } else { + if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW, + "Found floating non-view and/or in non-workspace")) { + return parent; + } + struct sway_workspace *ws = parent->sway_workspace; + for (int i = 0; i < ws->floating->length; ++i) { + if (ws->floating->items[i] == child) { + list_del(ws->floating, i); + break; + } } + child->is_floating = false; } child->parent = NULL; container_notify_subtree_changed(parent); @@ -154,6 +169,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { return parent; } +void container_add_floating(struct sway_container *workspace, + struct sway_container *child) { + if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW, + "Attempted to float non-view and/or in non-workspace")) { + return; + } + if (!sway_assert(!child->parent, + "child already has a parent (invalid call)")) { + return; + } + if (!sway_assert(!child->is_floating, + "child is already floating (invalid state)")) { + return; + } + struct sway_workspace *ws = workspace->sway_workspace; + list_add(ws->floating, child); + child->parent = workspace; + child->is_floating = true; +} + void container_move_to(struct sway_container *container, struct sway_container *destination) { if (container == destination diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index f34baa9e..c4f8ac5e 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,7 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; + swayws->floating = create_list(); workspace->sway_workspace = swayws; container_add_child(output, workspace); -- cgit v1.2.3 From 1f2e399ade77070a2d0b82856ad9a3eef96b8676 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 24 May 2018 22:30:44 +1000 Subject: Implement floating --- sway/tree/arrange.c | 12 +++++ sway/tree/container.c | 133 +++++++++++++++++++++++++++++++++++++++++++++----- sway/tree/layout.c | 73 +++++++++------------------ sway/tree/view.c | 87 +++++++++++++++++++++------------ sway/tree/workspace.c | 17 ++++++- 5 files changed, 229 insertions(+), 93 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index bdef56ea..da4f7889 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -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..f9a0474c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -123,6 +123,7 @@ struct sway_container *container_create(enum sway_container_type type) { c->layout = L_NONE; c->type = type; c->alpha = 1.0f; + c->reapable = true; if (type != C_VIEW) { c->children = create_list(); @@ -189,14 +190,13 @@ static struct sway_container *container_workspace_destroy( } struct sway_container *parent = workspace->parent; - if (workspace->children->length == 0) { - // destroy the WS if there are no children (TODO check for floating) + if (workspace_is_empty(workspace)) { + // destroy the WS if there are no children wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); ipc_event_workspace(workspace, NULL, "empty"); } else if (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 +209,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 +280,16 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { + if (!con->reapable) { + 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; @@ -436,7 +444,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 +455,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; } @@ -608,8 +618,6 @@ struct sway_container *container_at(struct sway_container *parent, return container_at_tabbed(parent, ox, oy, surface, sx, sy); case L_STACKED: return container_at_stacked(parent, ox, oy, surface, sx, sy); - case L_FLOATING: - return NULL; // TODO case L_NONE: return NULL; } @@ -617,6 +625,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; + bool ws_is_visible = workspace_is_visible(workspace); + for (int k = 0; k < ws->floating->children->length; ++k) { + struct sway_container *floater = + ws->floating->children->items[k]; + if (ws_is_visible || floater->is_sticky) { + 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 +710,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); @@ -806,9 +842,6 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe case L_STACKED: lenient_strcat(buffer, "S["); break; - case L_FLOATING: - lenient_strcat(buffer, "F["); - break; case L_NONE: lenient_strcat(buffer, "D["); break; @@ -866,3 +899,81 @@ void container_notify_subtree_changed(struct sway_container *container) { size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } + +static void configure_floating_view(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; + struct sway_container *output = ws->parent; + int lx = output->x + (ws->width - width) / 2; + int ly = output->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_set_maximized(view, false); + view_configure(view, lx, ly, width, height); +} + +void container_set_floating(struct sway_container *container, bool enable) { + if (container->is_floating == 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); + container->is_floating = true; + if (container->type == C_VIEW) { + configure_floating_view(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; + if (container->type == C_VIEW) { + view_set_maximized(container->sway_view, true); + } + container->is_floating = false; + container->is_sticky = false; + container_reap_empty_recursive(workspace->sway_workspace->floating); + } + arrange_workspace(workspace); + container_damage_whole(container); +} + +void container_set_geometry_from_view(struct sway_container *container) { + if (!sway_assert(container->type == C_VIEW, "Expected a view")) { + return; + } + if (!sway_assert(container->is_floating, "Expected a floating view")) { + return; + } + struct sway_view *view = container->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; + + container->x = view->x - border_width; + container->y = view->y - top; + container->width = view->width + border_width * 2; + container->height = top + view->height + border_width; +} + +bool container_self_or_parent_floating(struct sway_container *container) { + while (container->parent->type != C_WORKSPACE + && container->parent->parent->type != C_WORKSPACE) { + container = container->parent; + } + return container->is_floating; +} diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 7bbeb4b1..59ad0b53 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, @@ -142,26 +136,11 @@ struct sway_container *container_remove_child(struct sway_container *child) { } struct sway_container *parent = child->parent; - if (!child->is_floating) { - for (int i = 0; i < parent->children->length; ++i) { - if (parent->children->items[i] == child) { - list_del(parent->children, i); - break; - } - } - } else { - if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW, - "Found floating non-view and/or in non-workspace")) { - return parent; - } - struct sway_workspace *ws = parent->sway_workspace; - for (int i = 0; i < ws->floating->length; ++i) { - if (ws->floating->items[i] == child) { - list_del(ws->floating, i); - break; - } + for (int i = 0; i < parent->children->length; ++i) { + if (parent->children->items[i] == child) { + list_del(parent->children, i); + break; } - child->is_floating = false; } child->parent = NULL; container_notify_subtree_changed(parent); @@ -169,32 +148,16 @@ struct sway_container *container_remove_child(struct sway_container *child) { return parent; } -void container_add_floating(struct sway_container *workspace, - struct sway_container *child) { - if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW, - "Attempted to float non-view and/or in non-workspace")) { - return; - } - if (!sway_assert(!child->parent, - "child already has a parent (invalid call)")) { - return; - } - if (!sway_assert(!child->is_floating, - "child is already floating (invalid state)")) { - return; - } - struct sway_workspace *ws = workspace->sway_workspace; - list_add(ws->floating, child); - child->parent = workspace; - child->is_floating = true; -} - void container_move_to(struct sway_container *container, struct sway_container *destination) { if (container == destination || container_has_ancestor(container, destination)) { return; } + if (container->is_floating) { + // TODO + return; + } struct sway_container *old_parent = container_remove_child(container); container->width = container->height = 0; container->saved_width = container->saved_height = 0; @@ -207,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 = @@ -754,6 +718,10 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; + if (container->is_floating) { + return NULL; + } + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { if (dir == MOVE_PARENT || dir == MOVE_CHILD) { return NULL; @@ -778,6 +746,9 @@ 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), diff --git a/sway/tree/view.c b/sway/tree/view.c index 26ff1e8d..651a2be6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -158,21 +158,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 +182,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) { @@ -237,6 +235,12 @@ void view_set_activated(struct sway_view *view, bool activated) { } } +void view_set_maximized(struct sway_view *view, bool maximized) { + if (view->impl->set_maximized) { + view->impl->set_maximized(view, maximized); + } +} + // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { @@ -452,6 +456,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 (focus->is_floating) { + focus = focus->parent->parent; + } free(criterias); cont = container_view_create(focus, view); @@ -468,7 +477,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 +530,14 @@ 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->swayc->is_floating) { 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; + container_set_geometry_from_view(view->swayc); container_damage_whole(view->swayc); } @@ -533,15 +545,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 (view->swayc->is_floating) { + container_set_geometry_from_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 +900,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 (is_floating=true) -> floating -> workspace + // A more complex ancestry could be: + // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> 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 = floater->is_floating && 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 +926,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 c4f8ac5e..5bef409a 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -65,7 +65,9 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; - swayws->floating = create_list(); + swayws->floating = container_create(C_CONTAINER); + swayws->floating->parent = swayws->swayc; + swayws->floating->reapable = false; workspace->sway_workspace = swayws; container_add_child(output, workspace); @@ -408,3 +410,16 @@ 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; + } + if (ws->sway_workspace->floating->children->length) { + return false; + } + return true; +} -- cgit v1.2.3 From 34f35f0badc767d9b0cbaf2fd429af1d30592d08 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:10:35 +1000 Subject: Use L_FLOATING instead of reapable boolean --- sway/tree/container.c | 10 ++++++++-- sway/tree/workspace.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index f9a0474c..17d29d92 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -123,7 +123,6 @@ struct sway_container *container_create(enum sway_container_type type) { c->layout = L_NONE; c->type = type; c->alpha = 1.0f; - c->reapable = true; if (type != C_VIEW) { c->children = create_list(); @@ -280,7 +279,8 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { - if (!con->reapable) { + if (con->layout == L_FLOATING) { + // Don't reap the magical floating container that each workspace has return false; } switch (con->type) { @@ -618,6 +618,9 @@ struct sway_container *container_at(struct sway_container *parent, return container_at_tabbed(parent, ox, oy, surface, sx, sy); case L_STACKED: return container_at_stacked(parent, ox, oy, surface, sx, sy); + case L_FLOATING: + sway_assert(false, "Didn't expect to see floating here"); + return NULL; case L_NONE: return NULL; } @@ -842,6 +845,9 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe case L_STACKED: lenient_strcat(buffer, "S["); break; + case L_FLOATING: + strcpy(buffer, "F["); + break; case L_NONE: lenient_strcat(buffer, "D["); break; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 5bef409a..37d4a06a 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -67,7 +67,7 @@ struct sway_container *workspace_create(struct sway_container *output, swayws->swayc = workspace; swayws->floating = container_create(C_CONTAINER); swayws->floating->parent = swayws->swayc; - swayws->floating->reapable = false; + swayws->floating->layout = L_FLOATING; workspace->sway_workspace = swayws; container_add_child(output, workspace); -- cgit v1.2.3 From aaba7642b3e4e9a63aea49412b10221f399b17af Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:26:23 +1000 Subject: Replace is_floating boolean with function --- sway/tree/container.c | 24 ++++++++++++++++-------- sway/tree/layout.c | 4 ++-- sway/tree/view.c | 12 ++++++------ 3 files changed, 24 insertions(+), 16 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 17d29d92..c16f1748 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -924,7 +924,7 @@ static void configure_floating_view(struct sway_view *view) { } void container_set_floating(struct sway_container *container, bool enable) { - if (container->is_floating == enable) { + if (container_is_floating(container) == enable) { return; } @@ -935,7 +935,6 @@ void container_set_floating(struct sway_container *container, bool enable) { if (enable) { container_remove_child(container); container_add_child(workspace->sway_workspace->floating, container); - container->is_floating = true; if (container->type == C_VIEW) { configure_floating_view(container->sway_view); } @@ -950,7 +949,6 @@ void container_set_floating(struct sway_container *container, bool enable) { if (container->type == C_VIEW) { view_set_maximized(container->sway_view, true); } - container->is_floating = false; container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); } @@ -962,7 +960,8 @@ void container_set_geometry_from_view(struct sway_container *container) { if (!sway_assert(container->type == C_VIEW, "Expected a view")) { return; } - if (!sway_assert(container->is_floating, "Expected a floating view")) { + if (!sway_assert(container_is_floating(container), + "Expected a floating view")) { return; } struct sway_view *view = container->sway_view; @@ -977,9 +976,18 @@ void container_set_geometry_from_view(struct sway_container *container) { } bool container_self_or_parent_floating(struct sway_container *container) { - while (container->parent->type != C_WORKSPACE - && container->parent->parent->type != C_WORKSPACE) { - container = container->parent; + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + if (!workspace) { + return false; + } + return container_has_anscestor(container, + workspace->sway_workspace->floating); +} + +bool container_is_floating(struct sway_container *container) { + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + if (!workspace) { + return false; } - return container->is_floating; + return container->parent == workspace->sway_workspace->floating; } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 59ad0b53..28775253 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -154,7 +154,7 @@ void container_move_to(struct sway_container *container, || container_has_ancestor(container, destination)) { return; } - if (container->is_floating) { + if (container_is_floating(container)) { // TODO return; } @@ -718,7 +718,7 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; - if (container->is_floating) { + if (container_is_floating(container)) { return NULL; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 651a2be6..8548d9b8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -458,7 +458,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { } // 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 (focus->is_floating) { + if (container_is_floating(focus)) { focus = focus->parent->parent; } free(criterias); @@ -531,7 +531,7 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { - if (!view->swayc->is_floating) { + if (!container_is_floating(view->swayc)) { return; } container_damage_whole(view->swayc); @@ -548,7 +548,7 @@ void view_update_size(struct sway_view *view, int width, int height) { container_damage_whole(view->swayc); view->width = width; view->height = height; - if (view->swayc->is_floating) { + if (container_is_floating(view->swayc)) { container_set_geometry_from_view(view->swayc); } container_damage_whole(view->swayc); @@ -904,15 +904,15 @@ bool view_is_visible(struct sway_view *view) { 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 (is_floating=true) -> floating -> workspace + // C_VIEW -> floating -> workspace // A more complex ancestry could be: - // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace + // 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 = floater->is_floating && floater->is_sticky; + 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; -- cgit v1.2.3 From 13a4b0512e25b8da6e16ca1286f8b62fcc24c5cc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 11:15:43 +1000 Subject: Fix unfullscreening a floating view --- sway/tree/container.c | 19 +------------------ sway/tree/view.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index c16f1748..fd7ee2c3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -906,23 +906,6 @@ size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } -static void configure_floating_view(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; - struct sway_container *output = ws->parent; - int lx = output->x + (ws->width - width) / 2; - int ly = output->y + (ws->height - height) / 2; - - view->border_left = view->border_right = view->border_bottom = true; - view_set_maximized(view, false); - view_configure(view, lx, ly, width, height); -} - void container_set_floating(struct sway_container *container, bool enable) { if (container_is_floating(container) == enable) { return; @@ -936,7 +919,7 @@ void container_set_floating(struct sway_container *container, bool enable) { container_remove_child(container); container_add_child(workspace->sway_workspace->floating, container); if (container->type == C_VIEW) { - configure_floating_view(container->sway_view); + view_autoconfigure(container->sway_view); } seat_set_focus(seat, seat_get_focus_inactive(seat, container)); container_reap_empty_recursive(workspace); diff --git a/sway/tree/view.c b/sway/tree/view.c index 8548d9b8..65961dd9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -126,6 +126,23 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, } } +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; + struct sway_container *output = ws->parent; + int lx = output->x + (ws->width - width) / 2; + int ly = output->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_set_maximized(view, false); + 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")) { @@ -140,6 +157,11 @@ void view_autoconfigure(struct sway_view *view) { return; } + if (container_is_floating(view->swayc)) { + view_autoconfigure_floating(view); + return; + } + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); int other_views = 0; @@ -261,6 +283,8 @@ 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->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; @@ -283,6 +307,11 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { 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->swayc->x = view->swayc->saved_x; + view->swayc->y = view->swayc->saved_y; + view_autoconfigure(view); + } } } -- cgit v1.2.3 From dc83b158e12ae33f03165cfd64a50aa7f0a52e26 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 15:39:14 +1000 Subject: Fix issues with sticky containers and workspaces * Attach sticky containers to new workspaces when switching * Fire the close event *before* we start destroying the workspace to prevent a crash Because the sticky container now follows the visible workspace, this simplifies the rendering and container_at logic. --- sway/tree/container.c | 45 ++++++++++++++++++--------------------------- sway/tree/workspace.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 30 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index fd7ee2c3..532722e8 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,12 +178,11 @@ 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_is_empty(workspace)) { - // destroy the WS if there are no children - 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; for (int i = 0; i < output->children->length; i++) { @@ -357,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: @@ -635,20 +626,20 @@ struct sway_container *floating_container_at(double lx, double ly, for (int j = 0; j < output->children->length; ++j) { struct sway_container *workspace = output->children->items[j]; struct sway_workspace *ws = workspace->sway_workspace; - bool ws_is_visible = workspace_is_visible(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]; - if (ws_is_visible || floater->is_sticky) { - 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); - } + 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); } } } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 37d4a06a..f78ae9a5 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -387,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); @@ -395,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); @@ -418,8 +442,13 @@ bool workspace_is_empty(struct sway_container *ws) { if (ws->children->length) { return false; } - if (ws->sway_workspace->floating->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; } -- cgit v1.2.3 From 02de2a6f65c189bf563cca5b4d3fbc11826ea7f7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 09:22:10 +1000 Subject: Rename set_maximized functions to set_tiled --- sway/tree/container.c | 2 +- sway/tree/view.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 532722e8..12f74e37 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -921,7 +921,7 @@ void container_set_floating(struct sway_container *container, bool enable) { container->width = container->parent->width; container->height = container->parent->height; if (container->type == C_VIEW) { - view_set_maximized(container->sway_view, true); + view_set_tiled(container->sway_view, true); } container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); diff --git a/sway/tree/view.c b/sway/tree/view.c index 65961dd9..3de9879e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -139,7 +139,7 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = output->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_maximized(view, false); + view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -257,9 +257,9 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_maximized(struct sway_view *view, bool maximized) { - if (view->impl->set_maximized) { - view->impl->set_maximized(view, maximized); +void view_set_tiled(struct sway_view *view, bool tiled) { + if (view->impl->set_tiled) { + view->impl->set_tiled(view, tiled); } } -- cgit v1.2.3 From e4e912ea91a5a36d9f17c1730ffbf29707984399 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:26:10 +1000 Subject: Store swayc coordinates as layout-local --- sway/tree/arrange.c | 4 ++-- sway/tree/container.c | 42 +++++++++++++++++++++--------------------- sway/tree/view.c | 15 ++++++++------- 3 files changed, 31 insertions(+), 30 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index da4f7889..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); diff --git a/sway/tree/container.c b/sway/tree/container.c index 12f74e37..7928ffc3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -467,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; @@ -516,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; } @@ -538,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); @@ -563,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]; @@ -580,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; @@ -604,11 +604,11 @@ 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: sway_assert(false, "Didn't expect to see floating here"); return NULL; @@ -837,7 +837,7 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe lenient_strcat(buffer, "S["); break; case L_FLOATING: - strcpy(buffer, "F["); + lenient_strcat(buffer, "F["); break; case L_NONE: lenient_strcat(buffer, "D["); diff --git a/sway/tree/view.c b/sway/tree/view.c index 3de9879e..065d00db 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -119,10 +119,10 @@ 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); } } @@ -134,9 +134,8 @@ static void view_autoconfigure_floating(struct sway_view *view) { view->natural_width > max_width ? max_width : view->natural_width; int height = view->natural_height > max_height ? max_height : view->natural_height; - struct sway_container *output = ws->parent; - int lx = output->x + (ws->width - width) / 2; - int ly = output->y + (ws->height - height) / 2; + 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_set_tiled(view, false); @@ -152,8 +151,7 @@ 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; } @@ -560,6 +558,9 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { + if (view->x == lx && view->y == ly) { + return; + } if (!container_is_floating(view->swayc)) { return; } -- cgit v1.2.3 From 70f5d6fcf3219f122077b7e8d0b43a464f4e3fd4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:32:24 +1000 Subject: Rename container_set_geometry_from_view --- sway/tree/container.c | 16 ++++++++-------- sway/tree/view.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 7928ffc3..7430aebb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -930,23 +930,23 @@ void container_set_floating(struct sway_container *container, bool enable) { container_damage_whole(container); } -void container_set_geometry_from_view(struct sway_container *container) { - if (!sway_assert(container->type == C_VIEW, "Expected a view")) { +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(container), + if (!sway_assert(container_is_floating(con), "Expected a floating view")) { return; } - struct sway_view *view = container->sway_view; + 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; - container->x = view->x - border_width; - container->y = view->y - top; - container->width = view->width + border_width * 2; - container->height = top + view->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_self_or_parent_floating(struct sway_container *container) { diff --git a/sway/tree/view.c b/sway/tree/view.c index 065d00db..30d5c7b4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -567,7 +567,7 @@ void view_update_position(struct sway_view *view, double lx, double ly) { container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); container_damage_whole(view->swayc); } @@ -579,7 +579,7 @@ void view_update_size(struct sway_view *view, int width, int height) { view->width = width; view->height = height; if (container_is_floating(view->swayc)) { - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); } container_damage_whole(view->swayc); } -- cgit v1.2.3 From d4ed204d4da742ccabae29db2c90a62d90244a90 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:34:15 +1000 Subject: Remove container_self_or_parent_floating --- sway/tree/container.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 7430aebb..4e041508 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -949,15 +949,6 @@ void container_set_geometry_from_floating_view(struct sway_container *con) { con->height = top + view->height + border_width; } -bool container_self_or_parent_floating(struct sway_container *container) { - struct sway_container *workspace = container_parent(container, C_WORKSPACE); - if (!workspace) { - return false; - } - return container_has_anscestor(container, - workspace->sway_workspace->floating); -} - bool container_is_floating(struct sway_container *container) { struct sway_container *workspace = container_parent(container, C_WORKSPACE); if (!workspace) { -- cgit v1.2.3 From 40af5d81a1da972cdd59ecb0372ee756433aba26 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 09:46:40 +1000 Subject: Fix getting adjacent output --- sway/tree/layout.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 28775253..d88948dc 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -680,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; @@ -755,8 +735,8 @@ struct sway_container *container_get_in_direction( "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 = -- cgit v1.2.3 From 97672295ed50d1d6272876c4a3b6b5607cab05c6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 23:43:05 +1000 Subject: Don't unmaximize floating views --- sway/tree/container.c | 3 --- sway/tree/view.c | 7 ------- 2 files changed, 10 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 4e041508..9e70da09 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -920,9 +920,6 @@ void container_set_floating(struct sway_container *container, bool enable) { container_add_child(workspace, container); container->width = container->parent->width; container->height = container->parent->height; - if (container->type == C_VIEW) { - view_set_tiled(container->sway_view, true); - } container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); } diff --git a/sway/tree/view.c b/sway/tree/view.c index 30d5c7b4..6e589611 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -138,7 +138,6 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = ws->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -255,12 +254,6 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_tiled(struct sway_view *view, bool tiled) { - if (view->impl->set_tiled) { - view->impl->set_tiled(view, tiled); - } -} - // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { -- cgit v1.2.3 From f24087d1045bbee8642ee0703f6513ae605f2c47 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 28 May 2018 17:42:56 +1000 Subject: Fix fullscreen position --- sway/tree/view.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/view.c b/sway/tree/view.c index 6e589611..2eaa5d49 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -554,13 +554,12 @@ void view_update_position(struct sway_view *view, double lx, double ly) { if (view->x == lx && view->y == ly) { return; } - if (!container_is_floating(view->swayc)) { - return; - } container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_floating_view(view->swayc); + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } -- cgit v1.2.3 From a2c1cb9072b990de9181bffeb69e43f9b3030804 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 18:21:49 +1000 Subject: Fix mpv damage issue when unfullscreening into floating --- sway/tree/view.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/view.c b/sway/tree/view.c index 2eaa5d49..3117ded6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -274,6 +274,10 @@ 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; @@ -296,11 +300,12 @@ 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->swayc->x = view->swayc->saved_x; - view->swayc->y = view->swayc->saved_y; + 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); } } -- cgit v1.2.3