aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seatop_resize_tiling.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-03-16 17:47:39 +1000
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-03-17 10:02:04 -0600
commit7b9ae42331e49fea0f566fa7592855dee5da1991 (patch)
treeba03e7826af566f871580cd2a1ec344013cebd4f /sway/input/seatop_resize_tiling.c
parentReplace seatup allows_events with button callback (diff)
downloadsway-7b9ae42331e49fea0f566fa7592855dee5da1991.tar.gz
sway-7b9ae42331e49fea0f566fa7592855dee5da1991.tar.zst
sway-7b9ae42331e49fea0f566fa7592855dee5da1991.zip
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse buttons are being held. This means there is now always a seat operation in progress. It allows us to separate `default` code from the standard cursor management code. The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and `end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are only used by the default seatop. `end` is called when a seatop is being replaced by another one and allows the seatop to free any resources, though no seatop currently needs to do this. `finish` is no longer required, as each seatop can gracefully finish in their `button` callback. And `abort` is not needed, as calling `end` would achieve the same thing. The struct has also gained a bool named allow_set_cursor which allows the client to set a new cursor during `default` and `down` seatops. Seatops would previously store which button they were started with and stop when that button was released. This behaviour is changed so that it only ends once all buttons are released. So you can start a drag with $mod+left, then click and hold right, release left and it'll continue dragging while the right button is held. The motion callback now accepts dx and dy. Most seatops don't use this as they store the cursor position when the seatop is started and compare it with the current cursor position. This approach doesn't make sense for the default seatop though, hence why dx and dy are needed. The pressed_buttons array has been moved from the sway_cursor struct to the default seatop's data. This is only used for the default seatop to check bindings. The total pressed button count remains in the sway_cursor struct though, because all the other seatops check it to know if they should end. The `down` seatop no longer has a `moved` property. This was used to track if the cursor moved and to recheck focus_follows_mouse, but seems to work without it. The logic for focus_follows_mouse has been refactored. As part of this I've removed the call to wlr_seat_keyboard_has_grab as we don't appear to use keyboard grabs. The functions for handling relative motion, absolute motion and tool axis have been changed. Previously the handler functions were handle_cursor_motion, handle_cursor_motion_absolute and handle_tool_axis. The latter two both called cursor_motion_absolute. Both handle_cursor_motion and cursor_motion_absolute did very similar things. These are now simplified into three handlers and a single common function called cursor_motion. All three handlers call cursor_motion. As cursor_motion works with relative distances, the absolute and tool axis handlers convert them to relative first.
Diffstat (limited to 'sway/input/seatop_resize_tiling.c')
-rw-r--r--sway/input/seatop_resize_tiling.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c
index db32065c..6b705823 100644
--- a/sway/input/seatop_resize_tiling.c
+++ b/sway/input/seatop_resize_tiling.c
@@ -19,7 +19,16 @@ struct seatop_resize_tiling_event {
19 double v_con_orig_height; // height of the vertical ancestor at start 19 double v_con_orig_height; // height of the vertical ancestor at start
20}; 20};
21 21
22static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { 22static void handle_button(struct sway_seat *seat, uint32_t time_msec,
23 struct wlr_input_device *device, uint32_t button,
24 enum wlr_button_state state) {
25 if (seat->cursor->pressed_button_count == 0) {
26 seatop_begin_default(seat);
27 }
28}
29
30static void handle_motion(struct sway_seat *seat, uint32_t time_msec,
31 double dx, double dy) {
23 struct seatop_resize_tiling_event *e = seat->seatop_data; 32 struct seatop_resize_tiling_event *e = seat->seatop_data;
24 int amount_x = 0; 33 int amount_x = 0;
25 int amount_y = 0; 34 int amount_y = 0;
@@ -49,31 +58,22 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
49 } 58 }
50} 59}
51 60
52static void handle_finish(struct sway_seat *seat, uint32_t time_msec) {
53 cursor_set_image(seat->cursor, "left_ptr", NULL);
54}
55
56static void handle_abort(struct sway_seat *seat) {
57 cursor_set_image(seat->cursor, "left_ptr", NULL);
58}
59
60static void handle_unref(struct sway_seat *seat, struct sway_container *con) { 61static void handle_unref(struct sway_seat *seat, struct sway_container *con) {
61 struct seatop_resize_tiling_event *e = seat->seatop_data; 62 struct seatop_resize_tiling_event *e = seat->seatop_data;
62 if (e->con == con) { 63 if (e->con == con) {
63 seatop_abort(seat); 64 seatop_begin_default(seat);
64 } 65 }
65} 66}
66 67
67static const struct sway_seatop_impl seatop_impl = { 68static const struct sway_seatop_impl seatop_impl = {
69 .button = handle_button,
68 .motion = handle_motion, 70 .motion = handle_motion,
69 .finish = handle_finish,
70 .abort = handle_abort,
71 .unref = handle_unref, 71 .unref = handle_unref,
72}; 72};
73 73
74void seatop_begin_resize_tiling(struct sway_seat *seat, 74void seatop_begin_resize_tiling(struct sway_seat *seat,
75 struct sway_container *con, uint32_t button, enum wlr_edges edge) { 75 struct sway_container *con, enum wlr_edges edge) {
76 seatop_abort(seat); 76 seatop_end(seat);
77 77
78 struct seatop_resize_tiling_event *e = 78 struct seatop_resize_tiling_event *e =
79 calloc(1, sizeof(struct seatop_resize_tiling_event)); 79 calloc(1, sizeof(struct seatop_resize_tiling_event));
@@ -105,5 +105,4 @@ void seatop_begin_resize_tiling(struct sway_seat *seat,
105 105
106 seat->seatop_impl = &seatop_impl; 106 seat->seatop_impl = &seatop_impl;
107 seat->seatop_data = e; 107 seat->seatop_data = e;
108 seat->seatop_button = button;
109} 108}