summaryrefslogtreecommitdiffstats
path: root/sway/resize.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/resize.c')
-rw-r--r--sway/resize.c338
1 files changed, 0 insertions, 338 deletions
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
10static 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
41static 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
55static 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
278static 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
291bool 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
305bool 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}