aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seatop_down.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/seatop_down.c')
-rw-r--r--sway/input/seatop_down.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c
index cc54b90b..ecc34fea 100644
--- a/sway/input/seatop_down.c
+++ b/sway/input/seatop_down.c
@@ -10,8 +10,10 @@
10 10
11struct seatop_down_event { 11struct seatop_down_event {
12 struct sway_container *con; 12 struct sway_container *con;
13 struct sway_seat *seat;
14 struct wl_listener surface_destroy;
13 struct wlr_surface *surface; 15 struct wlr_surface *surface;
14 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
15 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
16}; 18};
17 19
@@ -71,6 +73,14 @@ static void handle_tablet_tool_motion(struct sway_seat *seat,
71 } 73 }
72} 74}
73 75
76static 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
74static void handle_unref(struct sway_seat *seat, struct sway_container *con) { 84static 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
91static 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
81static const struct sway_seatop_impl seatop_impl = { 96static 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,33 +100,21 @@ 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
91void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, 107void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
92 uint32_t time_msec, double sx, double sy) { 108 uint32_t time_msec, double sx, double sy) {
93 seatop_end(seat); 109 seatop_begin_down_on_surface(seat, con->view->surface, time_msec, sx, sy);
94 110 struct seatop_down_event *e = seat->seatop_data;
95 struct seatop_down_event *e =
96 calloc(1, sizeof(struct seatop_down_event));
97 if (!e) {
98 return;
99 }
100 e->con = con; 111 e->con = con;
101 e->surface = con->view->surface;
102 e->ref_lx = seat->cursor->cursor->x;
103 e->ref_ly = seat->cursor->cursor->y;
104 e->ref_con_lx = sx;
105 e->ref_con_ly = sy;
106
107 seat->seatop_impl = &seatop_impl;
108 seat->seatop_data = e;
109 112
110 container_raise_floating(con); 113 container_raise_floating(con);
111 transaction_commit_dirty(); 114 transaction_commit_dirty();
112} 115}
113 116
114void seatop_begin_down_on_layer_surface(struct sway_seat *seat, 117void seatop_begin_down_on_surface(struct sway_seat *seat,
115 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) { 118 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) {
116 seatop_end(seat); 119 seatop_end(seat);
117 120
@@ -121,7 +124,10 @@ void seatop_begin_down_on_layer_surface(struct sway_seat *seat,
121 return; 124 return;
122 } 125 }
123 e->con = NULL; 126 e->con = NULL;
127 e->seat = seat;
124 e->surface = surface; 128 e->surface = surface;
129 wl_signal_add(&e->surface->events.destroy, &e->surface_destroy);
130 e->surface_destroy.notify = handle_destroy;
125 e->ref_lx = seat->cursor->cursor->x; 131 e->ref_lx = seat->cursor->cursor->x;
126 e->ref_ly = seat->cursor->cursor->y; 132 e->ref_ly = seat->cursor->cursor->y;
127 e->ref_con_lx = sx; 133 e->ref_con_lx = sx;