diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2019-01-10 22:04:42 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2019-01-10 22:04:42 +1000 |
commit | ed5aafd90bd850ad27dcb36ac4438ed926480394 (patch) | |
tree | 46d0b5fe8488e5d9415cbc9a732e86c1e7100ffe /sway/input/seatop_move_floating.c | |
parent | Merge pull request #3341 from RedSoxFan/mouse-bindings-improved (diff) | |
download | sway-ed5aafd90bd850ad27dcb36ac4438ed926480394.tar.gz sway-ed5aafd90bd850ad27dcb36ac4438ed926480394.tar.zst sway-ed5aafd90bd850ad27dcb36ac4438ed926480394.zip |
Refactor seat operations to use an interface
This splits each seat operation (drag/move tiling/floating etc) into a
separate file and introduces a struct sway_seatop_impl to abstract the
operation.
The move_tiling_threshold operation has been merged into move_tiling.
The main logic for each operation is untouched aside from variable
renames.
The following previously-static functions have been made public:
* node_at_coords
* container_raise_floating
* render_rect
* premultiply_alpha
* scale_box
Diffstat (limited to 'sway/input/seatop_move_floating.c')
-rw-r--r-- | sway/input/seatop_move_floating.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/input/seatop_move_floating.c b/sway/input/seatop_move_floating.c new file mode 100644 index 00000000..08e3a5a4 --- /dev/null +++ b/sway/input/seatop_move_floating.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <wlr/types/wlr_cursor.h> | ||
3 | #include "sway/desktop.h" | ||
4 | #include "sway/input/cursor.h" | ||
5 | #include "sway/input/seat.h" | ||
6 | |||
7 | struct seatop_move_floating_event { | ||
8 | struct sway_container *con; | ||
9 | }; | ||
10 | |||
11 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | ||
12 | struct seatop_move_floating_event *e = seat->seatop_data; | ||
13 | desktop_damage_whole_container(e->con); | ||
14 | container_floating_translate(e->con, | ||
15 | seat->cursor->cursor->x - seat->cursor->previous.x, | ||
16 | seat->cursor->cursor->y - seat->cursor->previous.y); | ||
17 | desktop_damage_whole_container(e->con); | ||
18 | } | ||
19 | |||
20 | static void handle_finish(struct sway_seat *seat) { | ||
21 | struct seatop_move_floating_event *e = seat->seatop_data; | ||
22 | |||
23 | // We "move" the container to its own location | ||
24 | // so it discovers its output again. | ||
25 | container_floating_move_to(e->con, e->con->x, e->con->y); | ||
26 | cursor_set_image(seat->cursor, "left_ptr", NULL); | ||
27 | } | ||
28 | |||
29 | static void handle_abort(struct sway_seat *seat) { | ||
30 | cursor_set_image(seat->cursor, "left_ptr", NULL); | ||
31 | } | ||
32 | |||
33 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { | ||
34 | struct seatop_move_floating_event *e = seat->seatop_data; | ||
35 | if (e->con == con) { | ||
36 | seatop_abort(seat); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | static const struct sway_seatop_impl seatop_impl = { | ||
41 | .motion = handle_motion, | ||
42 | .finish = handle_finish, | ||
43 | .abort = handle_abort, | ||
44 | .unref = handle_unref, | ||
45 | }; | ||
46 | |||
47 | void seatop_begin_move_floating(struct sway_seat *seat, | ||
48 | struct sway_container *con, uint32_t button) { | ||
49 | seatop_abort(seat); | ||
50 | |||
51 | struct seatop_move_floating_event *e = | ||
52 | calloc(1, sizeof(struct seatop_move_floating_event)); | ||
53 | if (!e) { | ||
54 | return; | ||
55 | } | ||
56 | e->con = con; | ||
57 | |||
58 | seat->seatop_impl = &seatop_impl; | ||
59 | seat->seatop_data = e; | ||
60 | seat->seatop_button = button; | ||
61 | |||
62 | container_raise_floating(con); | ||
63 | |||
64 | cursor_set_image(seat->cursor, "grab", NULL); | ||
65 | } | ||