diff options
author | 2019-01-14 21:22:53 +1000 | |
---|---|---|
committer | 2019-01-15 08:01:21 +1000 | |
commit | 2024f1da72d5144a30864d815608e2e856639bf6 (patch) | |
tree | e924279ea83525a67b25367baa68a8fb38116324 /sway/input | |
parent | Disarm key repeat on reload (diff) | |
download | sway-2024f1da72d5144a30864d815608e2e856639bf6.tar.gz sway-2024f1da72d5144a30864d815608e2e856639bf6.tar.zst sway-2024f1da72d5144a30864d815608e2e856639bf6.zip |
Resize only current and immediate siblings rather than all siblings
For example, create layout V[view view view] and resize the leftmost
view using mod+rightclick. Previously, the edge between view 2 and 3
would be adjusted as well. Now this edge will remain constant, which
matches the behaviour of i3.
To do this operation correctly, the resize tiling seatop now keeps track
of two containers, as the container that resizes horizontally will be a
different container to the one which resizes vertically (one will be an
ancestor). The tiling resize seatop now figures out these containers
during the start of the operation and keeps references to them in the
event. A new function container_find_resize_parent has been introduced
to do this. This function is also used by the resize command.
During cursor motion, the seatop logic is similar to before, but now has
to choose the correct container to resize.
In resize.c, container_resize_tiled and resize_tiled have been merged
into one. One of them originally did nothing except pass the values
through to the other.
container_resize_tiled now takes a simplified approach where it just
finds the immediate siblings on either side and resizes them without
worrying about the others. The parellel_coord and parallel_size
functions are no longer needed and have been removed.
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/seatop_resize_tiling.c | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c index 30431f04..cb0f723d 100644 --- a/sway/input/seatop_resize_tiling.c +++ b/sway/input/seatop_resize_tiling.c | |||
@@ -1,15 +1,22 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <wlr/types/wlr_cursor.h> | 2 | #include <wlr/types/wlr_cursor.h> |
3 | #include <wlr/util/edges.h> | ||
3 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
4 | #include "sway/input/cursor.h" | 5 | #include "sway/input/cursor.h" |
5 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
6 | 7 | ||
7 | struct seatop_resize_tiling_event { | 8 | struct seatop_resize_tiling_event { |
8 | struct sway_container *con; | 9 | struct sway_container *con; // leaf container |
10 | |||
11 | // con, or ancestor of con which will be resized horizontally/vertically | ||
12 | struct sway_container *h_con; | ||
13 | struct sway_container *v_con; | ||
14 | |||
9 | enum wlr_edges edge; | 15 | enum wlr_edges edge; |
16 | enum wlr_edges edge_x, edge_y; | ||
10 | double ref_lx, ref_ly; // cursor's x/y at start of op | 17 | double ref_lx, ref_ly; // cursor's x/y at start of op |
11 | double ref_width, ref_height; // container's size at start of op | 18 | double h_con_orig_width; // width of the horizontal ancestor at start |
12 | double ref_con_lx, ref_con_ly; // container's x/y at start of op | 19 | double v_con_orig_height; // height of the vertical ancestor at start |
13 | }; | 20 | }; |
14 | 21 | ||
15 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | 22 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { |
@@ -18,30 +25,27 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | |||
18 | int amount_y = 0; | 25 | int amount_y = 0; |
19 | int moved_x = seat->cursor->cursor->x - e->ref_lx; | 26 | int moved_x = seat->cursor->cursor->x - e->ref_lx; |
20 | int moved_y = seat->cursor->cursor->y - e->ref_ly; | 27 | int moved_y = seat->cursor->cursor->y - e->ref_ly; |
21 | enum wlr_edges edge_x = WLR_EDGE_NONE; | 28 | |
22 | enum wlr_edges edge_y = WLR_EDGE_NONE; | 29 | if (e->h_con) { |
23 | struct sway_container *con = e->con; | 30 | if (e->edge & WLR_EDGE_LEFT) { |
24 | 31 | amount_x = (e->h_con_orig_width - moved_x) - e->h_con->width; | |
25 | if (e->edge & WLR_EDGE_TOP) { | 32 | } else if (e->edge & WLR_EDGE_RIGHT) { |
26 | amount_y = (e->ref_height - moved_y) - con->height; | 33 | amount_x = (e->h_con_orig_width + moved_x) - e->h_con->width; |
27 | edge_y = WLR_EDGE_TOP; | 34 | } |
28 | } else if (e->edge & WLR_EDGE_BOTTOM) { | ||
29 | amount_y = (e->ref_height + moved_y) - con->height; | ||
30 | edge_y = WLR_EDGE_BOTTOM; | ||
31 | } | 35 | } |
32 | if (e->edge & WLR_EDGE_LEFT) { | 36 | if (e->v_con) { |
33 | amount_x = (e->ref_width - moved_x) - con->width; | 37 | if (e->edge & WLR_EDGE_TOP) { |
34 | edge_x = WLR_EDGE_LEFT; | 38 | amount_y = (e->v_con_orig_height - moved_y) - e->v_con->height; |
35 | } else if (e->edge & WLR_EDGE_RIGHT) { | 39 | } else if (e->edge & WLR_EDGE_BOTTOM) { |
36 | amount_x = (e->ref_width + moved_x) - con->width; | 40 | amount_y = (e->v_con_orig_height + moved_y) - e->v_con->height; |
37 | edge_x = WLR_EDGE_RIGHT; | 41 | } |
38 | } | 42 | } |
39 | 43 | ||
40 | if (amount_x != 0) { | 44 | if (amount_x != 0) { |
41 | container_resize_tiled(e->con, edge_x, amount_x); | 45 | container_resize_tiled(e->h_con, e->edge_x, amount_x); |
42 | } | 46 | } |
43 | if (amount_y != 0) { | 47 | if (amount_y != 0) { |
44 | container_resize_tiled(e->con, edge_y, amount_y); | 48 | container_resize_tiled(e->v_con, e->edge_y, amount_y); |
45 | } | 49 | } |
46 | } | 50 | } |
47 | 51 | ||
@@ -81,10 +85,23 @@ void seatop_begin_resize_tiling(struct sway_seat *seat, | |||
81 | 85 | ||
82 | e->ref_lx = seat->cursor->cursor->x; | 86 | e->ref_lx = seat->cursor->cursor->x; |
83 | e->ref_ly = seat->cursor->cursor->y; | 87 | e->ref_ly = seat->cursor->cursor->y; |
84 | e->ref_con_lx = con->x; | 88 | |
85 | e->ref_con_ly = con->y; | 89 | if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) { |
86 | e->ref_width = con->width; | 90 | e->edge_x = edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT); |
87 | e->ref_height = con->height; | 91 | e->h_con = container_find_resize_parent(e->con, e->edge_x); |
92 | |||
93 | if (e->h_con) { | ||
94 | e->h_con_orig_width = e->h_con->width; | ||
95 | } | ||
96 | } | ||
97 | if (edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) { | ||
98 | e->edge_y = edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM); | ||
99 | e->v_con = container_find_resize_parent(e->con, e->edge_y); | ||
100 | |||
101 | if (e->v_con) { | ||
102 | e->v_con_orig_height = e->v_con->height; | ||
103 | } | ||
104 | } | ||
88 | 105 | ||
89 | seat->seatop_impl = &seatop_impl; | 106 | seat->seatop_impl = &seatop_impl; |
90 | seat->seatop_data = e; | 107 | seat->seatop_data = e; |