diff options
Diffstat (limited to 'sway/input/seatop_down.c')
-rw-r--r-- | sway/input/seatop_down.c | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c index fb2cf1d0..95ea7cbb 100644 --- a/sway/input/seatop_down.c +++ b/sway/input/seatop_down.c | |||
@@ -3,21 +3,26 @@ | |||
3 | #include "sway/input/cursor.h" | 3 | #include "sway/input/cursor.h" |
4 | #include "sway/input/seat.h" | 4 | #include "sway/input/seat.h" |
5 | #include "sway/tree/view.h" | 5 | #include "sway/tree/view.h" |
6 | #include "log.h" | ||
6 | 7 | ||
7 | struct seatop_down_event { | 8 | struct seatop_down_event { |
8 | struct sway_container *con; | 9 | struct sway_container *con; |
9 | double ref_lx, ref_ly; // cursor's x/y at start of op | 10 | double ref_lx, ref_ly; // cursor's x/y at start of op |
10 | double ref_con_lx, ref_con_ly; // container's x/y at start of op | 11 | double ref_con_lx, ref_con_ly; // container's x/y at start of op |
11 | bool moved; | ||
12 | }; | 12 | }; |
13 | 13 | ||
14 | static void handle_button(struct sway_seat *seat, uint32_t time_msec, | 14 | static void handle_button(struct sway_seat *seat, uint32_t time_msec, |
15 | struct wlr_input_device *device, uint32_t button, | 15 | struct wlr_input_device *device, uint32_t button, |
16 | enum wlr_button_state state) { | 16 | enum wlr_button_state state) { |
17 | seat_pointer_notify_button(seat, time_msec, button, state); | 17 | seat_pointer_notify_button(seat, time_msec, button, state); |
18 | |||
19 | if (seat->cursor->pressed_button_count == 0) { | ||
20 | seatop_begin_default(seat); | ||
21 | } | ||
18 | } | 22 | } |
19 | 23 | ||
20 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | 24 | static void handle_motion(struct sway_seat *seat, uint32_t time_msec, |
25 | double dx, double dy) { | ||
21 | struct seatop_down_event *e = seat->seatop_data; | 26 | struct seatop_down_event *e = seat->seatop_data; |
22 | struct sway_container *con = e->con; | 27 | struct sway_container *con = e->con; |
23 | if (seat_is_input_allowed(seat, con->view->surface)) { | 28 | if (seat_is_input_allowed(seat, con->view->surface)) { |
@@ -27,49 +32,25 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { | |||
27 | double sy = e->ref_con_ly + moved_y; | 32 | double sy = e->ref_con_ly + moved_y; |
28 | wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy); | 33 | wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy); |
29 | } | 34 | } |
30 | e->moved = true; | ||
31 | } | ||
32 | |||
33 | static void handle_finish(struct sway_seat *seat, uint32_t time_msec) { | ||
34 | struct seatop_down_event *e = seat->seatop_data; | ||
35 | struct sway_cursor *cursor = seat->cursor; | ||
36 | // Set the cursor's previous coords to the x/y at the start of the | ||
37 | // operation, so the container change will be detected if using | ||
38 | // focus_follows_mouse and the cursor moved off the original container | ||
39 | // during the operation. | ||
40 | cursor->previous.x = e->ref_lx; | ||
41 | cursor->previous.y = e->ref_ly; | ||
42 | if (e->moved) { | ||
43 | struct wlr_surface *surface = NULL; | ||
44 | double sx, sy; | ||
45 | struct sway_node *node = node_at_coords(seat, | ||
46 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | ||
47 | cursor_send_pointer_motion(cursor, 0, node, surface, sx, sy); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static void handle_abort(struct sway_seat *seat) { | ||
52 | cursor_set_image(seat->cursor, "left_ptr", NULL); | ||
53 | } | 35 | } |
54 | 36 | ||
55 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { | 37 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { |
56 | struct seatop_down_event *e = seat->seatop_data; | 38 | struct seatop_down_event *e = seat->seatop_data; |
57 | if (e->con == con) { | 39 | if (e->con == con) { |
58 | seatop_abort(seat); | 40 | seatop_begin_default(seat); |
59 | } | 41 | } |
60 | } | 42 | } |
61 | 43 | ||
62 | static const struct sway_seatop_impl seatop_impl = { | 44 | static const struct sway_seatop_impl seatop_impl = { |
63 | .button = handle_button, | 45 | .button = handle_button, |
64 | .motion = handle_motion, | 46 | .motion = handle_motion, |
65 | .finish = handle_finish, | ||
66 | .abort = handle_abort, | ||
67 | .unref = handle_unref, | 47 | .unref = handle_unref, |
48 | .allow_set_cursor = true, | ||
68 | }; | 49 | }; |
69 | 50 | ||
70 | void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, | 51 | void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, |
71 | uint32_t time_msec, uint32_t button, int sx, int sy) { | 52 | uint32_t time_msec, int sx, int sy) { |
72 | seatop_abort(seat); | 53 | seatop_end(seat); |
73 | 54 | ||
74 | struct seatop_down_event *e = | 55 | struct seatop_down_event *e = |
75 | calloc(1, sizeof(struct seatop_down_event)); | 56 | calloc(1, sizeof(struct seatop_down_event)); |
@@ -81,11 +62,9 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, | |||
81 | e->ref_ly = seat->cursor->cursor->y; | 62 | e->ref_ly = seat->cursor->cursor->y; |
82 | e->ref_con_lx = sx; | 63 | e->ref_con_lx = sx; |
83 | e->ref_con_ly = sy; | 64 | e->ref_con_ly = sy; |
84 | e->moved = false; | ||
85 | 65 | ||
86 | seat->seatop_impl = &seatop_impl; | 66 | seat->seatop_impl = &seatop_impl; |
87 | seat->seatop_data = e; | 67 | seat->seatop_data = e; |
88 | seat->seatop_button = button; | ||
89 | 68 | ||
90 | container_raise_floating(con); | 69 | container_raise_floating(con); |
91 | } | 70 | } |