aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-15 16:47:02 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-18 09:18:32 +1000
commita36625a482585e86d465df1eaa3669c1c4390a20 (patch)
treefcc64fb33bea1347c634b8a2363cdbc13b93ab4b /sway/input
parentMerge pull request #2472 from RyanDwyer/refactor-seat-get-focus (diff)
downloadsway-a36625a482585e86d465df1eaa3669c1c4390a20.tar.gz
sway-a36625a482585e86d465df1eaa3669c1c4390a20.tar.zst
sway-a36625a482585e86d465df1eaa3669c1c4390a20.zip
Implement mousedown operation
This allows you to move the cursor off the surface while dragging its scrollbar.
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/cursor.c23
-rw-r--r--sway/input/seat.c24
2 files changed, 46 insertions, 1 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 3b70b471..bd0030f0 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -215,6 +215,18 @@ static enum wlr_edges find_resize_edge(struct sway_container *cont,
215 return edge; 215 return edge;
216} 216}
217 217
218static void handle_mousedown_motion(struct sway_seat *seat,
219 struct sway_cursor *cursor, uint32_t time_msec) {
220 struct sway_container *con = seat->op_container;
221 if (seat_is_input_allowed(seat, con->sway_view->surface)) {
222 double moved_x = cursor->cursor->x - seat->op_ref_lx;
223 double moved_y = cursor->cursor->y - seat->op_ref_ly;
224 double sx = seat->op_ref_con_lx + moved_x;
225 double sy = seat->op_ref_con_ly + moved_y;
226 wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy);
227 }
228}
229
218static void handle_move_motion(struct sway_seat *seat, 230static void handle_move_motion(struct sway_seat *seat,
219 struct sway_cursor *cursor) { 231 struct sway_cursor *cursor) {
220 struct sway_container *con = seat->op_container; 232 struct sway_container *con = seat->op_container;
@@ -397,6 +409,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
397 409
398 if (seat->operation != OP_NONE) { 410 if (seat->operation != OP_NONE) {
399 switch (seat->operation) { 411 switch (seat->operation) {
412 case OP_MOUSEDOWN:
413 handle_mousedown_motion(seat, cursor, time_msec);
414 break;
400 case OP_MOVE: 415 case OP_MOVE:
401 handle_move_motion(seat, cursor); 416 handle_move_motion(seat, cursor);
402 break; 417 break;
@@ -743,6 +758,14 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
743 } 758 }
744 } 759 }
745 760
761 // Handle mousedown on a container surface
762 if (surface && cont && state == WLR_BUTTON_PRESSED) {
763 seat_set_focus(seat, cont);
764 seat_pointer_notify_button(seat, time_msec, button, state);
765 seat_begin_mousedown(seat, cont, button, sx, sy);
766 return;
767 }
768
746 // Handle clicking a container surface 769 // Handle clicking a container surface
747 if (cont) { 770 if (cont) {
748 seat_set_focus(seat, cont); 771 seat_set_focus(seat, cont);
diff --git a/sway/input/seat.c b/sway/input/seat.c
index fa41904a..045bf91a 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -954,6 +954,17 @@ struct seat_config *seat_get_config(struct sway_seat *seat) {
954 return NULL; 954 return NULL;
955} 955}
956 956
957void seat_begin_mousedown(struct sway_seat *seat, struct sway_container *con,
958 uint32_t button, double sx, double sy) {
959 seat->operation = OP_MOUSEDOWN;
960 seat->op_container = con;
961 seat->op_button = button;
962 seat->op_ref_lx = seat->cursor->cursor->x;
963 seat->op_ref_ly = seat->cursor->cursor->y;
964 seat->op_ref_con_lx = sx;
965 seat->op_ref_con_ly = sy;
966}
967
957void seat_begin_move(struct sway_seat *seat, struct sway_container *con, 968void seat_begin_move(struct sway_seat *seat, struct sway_container *con,
958 uint32_t button) { 969 uint32_t button) {
959 if (!seat->cursor) { 970 if (!seat->cursor) {
@@ -1007,6 +1018,7 @@ void seat_begin_resize_tiling(struct sway_seat *seat,
1007} 1018}
1008 1019
1009void seat_end_mouse_operation(struct sway_seat *seat) { 1020void seat_end_mouse_operation(struct sway_seat *seat) {
1021 int operation = seat->operation;
1010 if (seat->operation == OP_MOVE) { 1022 if (seat->operation == OP_MOVE) {
1011 // We "move" the container to its own location so it discovers its 1023 // We "move" the container to its own location so it discovers its
1012 // output again. 1024 // output again.
@@ -1015,7 +1027,17 @@ void seat_end_mouse_operation(struct sway_seat *seat) {
1015 } 1027 }
1016 seat->operation = OP_NONE; 1028 seat->operation = OP_NONE;
1017 seat->op_container = NULL; 1029 seat->op_container = NULL;
1018 cursor_set_image(seat->cursor, "left_ptr", NULL); 1030 if (operation == OP_MOUSEDOWN) {
1031 // Set the cursor's previous coords to the x/y at the start of the
1032 // operation, so the container change will be detected if using
1033 // focus_follows_mouse and the cursor moved off the original container
1034 // during the operation.
1035 seat->cursor->previous.x = seat->op_ref_lx;
1036 seat->cursor->previous.y = seat->op_ref_ly;
1037 cursor_send_pointer_motion(seat->cursor, 0, true);
1038 } else {
1039 cursor_set_image(seat->cursor, "left_ptr", NULL);
1040 }
1019} 1041}
1020 1042
1021void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec, 1043void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec,