aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-24 22:30:44 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-01 23:14:58 +1000
commit1f2e399ade77070a2d0b82856ad9a3eef96b8676 (patch)
treec469197e140051aea912cb173723c7e55ce1e410 /sway/tree/layout.c
parentSend frame done to floating views (diff)
downloadsway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.tar.gz
sway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.tar.zst
sway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.zip
Implement floating
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c73
1 files changed, 22 insertions, 51 deletions
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) {
45} 45}
46 46
47static int index_child(const struct sway_container *child) { 47static int index_child(const struct sway_container *child) {
48 // TODO handle floating
49 struct sway_container *parent = child->parent; 48 struct sway_container *parent = child->parent;
50 int i, len; 49 for (int i = 0; i < parent->children->length; ++i) {
51 len = parent->children->length;
52 for (i = 0; i < len; ++i) {
53 if (parent->children->items[i] == child) { 50 if (parent->children->items[i] == child) {
54 break; 51 return i;
55 } 52 }
56 } 53 }
57 54 // This happens if the child is a floating container
58 if (!sway_assert(i < len, "Stray container")) { 55 return -1;
59 return -1;
60 }
61 return i;
62} 56}
63 57
64static void container_handle_fullscreen_reparent(struct sway_container *viewcon, 58static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
@@ -142,26 +136,11 @@ struct sway_container *container_remove_child(struct sway_container *child) {
142 } 136 }
143 137
144 struct sway_container *parent = child->parent; 138 struct sway_container *parent = child->parent;
145 if (!child->is_floating) { 139 for (int i = 0; i < parent->children->length; ++i) {
146 for (int i = 0; i < parent->children->length; ++i) { 140 if (parent->children->items[i] == child) {
147 if (parent->children->items[i] == child) { 141 list_del(parent->children, i);
148 list_del(parent->children, i); 142 break;
149 break;
150 }
151 }
152 } else {
153 if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW,
154 "Found floating non-view and/or in non-workspace")) {
155 return parent;
156 }
157 struct sway_workspace *ws = parent->sway_workspace;
158 for (int i = 0; i < ws->floating->length; ++i) {
159 if (ws->floating->items[i] == child) {
160 list_del(ws->floating, i);
161 break;
162 }
163 } 143 }
164 child->is_floating = false;
165 } 144 }
166 child->parent = NULL; 145 child->parent = NULL;
167 container_notify_subtree_changed(parent); 146 container_notify_subtree_changed(parent);
@@ -169,32 +148,16 @@ struct sway_container *container_remove_child(struct sway_container *child) {
169 return parent; 148 return parent;
170} 149}
171 150
172void container_add_floating(struct sway_container *workspace,
173 struct sway_container *child) {
174 if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW,
175 "Attempted to float non-view and/or in non-workspace")) {
176 return;
177 }
178 if (!sway_assert(!child->parent,
179 "child already has a parent (invalid call)")) {
180 return;
181 }
182 if (!sway_assert(!child->is_floating,
183 "child is already floating (invalid state)")) {
184 return;
185 }
186 struct sway_workspace *ws = workspace->sway_workspace;
187 list_add(ws->floating, child);
188 child->parent = workspace;
189 child->is_floating = true;
190}
191
192void container_move_to(struct sway_container *container, 151void container_move_to(struct sway_container *container,
193 struct sway_container *destination) { 152 struct sway_container *destination) {
194 if (container == destination 153 if (container == destination
195 || container_has_ancestor(container, destination)) { 154 || container_has_ancestor(container, destination)) {
196 return; 155 return;
197 } 156 }
157 if (container->is_floating) {
158 // TODO
159 return;
160 }
198 struct sway_container *old_parent = container_remove_child(container); 161 struct sway_container *old_parent = container_remove_child(container);
199 container->width = container->height = 0; 162 container->width = container->height = 0;
200 container->saved_width = container->saved_height = 0; 163 container->saved_width = container->saved_height = 0;
@@ -207,8 +170,9 @@ void container_move_to(struct sway_container *container,
207 } 170 }
208 wl_signal_emit(&container->events.reparent, old_parent); 171 wl_signal_emit(&container->events.reparent, old_parent);
209 if (container->type == C_WORKSPACE) { 172 if (container->type == C_WORKSPACE) {
210 struct sway_seat *seat = input_manager_get_default_seat( 173 // If moving a workspace to a new output, maybe create a new workspace
211 input_manager); 174 // on the previous output
175 struct sway_seat *seat = input_manager_get_default_seat(input_manager);
212 if (old_parent->children->length == 0) { 176 if (old_parent->children->length == 0) {
213 char *ws_name = workspace_next_name(old_parent->name); 177 char *ws_name = workspace_next_name(old_parent->name);
214 struct sway_container *ws = 178 struct sway_container *ws =
@@ -754,6 +718,10 @@ struct sway_container *container_get_in_direction(
754 enum movement_direction dir) { 718 enum movement_direction dir) {
755 struct sway_container *parent = container->parent; 719 struct sway_container *parent = container->parent;
756 720
721 if (container->is_floating) {
722 return NULL;
723 }
724
757 if (container->type == C_VIEW && container->sway_view->is_fullscreen) { 725 if (container->type == C_VIEW && container->sway_view->is_fullscreen) {
758 if (dir == MOVE_PARENT || dir == MOVE_CHILD) { 726 if (dir == MOVE_PARENT || dir == MOVE_CHILD) {
759 return NULL; 727 return NULL;
@@ -778,6 +746,9 @@ struct sway_container *container_get_in_direction(
778 bool can_move = false; 746 bool can_move = false;
779 int desired; 747 int desired;
780 int idx = index_child(container); 748 int idx = index_child(container);
749 if (idx == -1) {
750 return NULL;
751 }
781 if (parent->type == C_ROOT) { 752 if (parent->type == C_ROOT) {
782 enum wlr_direction wlr_dir = 0; 753 enum wlr_direction wlr_dir = 0;
783 if (!sway_assert(sway_dir_to_wlr(dir, &wlr_dir), 754 if (!sway_assert(sway_dir_to_wlr(dir, &wlr_dir),