diff options
Diffstat (limited to 'sway/input/seatop_resize_tiling.c')
-rw-r--r-- | sway/input/seatop_resize_tiling.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c new file mode 100644 index 00000000..30431f04 --- /dev/null +++ b/sway/input/seatop_resize_tiling.c | |||
@@ -0,0 +1,92 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <wlr/types/wlr_cursor.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/cursor.h" | ||
5 | #include "sway/input/seat.h" | ||
6 | |||
7 | struct seatop_resize_tiling_event { | ||
8 | struct sway_container *con; | ||
9 | enum wlr_edges edge; | ||
10 | 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 | ||
12 | double ref_con_lx, ref_con_ly; // container's x/y at start of op | ||
13 | }; | ||
14 | |||
15 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | ||
16 | struct seatop_resize_tiling_event *e = seat->seatop_data; | ||
17 | int amount_x = 0; | ||
18 | int amount_y = 0; | ||
19 | int moved_x = seat->cursor->cursor->x - e->ref_lx; | ||
20 | int moved_y = seat->cursor->cursor->y - e->ref_ly; | ||
21 | enum wlr_edges edge_x = WLR_EDGE_NONE; | ||
22 | enum wlr_edges edge_y = WLR_EDGE_NONE; | ||
23 | struct sway_container *con = e->con; | ||
24 | |||
25 | if (e->edge & WLR_EDGE_TOP) { | ||
26 | amount_y = (e->ref_height - moved_y) - con->height; | ||
27 | edge_y = WLR_EDGE_TOP; | ||
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 | } | ||
32 | if (e->edge & WLR_EDGE_LEFT) { | ||
33 | amount_x = (e->ref_width - moved_x) - con->width; | ||
34 | edge_x = WLR_EDGE_LEFT; | ||
35 | } else if (e->edge & WLR_EDGE_RIGHT) { | ||
36 | amount_x = (e->ref_width + moved_x) - con->width; | ||
37 | edge_x = WLR_EDGE_RIGHT; | ||
38 | } | ||
39 | |||
40 | if (amount_x != 0) { | ||
41 | container_resize_tiled(e->con, edge_x, amount_x); | ||
42 | } | ||
43 | if (amount_y != 0) { | ||
44 | container_resize_tiled(e->con, edge_y, amount_y); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | static void handle_finish(struct sway_seat *seat) { | ||
49 | cursor_set_image(seat->cursor, "left_ptr", NULL); | ||
50 | } | ||
51 | |||
52 | static void handle_abort(struct sway_seat *seat) { | ||
53 | cursor_set_image(seat->cursor, "left_ptr", NULL); | ||
54 | } | ||
55 | |||
56 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { | ||
57 | struct seatop_resize_tiling_event *e = seat->seatop_data; | ||
58 | if (e->con == con) { | ||
59 | seatop_abort(seat); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | static const struct sway_seatop_impl seatop_impl = { | ||
64 | .motion = handle_motion, | ||
65 | .finish = handle_finish, | ||
66 | .abort = handle_abort, | ||
67 | .unref = handle_unref, | ||
68 | }; | ||
69 | |||
70 | void seatop_begin_resize_tiling(struct sway_seat *seat, | ||
71 | struct sway_container *con, uint32_t button, enum wlr_edges edge) { | ||
72 | seatop_abort(seat); | ||
73 | |||
74 | struct seatop_resize_tiling_event *e = | ||
75 | calloc(1, sizeof(struct seatop_resize_tiling_event)); | ||
76 | if (!e) { | ||
77 | return; | ||
78 | } | ||
79 | e->con = con; | ||
80 | e->edge = edge; | ||
81 | |||
82 | e->ref_lx = seat->cursor->cursor->x; | ||
83 | e->ref_ly = seat->cursor->cursor->y; | ||
84 | e->ref_con_lx = con->x; | ||
85 | e->ref_con_ly = con->y; | ||
86 | e->ref_width = con->width; | ||
87 | e->ref_height = con->height; | ||
88 | |||
89 | seat->seatop_impl = &seatop_impl; | ||
90 | seat->seatop_data = e; | ||
91 | seat->seatop_button = button; | ||
92 | } | ||