aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-01-10 22:04:42 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-01-10 22:04:42 +1000
commited5aafd90bd850ad27dcb36ac4438ed926480394 (patch)
tree46d0b5fe8488e5d9415cbc9a732e86c1e7100ffe /include
parentMerge pull request #3341 from RedSoxFan/mouse-bindings-improved (diff)
downloadsway-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 'include')
-rw-r--r--include/sway/input/cursor.h6
-rw-r--r--include/sway/input/seat.h83
-rw-r--r--include/sway/output.h8
-rw-r--r--include/sway/tree/container.h2
4 files changed, 67 insertions, 32 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index 4636bf6b..9f699dcd 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -50,6 +50,12 @@ struct sway_cursor {
50 size_t pressed_button_count; 50 size_t pressed_button_count;
51}; 51};
52 52
53struct sway_node;
54
55struct sway_node *node_at_coords(
56 struct sway_seat *seat, double lx, double ly,
57 struct wlr_surface **surface, double *sx, double *sy);
58
53void sway_cursor_destroy(struct sway_cursor *cursor); 59void sway_cursor_destroy(struct sway_cursor *cursor);
54struct sway_cursor *sway_cursor_create(struct sway_seat *seat); 60struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
55 61
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index a3c20346..ce8abde9 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -6,6 +6,17 @@
6#include <wlr/util/edges.h> 6#include <wlr/util/edges.h>
7#include "sway/input/input-manager.h" 7#include "sway/input/input-manager.h"
8 8
9struct sway_seat;
10
11struct sway_seatop_impl {
12 void (*motion)(struct sway_seat *seat, uint32_t time_msec);
13 void (*finish)(struct sway_seat *seat);
14 void (*abort)(struct sway_seat *seat);
15 void (*unref)(struct sway_seat *seat, struct sway_container *con);
16 void (*render)(struct sway_seat *seat, struct sway_output *output,
17 pixman_region32_t *damage);
18};
19
9struct sway_seat_device { 20struct sway_seat_device {
10 struct sway_seat *sway_seat; 21 struct sway_seat *sway_seat;
11 struct sway_input_device *input_device; 22 struct sway_input_device *input_device;
@@ -35,16 +46,6 @@ struct sway_drag_icon {
35 struct wl_listener destroy; 46 struct wl_listener destroy;
36}; 47};
37 48
38enum sway_seat_operation {
39 OP_NONE,
40 OP_DOWN,
41 OP_MOVE_FLOATING,
42 OP_MOVE_TILING_THRESHOLD,
43 OP_MOVE_TILING,
44 OP_RESIZE_FLOATING,
45 OP_RESIZE_TILING,
46};
47
48struct sway_seat { 49struct sway_seat {
49 struct wlr_seat *wlr_seat; 50 struct wlr_seat *wlr_seat;
50 struct sway_cursor *cursor; 51 struct sway_cursor *cursor;
@@ -64,19 +65,10 @@ struct sway_seat {
64 int32_t touch_id; 65 int32_t touch_id;
65 double touch_x, touch_y; 66 double touch_x, touch_y;
66 67
67 // Operations (drag and resize) 68 // Seat operations (drag and resize)
68 enum sway_seat_operation operation; 69 const struct sway_seatop_impl *seatop_impl;
69 struct sway_container *op_container; 70 void *seatop_data;
70 struct sway_node *op_target_node; // target for tiling move 71 uint32_t seatop_button;
71 enum wlr_edges op_target_edge;
72 struct wlr_box op_drop_box;
73 enum wlr_edges op_resize_edge;
74 uint32_t op_button;
75 bool op_resize_preserve_ratio;
76 double op_ref_lx, op_ref_ly; // cursor's x/y at start of op
77 double op_ref_width, op_ref_height; // container's size at start of op
78 double op_ref_con_lx, op_ref_con_ly; // container's x/y at start of op
79 bool op_moved; // if the mouse moved during a down op
80 72
81 uint32_t last_button; 73 uint32_t last_button;
82 uint32_t last_button_serial; 74 uint32_t last_button_serial;
@@ -181,32 +173,59 @@ bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface);
181 173
182void drag_icon_update_position(struct sway_drag_icon *icon); 174void drag_icon_update_position(struct sway_drag_icon *icon);
183 175
184void seat_begin_down(struct sway_seat *seat, struct sway_container *con, 176void seatop_begin_down(struct sway_seat *seat,
185 uint32_t button, double sx, double sy); 177 struct sway_container *con, uint32_t button, int sx, int sy);
186 178
187void seat_begin_move_floating(struct sway_seat *seat, 179void seatop_begin_move_floating(struct sway_seat *seat,
188 struct sway_container *con, uint32_t button); 180 struct sway_container *con, uint32_t button);
189 181
190void seat_begin_move_tiling_threshold(struct sway_seat *seat, 182void seatop_begin_move_tiling_threshold(struct sway_seat *seat,
191 struct sway_container *con, uint32_t button); 183 struct sway_container *con, uint32_t button);
192 184
193void seat_begin_move_tiling(struct sway_seat *seat, 185void seatop_begin_move_tiling(struct sway_seat *seat,
194 struct sway_container *con, uint32_t button); 186 struct sway_container *con, uint32_t button);
195 187
196void seat_begin_resize_floating(struct sway_seat *seat, 188void seatop_begin_resize_floating(struct sway_seat *seat,
197 struct sway_container *con, uint32_t button, enum wlr_edges edge); 189 struct sway_container *con, uint32_t button, enum wlr_edges edge);
198 190
199void seat_begin_resize_tiling(struct sway_seat *seat, 191void seatop_begin_resize_tiling(struct sway_seat *seat,
200 struct sway_container *con, uint32_t button, enum wlr_edges edge); 192 struct sway_container *con, uint32_t button, enum wlr_edges edge);
201 193
202struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, 194struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat,
203 struct sway_workspace *workspace); 195 struct sway_workspace *workspace);
204 196
205void seat_end_mouse_operation(struct sway_seat *seat);
206
207void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec, 197void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec,
208 uint32_t button, enum wlr_button_state state); 198 uint32_t button, enum wlr_button_state state);
209 199
210void seat_consider_warp_to_focus(struct sway_seat *seat); 200void seat_consider_warp_to_focus(struct sway_seat *seat);
211 201
202bool seat_doing_seatop(struct sway_seat *seat);
203
204void seatop_motion(struct sway_seat *seat, uint32_t time_msec);
205
206/**
207 * End a seatop and apply the affects.
208 */
209void seatop_finish(struct sway_seat *seat);
210
211/**
212 * End a seatop without applying the affects.
213 */
214void seatop_abort(struct sway_seat *seat);
215
216/**
217 * Instructs the seatop implementation to drop any references to the given
218 * container (eg. because the container is destroying).
219 * The seatop may choose to abort itself in response to this.
220 */
221void seatop_unref(struct sway_seat *seat, struct sway_container *con);
222
223/**
224 * Instructs a seatop to render anything that it needs to render
225 * (eg. dropzone for move-tiling)
226 */
227void seatop_render(struct sway_seat *seat, struct sway_output *output,
228 pixman_region32_t *damage);
229
230
212#endif 231#endif
diff --git a/include/sway/output.h b/include/sway/output.h
index f7c5ceba..bdf9614d 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -146,4 +146,12 @@ enum sway_container_layout output_get_default_layout(
146 146
147void output_add_listeners(struct sway_output *output); 147void output_add_listeners(struct sway_output *output);
148 148
149void render_rect(struct wlr_output *wlr_output,
150 pixman_region32_t *output_damage, const struct wlr_box *_box,
151 float color[static 4]);
152
153void premultiply_alpha(float color[4], float opacity);
154
155void scale_box(struct wlr_box *box, float scale);
156
149#endif 157#endif
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 1d0a0ad1..9a432cb2 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -333,4 +333,6 @@ void container_add_mark(struct sway_container *container, char *mark);
333 333
334void container_update_marks_textures(struct sway_container *container); 334void container_update_marks_textures(struct sway_container *container);
335 335
336void container_raise_floating(struct sway_container *con);
337
336#endif 338#endif