diff options
Diffstat (limited to 'sway/resize.c')
-rw-r--r-- | sway/resize.c | 112 |
1 files changed, 103 insertions, 9 deletions
diff --git a/sway/resize.c b/sway/resize.c index 9411cfd8..18bb86bb 100644 --- a/sway/resize.c +++ b/sway/resize.c | |||
@@ -7,20 +7,52 @@ | |||
7 | #include "handlers.h" | 7 | #include "handlers.h" |
8 | #include "resize.h" | 8 | #include "resize.h" |
9 | 9 | ||
10 | bool set_size_tiled(int amount, bool use_width) { | 10 | static bool set_size_floating(int new_dimension, bool use_width) { |
11 | int desired; | 11 | swayc_t *view = get_focused_float(swayc_active_workspace()); |
12 | swayc_t *focused = get_focused_view(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); | ||
13 | 17 | ||
14 | if (use_width) { | 18 | int new_x = view->x + (int)(((view->desired_width - current_width) / 2) * -1); |
15 | desired = amount - focused->width; | 19 | view->width = view->desired_width; |
16 | } else { | 20 | view->x = new_x; |
17 | desired = amount - focused->height; | 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; | ||
18 | } | 36 | } |
19 | 37 | ||
20 | return resize_tiled(desired, use_width); | 38 | return false; |
21 | } | 39 | } |
22 | 40 | ||
23 | bool resize_tiled(int amount, bool use_width) { | 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) { | ||
24 | swayc_t *parent = get_focused_view(swayc_active_workspace()); | 56 | swayc_t *parent = get_focused_view(swayc_active_workspace()); |
25 | swayc_t *focused = parent; | 57 | swayc_t *focused = parent; |
26 | swayc_t *sibling; | 58 | swayc_t *sibling; |
@@ -242,3 +274,65 @@ bool resize_tiled(int amount, bool use_width) { | |||
242 | } | 274 | } |
243 | return true; | 275 | return true; |
244 | } | 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 | } | ||