diff options
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 109 |
1 files changed, 81 insertions, 28 deletions
diff --git a/sway/layout.c b/sway/layout.c index 18ecb1e7..fd2e80fe 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -20,7 +20,8 @@ void init_layout(void) { | |||
20 | root_container.handle = -1; | 20 | root_container.handle = -1; |
21 | } | 21 | } |
22 | 22 | ||
23 | static int index_child(swayc_t *parent, swayc_t *child) { | 23 | static int index_child(swayc_t *child) { |
24 | swayc_t *parent = child->parent; | ||
24 | int i; | 25 | int i; |
25 | for (i = 0; i < parent->children->length; ++i) { | 26 | for (i = 0; i < parent->children->length; ++i) { |
26 | if (parent->children->items[i] == child) { | 27 | if (parent->children->items[i] == child) { |
@@ -54,7 +55,7 @@ void add_floating(swayc_t *ws, swayc_t *child) { | |||
54 | 55 | ||
55 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { | 56 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { |
56 | swayc_t *parent = sibling->parent; | 57 | swayc_t *parent = sibling->parent; |
57 | int i = index_child(parent, sibling); | 58 | int i = index_child(sibling); |
58 | if (i == parent->children->length) { | 59 | if (i == parent->children->length) { |
59 | --i; | 60 | --i; |
60 | } | 61 | } |
@@ -68,17 +69,65 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { | |||
68 | if (parent == NULL) { | 69 | if (parent == NULL) { |
69 | return NULL; | 70 | return NULL; |
70 | } | 71 | } |
71 | int i = index_child(parent, child); | 72 | int i = index_child(child); |
72 | parent->children->items[i] = new_child; | 73 | parent->children->items[i] = new_child; |
73 | new_child->parent = child->parent; | 74 | new_child->parent = child->parent; |
74 | 75 | ||
76 | // Set parent for new child | ||
75 | if (child->parent->focused == child) { | 77 | if (child->parent->focused == child) { |
76 | child->parent->focused = new_child; | 78 | child->parent->focused = new_child; |
77 | } | 79 | } |
78 | child->parent = NULL; | 80 | child->parent = NULL; |
81 | // Set geometry for new child | ||
82 | new_child->x = child->x; | ||
83 | new_child->y = child->y; | ||
84 | new_child->width = child->width; | ||
85 | new_child->height = child->height; | ||
86 | // set child geometry to 0 | ||
87 | child->x = 0; | ||
88 | child->y = 0; | ||
89 | child->width = 0; | ||
90 | child->height = 0; | ||
79 | return parent; | 91 | return parent; |
80 | } | 92 | } |
81 | 93 | ||
94 | void swap_container(swayc_t *a, swayc_t *b) { | ||
95 | //TODO doesnt handle floating <-> tiling swap | ||
96 | if (!sway_assert(a&&b, "%s: parameters must be non null",__func__) || | ||
97 | !sway_assert(a->parent && b->parent, "%s: containers must have parents",__func__)) { | ||
98 | return; | ||
99 | } | ||
100 | size_t a_index = index_child(a); | ||
101 | size_t b_index = index_child(b); | ||
102 | swayc_t *a_parent = a->parent; | ||
103 | swayc_t *b_parent = b->parent; | ||
104 | // Swap the pointers | ||
105 | a_parent->children->items[a_index] = b; | ||
106 | b_parent->children->items[b_index] = a; | ||
107 | a->parent = b_parent; | ||
108 | b->parent = a_parent; | ||
109 | if (a_parent->focused == a) { | ||
110 | a_parent->focused = b; | ||
111 | } | ||
112 | // dont want to double switch | ||
113 | if (b_parent->focused == b && a_parent != b_parent) { | ||
114 | b_parent->focused = a; | ||
115 | } | ||
116 | // and their geometry | ||
117 | double x = a->x; | ||
118 | double y = a->y; | ||
119 | double w = a->width; | ||
120 | double h = a->height; | ||
121 | a->x = b->x; | ||
122 | a->y = b->y; | ||
123 | a->width = b->width; | ||
124 | a->height = b->height; | ||
125 | b->x = x; | ||
126 | b->y = y; | ||
127 | b->width = w; | ||
128 | b->height = h; | ||
129 | } | ||
130 | |||
82 | swayc_t *remove_child(swayc_t *child) { | 131 | swayc_t *remove_child(swayc_t *child) { |
83 | int i; | 132 | int i; |
84 | swayc_t *parent = child->parent; | 133 | swayc_t *parent = child->parent; |
@@ -154,6 +203,30 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir | |||
154 | 203 | ||
155 | } | 204 | } |
156 | 205 | ||
206 | void update_geometry(swayc_t *container) { | ||
207 | if (container->type != C_VIEW) { | ||
208 | return; | ||
209 | } | ||
210 | struct wlc_geometry geometry = { | ||
211 | .origin = { | ||
212 | .x = container->x + container->gaps / 2, | ||
213 | .y = container->y + container->gaps / 2 | ||
214 | }, | ||
215 | .size = { | ||
216 | .w = container->width - container->gaps, | ||
217 | .h = container->height - container->gaps | ||
218 | } | ||
219 | }; | ||
220 | if (swayc_is_fullscreen(container)) { | ||
221 | swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); | ||
222 | geometry.origin.x = 0; | ||
223 | geometry.origin.y = 0; | ||
224 | geometry.size.w = parent->width; | ||
225 | geometry.size.h = parent->height; | ||
226 | } | ||
227 | wlc_view_set_geometry(container->handle, 0, &geometry); | ||
228 | return; | ||
229 | } | ||
157 | 230 | ||
158 | void arrange_windows(swayc_t *container, double width, double height) { | 231 | void arrange_windows(swayc_t *container, double width, double height) { |
159 | int i; | 232 | int i; |
@@ -196,31 +269,11 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
196 | return; | 269 | return; |
197 | case C_VIEW: | 270 | case C_VIEW: |
198 | { | 271 | { |
199 | struct wlc_geometry geometry = { | 272 | container->width = width; |
200 | .origin = { | 273 | container->height = height; |
201 | .x = container->x + container->gaps / 2, | 274 | update_geometry(container); |
202 | .y = container->y + container->gaps / 2 | 275 | sway_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", container->width, |
203 | }, | 276 | container->height, container->x, container->y); |
204 | .size = { | ||
205 | .w = width - container->gaps, | ||
206 | .h = height - container->gaps | ||
207 | } | ||
208 | }; | ||
209 | if (swayc_is_fullscreen(container)) { | ||
210 | swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); | ||
211 | geometry.origin.x = 0; | ||
212 | geometry.origin.y = 0; | ||
213 | geometry.size.w = parent->width; | ||
214 | geometry.size.h = parent->height; | ||
215 | wlc_view_set_geometry(container->handle, 0, &geometry); | ||
216 | wlc_view_bring_to_front(container->handle); | ||
217 | } else { | ||
218 | wlc_view_set_geometry(container->handle, 0, &geometry); | ||
219 | container->width = width; | ||
220 | container->height = height; | ||
221 | } | ||
222 | sway_log(L_DEBUG, "Set view to %d x %d @ %d, %d", geometry.size.w, geometry.size.h, | ||
223 | geometry.origin.x, geometry.origin.y); | ||
224 | } | 277 | } |
225 | return; | 278 | return; |
226 | default: | 279 | default: |