diff options
author | Zandr Martin <zandrmartin@gmail.com> | 2016-09-07 06:48:41 -0500 |
---|---|---|
committer | Zandr Martin <zandrmartin@gmail.com> | 2016-09-07 06:48:41 -0500 |
commit | 511eed90cd925ec6bba93a8a749eb6a230ac5f98 (patch) | |
tree | bb1fc5102d3d8587c78ca11271631a584994da3b /sway | |
parent | Remove extraneous logging (diff) | |
download | sway-511eed90cd925ec6bba93a8a749eb6a230ac5f98.tar.gz sway-511eed90cd925ec6bba93a8a749eb6a230ac5f98.tar.zst sway-511eed90cd925ec6bba93a8a749eb6a230ac5f98.zip |
squash commits, move enum into resize.c
Diffstat (limited to 'sway')
-rw-r--r-- | sway/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/resize.c | 343 | ||||
-rw-r--r-- | sway/handlers.c | 1 | ||||
-rw-r--r-- | sway/resize.c | 338 |
5 files changed, 342 insertions, 342 deletions
diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index 36c03923..bb9ea81f 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt | |||
@@ -33,7 +33,6 @@ add_executable(sway | |||
33 | layout.c | 33 | layout.c |
34 | main.c | 34 | main.c |
35 | output.c | 35 | output.c |
36 | resize.c | ||
37 | workspace.c | 36 | workspace.c |
38 | border.c | 37 | border.c |
39 | ) | 38 | ) |
diff --git a/sway/commands.c b/sway/commands.c index 54c104b2..317122cd 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include "sway/container.h" | 23 | #include "sway/container.h" |
24 | #include "sway/output.h" | 24 | #include "sway/output.h" |
25 | #include "sway/handlers.h" | 25 | #include "sway/handlers.h" |
26 | #include "sway/resize.h" | ||
27 | #include "sway/input_state.h" | 26 | #include "sway/input_state.h" |
28 | #include "sway/criteria.h" | 27 | #include "sway/criteria.h" |
29 | #include "sway/ipc-server.h" | 28 | #include "sway/ipc-server.h" |
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 90ab824f..2c5b3f6b 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -1,11 +1,352 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <math.h> | ||
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
6 | #include <wlc/wlc.h> | ||
5 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
6 | #include "sway/resize.h" | 8 | #include "sway/layout.h" |
9 | #include "sway/focus.h" | ||
10 | #include "sway/input_state.h" | ||
11 | #include "sway/handlers.h" | ||
7 | #include "log.h" | 12 | #include "log.h" |
8 | 13 | ||
14 | enum resize_dim_types { | ||
15 | RESIZE_DIM_PX, | ||
16 | RESIZE_DIM_PPT, | ||
17 | RESIZE_DIM_DEFAULT, | ||
18 | }; | ||
19 | |||
20 | static bool set_size_floating(int new_dimension, bool use_width) { | ||
21 | swayc_t *view = get_focused_float(swayc_active_workspace()); | ||
22 | if (view) { | ||
23 | if (use_width) { | ||
24 | int current_width = view->width; | ||
25 | view->desired_width = new_dimension; | ||
26 | floating_view_sane_size(view); | ||
27 | |||
28 | int new_x = view->x + (int)(((view->desired_width - current_width) / 2) * -1); | ||
29 | view->width = view->desired_width; | ||
30 | view->x = new_x; | ||
31 | |||
32 | update_geometry(view); | ||
33 | } else { | ||
34 | int current_height = view->height; | ||
35 | view->desired_height = new_dimension; | ||
36 | floating_view_sane_size(view); | ||
37 | |||
38 | int new_y = view->y + (int)(((view->desired_height - current_height) / 2) * -1); | ||
39 | view->height = view->desired_height; | ||
40 | view->y = new_y; | ||
41 | |||
42 | update_geometry(view); | ||
43 | } | ||
44 | |||
45 | return true; | ||
46 | } | ||
47 | |||
48 | return false; | ||
49 | } | ||
50 | |||
51 | static bool resize_floating(int amount, bool use_width) { | ||
52 | swayc_t *view = get_focused_float(swayc_active_workspace()); | ||
53 | |||
54 | if (view) { | ||
55 | if (use_width) { | ||
56 | return set_size_floating(view->width + amount, true); | ||
57 | } else { | ||
58 | return set_size_floating(view->height + amount, false); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | return false; | ||
63 | } | ||
64 | |||
65 | static bool resize_tiled(int amount, bool use_width) { | ||
66 | swayc_t *parent = get_focused_view(swayc_active_workspace()); | ||
67 | swayc_t *focused = parent; | ||
68 | swayc_t *sibling; | ||
69 | if (!parent) { | ||
70 | return true; | ||
71 | } | ||
72 | // Find the closest parent container which has siblings of the proper layout. | ||
73 | // Then apply the resize to all of them. | ||
74 | int i; | ||
75 | if (use_width) { | ||
76 | int lnumber = 0; | ||
77 | int rnumber = 0; | ||
78 | while (parent->parent) { | ||
79 | if (parent->parent->layout == L_HORIZ && parent->parent->children) { | ||
80 | for (i = 0; i < parent->parent->children->length; i++) { | ||
81 | sibling = parent->parent->children->items[i]; | ||
82 | if (sibling->x != focused->x) { | ||
83 | if (sibling->x < parent->x) { | ||
84 | lnumber++; | ||
85 | } else if (sibling->x > parent->x) { | ||
86 | rnumber++; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | if (rnumber || lnumber) { | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | parent = parent->parent; | ||
95 | } | ||
96 | if (parent == &root_container) { | ||
97 | return true; | ||
98 | } | ||
99 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); | ||
100 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
101 | bool valid = true; | ||
102 | for (i = 0; i < parent->parent->children->length; i++) { | ||
103 | sibling = parent->parent->children->items[i]; | ||
104 | if (sibling->x != focused->x) { | ||
105 | if (sibling->x < parent->x) { | ||
106 | double pixels = -1 * amount; | ||
107 | pixels /= lnumber; | ||
108 | if (rnumber) { | ||
109 | if ((sibling->width + pixels/2) < min_sane_w) { | ||
110 | valid = false; | ||
111 | break; | ||
112 | } | ||
113 | } else { | ||
114 | if ((sibling->width + pixels) < min_sane_w) { | ||
115 | valid = false; | ||
116 | break; | ||
117 | } | ||
118 | } | ||
119 | } else if (sibling->x > parent->x) { | ||
120 | double pixels = -1 * amount; | ||
121 | pixels /= rnumber; | ||
122 | if (lnumber) { | ||
123 | if ((sibling->width + pixels/2) < min_sane_w) { | ||
124 | valid = false; | ||
125 | break; | ||
126 | } | ||
127 | } else { | ||
128 | if ((sibling->width + pixels) < min_sane_w) { | ||
129 | valid = false; | ||
130 | break; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | } else { | ||
135 | double pixels = amount; | ||
136 | if (parent->width + pixels < min_sane_w) { | ||
137 | valid = false; | ||
138 | break; | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | if (valid) { | ||
143 | for (i = 0; i < parent->parent->children->length; i++) { | ||
144 | sibling = parent->parent->children->items[i]; | ||
145 | if (sibling->x != focused->x) { | ||
146 | if (sibling->x < parent->x) { | ||
147 | double pixels = -1 * amount; | ||
148 | pixels /= lnumber; | ||
149 | if (rnumber) { | ||
150 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT); | ||
151 | } else { | ||
152 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
153 | } | ||
154 | } else if (sibling->x > parent->x) { | ||
155 | double pixels = -1 * amount; | ||
156 | pixels /= rnumber; | ||
157 | if (lnumber) { | ||
158 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT); | ||
159 | } else { | ||
160 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT); | ||
161 | } | ||
162 | } | ||
163 | } else { | ||
164 | if (rnumber != 0 && lnumber != 0) { | ||
165 | double pixels = amount; | ||
166 | pixels /= 2; | ||
167 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT); | ||
168 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
169 | } else if (rnumber) { | ||
170 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT); | ||
171 | } else if (lnumber) { | ||
172 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | // Recursive resize does not handle positions, let arrange_windows | ||
177 | // take care of that. | ||
178 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
179 | } | ||
180 | return true; | ||
181 | } else { | ||
182 | int tnumber = 0; | ||
183 | int bnumber = 0; | ||
184 | while (parent->parent) { | ||
185 | if (parent->parent->layout == L_VERT) { | ||
186 | for (i = 0; i < parent->parent->children->length; i++) { | ||
187 | sibling = parent->parent->children->items[i]; | ||
188 | if (sibling->y != focused->y) { | ||
189 | if (sibling->y < parent->y) { | ||
190 | bnumber++; | ||
191 | } else if (sibling->y > parent->y) { | ||
192 | tnumber++; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | if (bnumber || tnumber) { | ||
197 | break; | ||
198 | } | ||
199 | } | ||
200 | parent = parent->parent; | ||
201 | } | ||
202 | if (parent->parent == NULL || parent->parent->children == NULL) { | ||
203 | return true; | ||
204 | } | ||
205 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); | ||
206 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
207 | bool valid = true; | ||
208 | for (i = 0; i < parent->parent->children->length; i++) { | ||
209 | sibling = parent->parent->children->items[i]; | ||
210 | if (sibling->y != focused->y) { | ||
211 | if (sibling->y < parent->y) { | ||
212 | double pixels = -1 * amount; | ||
213 | pixels /= bnumber; | ||
214 | if (tnumber) { | ||
215 | if ((sibling->height + pixels/2) < min_sane_h) { | ||
216 | valid = false; | ||
217 | break; | ||
218 | } | ||
219 | } else { | ||
220 | if ((sibling->height + pixels) < min_sane_h) { | ||
221 | valid = false; | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | } else if (sibling->y > parent->y) { | ||
226 | double pixels = -1 * amount; | ||
227 | pixels /= tnumber; | ||
228 | if (bnumber) { | ||
229 | if ((sibling->height + pixels/2) < min_sane_h) { | ||
230 | valid = false; | ||
231 | break; | ||
232 | } | ||
233 | } else { | ||
234 | if ((sibling->height + pixels) < min_sane_h) { | ||
235 | valid = false; | ||
236 | break; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | } else { | ||
241 | double pixels = amount; | ||
242 | if (parent->height + pixels < min_sane_h) { | ||
243 | valid = false; | ||
244 | break; | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | if (valid) { | ||
249 | for (i = 0; i < parent->parent->children->length; i++) { | ||
250 | sibling = parent->parent->children->items[i]; | ||
251 | if (sibling->y != focused->y) { | ||
252 | if (sibling->y < parent->y) { | ||
253 | double pixels = -1 * amount; | ||
254 | pixels /= bnumber; | ||
255 | if (tnumber) { | ||
256 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM); | ||
257 | } else { | ||
258 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
259 | } | ||
260 | } else if (sibling->x > parent->x) { | ||
261 | double pixels = -1 * amount; | ||
262 | pixels /= tnumber; | ||
263 | if (bnumber) { | ||
264 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP); | ||
265 | } else { | ||
266 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP); | ||
267 | } | ||
268 | } | ||
269 | } else { | ||
270 | if (bnumber != 0 && tnumber != 0) { | ||
271 | double pixels = amount/2; | ||
272 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP); | ||
273 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
274 | } else if (tnumber) { | ||
275 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP); | ||
276 | } else if (bnumber) { | ||
277 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM); | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
282 | } | ||
283 | return true; | ||
284 | } | ||
285 | return true; | ||
286 | } | ||
287 | |||
288 | static bool set_size_tiled(int amount, bool use_width) { | ||
289 | int desired; | ||
290 | swayc_t *focused = get_focused_view(swayc_active_workspace()); | ||
291 | |||
292 | if (use_width) { | ||
293 | desired = amount - focused->width; | ||
294 | } else { | ||
295 | desired = amount - focused->height; | ||
296 | } | ||
297 | |||
298 | return resize_tiled(desired, use_width); | ||
299 | } | ||
300 | |||
301 | static bool set_size(int dimension, bool use_width) { | ||
302 | swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace()); | ||
303 | |||
304 | if (focused) { | ||
305 | if (focused->is_floating) { | ||
306 | return set_size_floating(dimension, use_width); | ||
307 | } else { | ||
308 | return set_size_tiled(dimension, use_width); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | return false; | ||
313 | } | ||
314 | |||
315 | static bool resize(int dimension, bool use_width, enum resize_dim_types dim_type) { | ||
316 | swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace()); | ||
317 | |||
318 | // translate "10 ppt" (10%) to appropriate # of pixels in case we need it | ||
319 | float ppt_dim = (float)dimension / 100; | ||
320 | |||
321 | if (use_width) { | ||
322 | ppt_dim = focused->width * ppt_dim; | ||
323 | } else { | ||
324 | ppt_dim = focused->height * ppt_dim; | ||
325 | } | ||
326 | |||
327 | if (focused) { | ||
328 | if (focused->is_floating) { | ||
329 | // floating view resize dimensions should default to px, so only | ||
330 | // use ppt if specified | ||
331 | if (dim_type == RESIZE_DIM_PPT) { | ||
332 | dimension = (int)ppt_dim; | ||
333 | } | ||
334 | |||
335 | return resize_floating(dimension, use_width); | ||
336 | } else { | ||
337 | // tiled view resize dimensions should default to ppt, so only use | ||
338 | // px if specified | ||
339 | if (dim_type != RESIZE_DIM_PX) { | ||
340 | dimension = (int)ppt_dim; | ||
341 | } | ||
342 | |||
343 | return resize_tiled(dimension, use_width); | ||
344 | } | ||
345 | } | ||
346 | |||
347 | return false; | ||
348 | } | ||
349 | |||
9 | static struct cmd_results *cmd_resize_set(int argc, char **argv) { | 350 | static struct cmd_results *cmd_resize_set(int argc, char **argv) { |
10 | struct cmd_results *error = NULL; | 351 | struct cmd_results *error = NULL; |
11 | if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { | 352 | if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { |
diff --git a/sway/handlers.c b/sway/handlers.c index 26da5407..1afdcbbb 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include "sway/output.h" | 17 | #include "sway/output.h" |
18 | #include "sway/focus.h" | 18 | #include "sway/focus.h" |
19 | #include "sway/input_state.h" | 19 | #include "sway/input_state.h" |
20 | #include "sway/resize.h" | ||
21 | #include "sway/extensions.h" | 20 | #include "sway/extensions.h" |
22 | #include "sway/criteria.h" | 21 | #include "sway/criteria.h" |
23 | #include "sway/ipc-server.h" | 22 | #include "sway/ipc-server.h" |
diff --git a/sway/resize.c b/sway/resize.c deleted file mode 100644 index b32d2431..00000000 --- a/sway/resize.c +++ /dev/null | |||
@@ -1,338 +0,0 @@ | |||
1 | #include <wlc/wlc.h> | ||
2 | #include <math.h> | ||
3 | #include "sway/layout.h" | ||
4 | #include "sway/focus.h" | ||
5 | #include "sway/input_state.h" | ||
6 | #include "sway/handlers.h" | ||
7 | #include "sway/resize.h" | ||
8 | #include "log.h" | ||
9 | |||
10 | static bool set_size_floating(int new_dimension, bool use_width) { | ||
11 | swayc_t *view = get_focused_float(swayc_active_workspace()); | ||
12 | if (view) { | ||
13 | if (use_width) { | ||
14 | int current_width = view->width; | ||
15 | view->desired_width = new_dimension; | ||
16 | floating_view_sane_size(view); | ||
17 | |||
18 | int new_x = view->x + (int)(((view->desired_width - current_width) / 2) * -1); | ||
19 | view->width = view->desired_width; | ||
20 | view->x = new_x; | ||
21 | |||
22 | update_geometry(view); | ||
23 | } else { | ||
24 | int current_height = view->height; | ||
25 | view->desired_height = new_dimension; | ||
26 | floating_view_sane_size(view); | ||
27 | |||
28 | int new_y = view->y + (int)(((view->desired_height - current_height) / 2) * -1); | ||
29 | view->height = view->desired_height; | ||
30 | view->y = new_y; | ||
31 | |||
32 | update_geometry(view); | ||
33 | } | ||
34 | |||
35 | return true; | ||
36 | } | ||
37 | |||
38 | return false; | ||
39 | } | ||
40 | |||
41 | static bool resize_floating(int amount, bool use_width) { | ||
42 | swayc_t *view = get_focused_float(swayc_active_workspace()); | ||
43 | |||
44 | if (view) { | ||
45 | if (use_width) { | ||
46 | return set_size_floating(view->width + amount, true); | ||
47 | } else { | ||
48 | return set_size_floating(view->height + amount, false); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | return false; | ||
53 | } | ||
54 | |||
55 | static bool resize_tiled(int amount, bool use_width) { | ||
56 | swayc_t *parent = get_focused_view(swayc_active_workspace()); | ||
57 | swayc_t *focused = parent; | ||
58 | swayc_t *sibling; | ||
59 | if (!parent) { | ||
60 | return true; | ||
61 | } | ||
62 | // Find the closest parent container which has siblings of the proper layout. | ||
63 | // Then apply the resize to all of them. | ||
64 | int i; | ||
65 | if (use_width) { | ||
66 | int lnumber = 0; | ||
67 | int rnumber = 0; | ||
68 | while (parent->parent) { | ||
69 | if (parent->parent->layout == L_HORIZ && parent->parent->children) { | ||
70 | for (i = 0; i < parent->parent->children->length; i++) { | ||
71 | sibling = parent->parent->children->items[i]; | ||
72 | if (sibling->x != focused->x) { | ||
73 | if (sibling->x < parent->x) { | ||
74 | lnumber++; | ||
75 | } else if (sibling->x > parent->x) { | ||
76 | rnumber++; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | if (rnumber || lnumber) { | ||
81 | break; | ||
82 | } | ||
83 | } | ||
84 | parent = parent->parent; | ||
85 | } | ||
86 | if (parent == &root_container) { | ||
87 | return true; | ||
88 | } | ||
89 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); | ||
90 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
91 | bool valid = true; | ||
92 | for (i = 0; i < parent->parent->children->length; i++) { | ||
93 | sibling = parent->parent->children->items[i]; | ||
94 | if (sibling->x != focused->x) { | ||
95 | if (sibling->x < parent->x) { | ||
96 | double pixels = -1 * amount; | ||
97 | pixels /= lnumber; | ||
98 | if (rnumber) { | ||
99 | if ((sibling->width + pixels/2) < min_sane_w) { | ||
100 | valid = false; | ||
101 | break; | ||
102 | } | ||
103 | } else { | ||
104 | if ((sibling->width + pixels) < min_sane_w) { | ||
105 | valid = false; | ||
106 | break; | ||
107 | } | ||
108 | } | ||
109 | } else if (sibling->x > parent->x) { | ||
110 | double pixels = -1 * amount; | ||
111 | pixels /= rnumber; | ||
112 | if (lnumber) { | ||
113 | if ((sibling->width + pixels/2) < min_sane_w) { | ||
114 | valid = false; | ||
115 | break; | ||
116 | } | ||
117 | } else { | ||
118 | if ((sibling->width + pixels) < min_sane_w) { | ||
119 | valid = false; | ||
120 | break; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } else { | ||
125 | double pixels = amount; | ||
126 | if (parent->width + pixels < min_sane_w) { | ||
127 | valid = false; | ||
128 | break; | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | if (valid) { | ||
133 | for (i = 0; i < parent->parent->children->length; i++) { | ||
134 | sibling = parent->parent->children->items[i]; | ||
135 | if (sibling->x != focused->x) { | ||
136 | if (sibling->x < parent->x) { | ||
137 | double pixels = -1 * amount; | ||
138 | pixels /= lnumber; | ||
139 | if (rnumber) { | ||
140 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT); | ||
141 | } else { | ||
142 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
143 | } | ||
144 | } else if (sibling->x > parent->x) { | ||
145 | double pixels = -1 * amount; | ||
146 | pixels /= rnumber; | ||
147 | if (lnumber) { | ||
148 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT); | ||
149 | } else { | ||
150 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT); | ||
151 | } | ||
152 | } | ||
153 | } else { | ||
154 | if (rnumber != 0 && lnumber != 0) { | ||
155 | double pixels = amount; | ||
156 | pixels /= 2; | ||
157 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT); | ||
158 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT); | ||
159 | } else if (rnumber) { | ||
160 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT); | ||
161 | } else if (lnumber) { | ||
162 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT); | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | // Recursive resize does not handle positions, let arrange_windows | ||
167 | // take care of that. | ||
168 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
169 | } | ||
170 | return true; | ||
171 | } else { | ||
172 | int tnumber = 0; | ||
173 | int bnumber = 0; | ||
174 | while (parent->parent) { | ||
175 | if (parent->parent->layout == L_VERT) { | ||
176 | for (i = 0; i < parent->parent->children->length; i++) { | ||
177 | sibling = parent->parent->children->items[i]; | ||
178 | if (sibling->y != focused->y) { | ||
179 | if (sibling->y < parent->y) { | ||
180 | bnumber++; | ||
181 | } else if (sibling->y > parent->y) { | ||
182 | tnumber++; | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | if (bnumber || tnumber) { | ||
187 | break; | ||
188 | } | ||
189 | } | ||
190 | parent = parent->parent; | ||
191 | } | ||
192 | if (parent->parent == NULL || parent->parent->children == NULL) { | ||
193 | return true; | ||
194 | } | ||
195 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); | ||
196 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
197 | bool valid = true; | ||
198 | for (i = 0; i < parent->parent->children->length; i++) { | ||
199 | sibling = parent->parent->children->items[i]; | ||
200 | if (sibling->y != focused->y) { | ||
201 | if (sibling->y < parent->y) { | ||
202 | double pixels = -1 * amount; | ||
203 | pixels /= bnumber; | ||
204 | if (tnumber) { | ||
205 | if ((sibling->height + pixels/2) < min_sane_h) { | ||
206 | valid = false; | ||
207 | break; | ||
208 | } | ||
209 | } else { | ||
210 | if ((sibling->height + pixels) < min_sane_h) { | ||
211 | valid = false; | ||
212 | break; | ||
213 | } | ||
214 | } | ||
215 | } else if (sibling->y > parent->y) { | ||
216 | double pixels = -1 * amount; | ||
217 | pixels /= tnumber; | ||
218 | if (bnumber) { | ||
219 | if ((sibling->height + pixels/2) < min_sane_h) { | ||
220 | valid = false; | ||
221 | break; | ||
222 | } | ||
223 | } else { | ||
224 | if ((sibling->height + pixels) < min_sane_h) { | ||
225 | valid = false; | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | } else { | ||
231 | double pixels = amount; | ||
232 | if (parent->height + pixels < min_sane_h) { | ||
233 | valid = false; | ||
234 | break; | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | if (valid) { | ||
239 | for (i = 0; i < parent->parent->children->length; i++) { | ||
240 | sibling = parent->parent->children->items[i]; | ||
241 | if (sibling->y != focused->y) { | ||
242 | if (sibling->y < parent->y) { | ||
243 | double pixels = -1 * amount; | ||
244 | pixels /= bnumber; | ||
245 | if (tnumber) { | ||
246 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM); | ||
247 | } else { | ||
248 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
249 | } | ||
250 | } else if (sibling->x > parent->x) { | ||
251 | double pixels = -1 * amount; | ||
252 | pixels /= tnumber; | ||
253 | if (bnumber) { | ||
254 | recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP); | ||
255 | } else { | ||
256 | recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP); | ||
257 | } | ||
258 | } | ||
259 | } else { | ||
260 | if (bnumber != 0 && tnumber != 0) { | ||
261 | double pixels = amount/2; | ||
262 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP); | ||
263 | recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM); | ||
264 | } else if (tnumber) { | ||
265 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP); | ||
266 | } else if (bnumber) { | ||
267 | recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM); | ||
268 | } | ||
269 | } | ||
270 | } | ||
271 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
272 | } | ||
273 | return true; | ||
274 | } | ||
275 | return true; | ||
276 | } | ||
277 | |||
278 | static bool set_size_tiled(int amount, bool use_width) { | ||
279 | int desired; | ||
280 | swayc_t *focused = get_focused_view(swayc_active_workspace()); | ||
281 | |||
282 | if (use_width) { | ||
283 | desired = amount - focused->width; | ||
284 | } else { | ||
285 | desired = amount - focused->height; | ||
286 | } | ||
287 | |||
288 | return resize_tiled(desired, use_width); | ||
289 | } | ||
290 | |||
291 | bool set_size(int dimension, bool use_width) { | ||
292 | swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace()); | ||
293 | |||
294 | if (focused) { | ||
295 | if (focused->is_floating) { | ||
296 | return set_size_floating(dimension, use_width); | ||
297 | } else { | ||
298 | return set_size_tiled(dimension, use_width); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | return false; | ||
303 | } | ||
304 | |||
305 | bool resize(int dimension, bool use_width, enum resize_dim_types dim_type) { | ||
306 | swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace()); | ||
307 | |||
308 | // translate "10 ppt" (10%) to appropriate # of pixels in case we need it | ||
309 | float ppt_dim = (float)dimension / 100; | ||
310 | |||
311 | if (use_width) { | ||
312 | ppt_dim = focused->width * ppt_dim; | ||
313 | } else { | ||
314 | ppt_dim = focused->height * ppt_dim; | ||
315 | } | ||
316 | |||
317 | if (focused) { | ||
318 | if (focused->is_floating) { | ||
319 | // floating view resize dimensions should default to px, so only | ||
320 | // use ppt if specified | ||
321 | if (dim_type == RESIZE_DIM_PPT) { | ||
322 | dimension = (int)ppt_dim; | ||
323 | } | ||
324 | |||
325 | return resize_floating(dimension, use_width); | ||
326 | } else { | ||
327 | // tiled view resize dimensions should default to ppt, so only use | ||
328 | // px if specified | ||
329 | if (dim_type != RESIZE_DIM_PX) { | ||
330 | dimension = (int)ppt_dim; | ||
331 | } | ||
332 | |||
333 | return resize_tiled(dimension, use_width); | ||
334 | } | ||
335 | } | ||
336 | |||
337 | return false; | ||
338 | } | ||