diff options
Diffstat (limited to 'sway/input/seatop_down.c')
-rw-r--r-- | sway/input/seatop_down.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c index 17f619e3..ecc34fea 100644 --- a/sway/input/seatop_down.c +++ b/sway/input/seatop_down.c | |||
@@ -5,10 +5,14 @@ | |||
5 | #include "sway/input/cursor.h" | 5 | #include "sway/input/cursor.h" |
6 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
7 | #include "sway/tree/view.h" | 7 | #include "sway/tree/view.h" |
8 | #include "sway/desktop/transaction.h" | ||
8 | #include "log.h" | 9 | #include "log.h" |
9 | 10 | ||
10 | struct seatop_down_event { | 11 | struct seatop_down_event { |
11 | struct sway_container *con; | 12 | struct sway_container *con; |
13 | struct sway_seat *seat; | ||
14 | struct wl_listener surface_destroy; | ||
15 | struct wlr_surface *surface; | ||
12 | double ref_lx, ref_ly; // cursor's x/y at start of op | 16 | double ref_lx, ref_ly; // cursor's x/y at start of op |
13 | double ref_con_lx, ref_con_ly; // container's x/y at start of op | 17 | double ref_con_lx, ref_con_ly; // container's x/y at start of op |
14 | }; | 18 | }; |
@@ -39,8 +43,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, | |||
39 | 43 | ||
40 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { | 44 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { |
41 | struct seatop_down_event *e = seat->seatop_data; | 45 | struct seatop_down_event *e = seat->seatop_data; |
42 | struct sway_container *con = e->con; | 46 | if (seat_is_input_allowed(seat, e->surface)) { |
43 | if (seat_is_input_allowed(seat, con->view->surface)) { | ||
44 | double moved_x = seat->cursor->cursor->x - e->ref_lx; | 47 | double moved_x = seat->cursor->cursor->x - e->ref_lx; |
45 | double moved_y = seat->cursor->cursor->y - e->ref_ly; | 48 | double moved_y = seat->cursor->cursor->y - e->ref_ly; |
46 | double sx = e->ref_con_lx + moved_x; | 49 | double sx = e->ref_con_lx + moved_x; |
@@ -61,8 +64,7 @@ static void handle_tablet_tool_tip(struct sway_seat *seat, | |||
61 | static void handle_tablet_tool_motion(struct sway_seat *seat, | 64 | static void handle_tablet_tool_motion(struct sway_seat *seat, |
62 | struct sway_tablet_tool *tool, uint32_t time_msec) { | 65 | struct sway_tablet_tool *tool, uint32_t time_msec) { |
63 | struct seatop_down_event *e = seat->seatop_data; | 66 | struct seatop_down_event *e = seat->seatop_data; |
64 | struct sway_container *con = e->con; | 67 | if (seat_is_input_allowed(seat, e->surface)) { |
65 | if (seat_is_input_allowed(seat, con->view->surface)) { | ||
66 | double moved_x = seat->cursor->cursor->x - e->ref_lx; | 68 | double moved_x = seat->cursor->cursor->x - e->ref_lx; |
67 | double moved_y = seat->cursor->cursor->y - e->ref_ly; | 69 | double moved_y = seat->cursor->cursor->y - e->ref_ly; |
68 | double sx = e->ref_con_lx + moved_x; | 70 | double sx = e->ref_con_lx + moved_x; |
@@ -71,6 +73,14 @@ static void handle_tablet_tool_motion(struct sway_seat *seat, | |||
71 | } | 73 | } |
72 | } | 74 | } |
73 | 75 | ||
76 | static void handle_destroy(struct wl_listener *listener, void *data) { | ||
77 | struct seatop_down_event *e = | ||
78 | wl_container_of(listener, e, surface_destroy); | ||
79 | if (e) { | ||
80 | seatop_begin_default(e->seat); | ||
81 | } | ||
82 | } | ||
83 | |||
74 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { | 84 | static void handle_unref(struct sway_seat *seat, struct sway_container *con) { |
75 | struct seatop_down_event *e = seat->seatop_data; | 85 | struct seatop_down_event *e = seat->seatop_data; |
76 | if (e->con == con) { | 86 | if (e->con == con) { |
@@ -78,6 +88,11 @@ static void handle_unref(struct sway_seat *seat, struct sway_container *con) { | |||
78 | } | 88 | } |
79 | } | 89 | } |
80 | 90 | ||
91 | static void handle_end(struct sway_seat *seat) { | ||
92 | struct seatop_down_event *e = seat->seatop_data; | ||
93 | wl_list_remove(&e->surface_destroy.link); | ||
94 | } | ||
95 | |||
81 | static const struct sway_seatop_impl seatop_impl = { | 96 | static const struct sway_seatop_impl seatop_impl = { |
82 | .button = handle_button, | 97 | .button = handle_button, |
83 | .pointer_motion = handle_pointer_motion, | 98 | .pointer_motion = handle_pointer_motion, |
@@ -85,11 +100,22 @@ static const struct sway_seatop_impl seatop_impl = { | |||
85 | .tablet_tool_tip = handle_tablet_tool_tip, | 100 | .tablet_tool_tip = handle_tablet_tool_tip, |
86 | .tablet_tool_motion = handle_tablet_tool_motion, | 101 | .tablet_tool_motion = handle_tablet_tool_motion, |
87 | .unref = handle_unref, | 102 | .unref = handle_unref, |
103 | .end = handle_end, | ||
88 | .allow_set_cursor = true, | 104 | .allow_set_cursor = true, |
89 | }; | 105 | }; |
90 | 106 | ||
91 | void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, | 107 | void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, |
92 | uint32_t time_msec, int sx, int sy) { | 108 | uint32_t time_msec, double sx, double sy) { |
109 | seatop_begin_down_on_surface(seat, con->view->surface, time_msec, sx, sy); | ||
110 | struct seatop_down_event *e = seat->seatop_data; | ||
111 | e->con = con; | ||
112 | |||
113 | container_raise_floating(con); | ||
114 | transaction_commit_dirty(); | ||
115 | } | ||
116 | |||
117 | void seatop_begin_down_on_surface(struct sway_seat *seat, | ||
118 | struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) { | ||
93 | seatop_end(seat); | 119 | seatop_end(seat); |
94 | 120 | ||
95 | struct seatop_down_event *e = | 121 | struct seatop_down_event *e = |
@@ -97,7 +123,11 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, | |||
97 | if (!e) { | 123 | if (!e) { |
98 | return; | 124 | return; |
99 | } | 125 | } |
100 | e->con = con; | 126 | e->con = NULL; |
127 | e->seat = seat; | ||
128 | e->surface = surface; | ||
129 | wl_signal_add(&e->surface->events.destroy, &e->surface_destroy); | ||
130 | e->surface_destroy.notify = handle_destroy; | ||
101 | e->ref_lx = seat->cursor->cursor->x; | 131 | e->ref_lx = seat->cursor->cursor->x; |
102 | e->ref_ly = seat->cursor->cursor->y; | 132 | e->ref_ly = seat->cursor->cursor->y; |
103 | e->ref_con_lx = sx; | 133 | e->ref_con_lx = sx; |
@@ -105,6 +135,4 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, | |||
105 | 135 | ||
106 | seat->seatop_impl = &seatop_impl; | 136 | seat->seatop_impl = &seatop_impl; |
107 | seat->seatop_data = e; | 137 | seat->seatop_data = e; |
108 | |||
109 | container_raise_floating(con); | ||
110 | } | 138 | } |