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 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'sway/tree/layout.c') 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 -- 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/layout.c | 73 ++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) (limited to 'sway/tree/layout.c') 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), -- 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/layout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sway/tree/layout.c') 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; } -- 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/layout.c') 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