diff options
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index fa604426..2fe5b202 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -4,8 +4,8 @@ | |||
4 | #include <libevdev/libevdev.h> | 4 | #include <libevdev/libevdev.h> |
5 | #include <linux/input-event-codes.h> | 5 | #include <linux/input-event-codes.h> |
6 | #include <errno.h> | 6 | #include <errno.h> |
7 | #include <time.h> | ||
7 | #include <strings.h> | 8 | #include <strings.h> |
8 | #include <wlr/types/wlr_box.h> | ||
9 | #include <wlr/types/wlr_cursor.h> | 9 | #include <wlr/types/wlr_cursor.h> |
10 | #include <wlr/types/wlr_idle.h> | 10 | #include <wlr/types/wlr_idle.h> |
11 | #include <wlr/types/wlr_pointer.h> | 11 | #include <wlr/types/wlr_pointer.h> |
@@ -20,7 +20,6 @@ | |||
20 | #include "util.h" | 20 | #include "util.h" |
21 | #include "sway/commands.h" | 21 | #include "sway/commands.h" |
22 | #include "sway/desktop.h" | 22 | #include "sway/desktop.h" |
23 | #include "sway/desktop/transaction.h" | ||
24 | #include "sway/input/cursor.h" | 23 | #include "sway/input/cursor.h" |
25 | #include "sway/input/keyboard.h" | 24 | #include "sway/input/keyboard.h" |
26 | #include "sway/input/tablet.h" | 25 | #include "sway/input/tablet.h" |
@@ -32,6 +31,12 @@ | |||
32 | #include "sway/tree/workspace.h" | 31 | #include "sway/tree/workspace.h" |
33 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 32 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
34 | 33 | ||
34 | static uint32_t get_current_time_msec(void) { | ||
35 | struct timespec now; | ||
36 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
37 | return now.tv_sec * 1000 + now.tv_nsec / 1000000; | ||
38 | } | ||
39 | |||
35 | static struct wlr_surface *layer_surface_at(struct sway_output *output, | 40 | static struct wlr_surface *layer_surface_at(struct sway_output *output, |
36 | struct wl_list *layer, double ox, double oy, double *sx, double *sy) { | 41 | struct wl_list *layer, double ox, double oy, double *sx, double *sy) { |
37 | struct sway_layer_surface *sway_layer; | 42 | struct sway_layer_surface *sway_layer; |
@@ -383,7 +388,6 @@ static void handle_pointer_motion_relative( | |||
383 | 388 | ||
384 | pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y, | 389 | pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y, |
385 | e->unaccel_dx, e->unaccel_dy); | 390 | e->unaccel_dx, e->unaccel_dy); |
386 | transaction_commit_dirty(); | ||
387 | } | 391 | } |
388 | 392 | ||
389 | static void handle_pointer_motion_absolute( | 393 | static void handle_pointer_motion_absolute( |
@@ -401,7 +405,6 @@ static void handle_pointer_motion_absolute( | |||
401 | double dy = ly - cursor->cursor->y; | 405 | double dy = ly - cursor->cursor->y; |
402 | 406 | ||
403 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); | 407 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); |
404 | transaction_commit_dirty(); | ||
405 | } | 408 | } |
406 | 409 | ||
407 | void dispatch_cursor_button(struct sway_cursor *cursor, | 410 | void dispatch_cursor_button(struct sway_cursor *cursor, |
@@ -431,7 +434,6 @@ static void handle_pointer_button(struct wl_listener *listener, void *data) { | |||
431 | cursor_handle_activity_from_device(cursor, event->device); | 434 | cursor_handle_activity_from_device(cursor, event->device); |
432 | dispatch_cursor_button(cursor, event->device, | 435 | dispatch_cursor_button(cursor, event->device, |
433 | event->time_msec, event->button, event->state); | 436 | event->time_msec, event->button, event->state); |
434 | transaction_commit_dirty(); | ||
435 | } | 437 | } |
436 | 438 | ||
437 | void dispatch_cursor_axis(struct sway_cursor *cursor, | 439 | void dispatch_cursor_axis(struct sway_cursor *cursor, |
@@ -444,7 +446,6 @@ static void handle_pointer_axis(struct wl_listener *listener, void *data) { | |||
444 | struct wlr_event_pointer_axis *event = data; | 446 | struct wlr_event_pointer_axis *event = data; |
445 | cursor_handle_activity_from_device(cursor, event->device); | 447 | cursor_handle_activity_from_device(cursor, event->device); |
446 | dispatch_cursor_axis(cursor, event); | 448 | dispatch_cursor_axis(cursor, event); |
447 | transaction_commit_dirty(); | ||
448 | } | 449 | } |
449 | 450 | ||
450 | static void handle_pointer_frame(struct wl_listener *listener, void *data) { | 451 | static void handle_pointer_frame(struct wl_listener *listener, void *data) { |
@@ -494,8 +495,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { | |||
494 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); | 495 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); |
495 | dispatch_cursor_button(cursor, event->device, event->time_msec, | 496 | dispatch_cursor_button(cursor, event->device, event->time_msec, |
496 | BTN_LEFT, WLR_BUTTON_PRESSED); | 497 | BTN_LEFT, WLR_BUTTON_PRESSED); |
497 | wlr_seat_pointer_notify_frame(wlr_seat); | ||
498 | transaction_commit_dirty(); | ||
499 | } | 498 | } |
500 | } | 499 | } |
501 | 500 | ||
@@ -508,11 +507,9 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { | |||
508 | 507 | ||
509 | if (cursor->simulating_pointer_from_touch) { | 508 | if (cursor->simulating_pointer_from_touch) { |
510 | if (cursor->pointer_touch_id == cursor->seat->touch_id) { | 509 | if (cursor->pointer_touch_id == cursor->seat->touch_id) { |
511 | cursor->simulating_pointer_from_touch = false; | 510 | cursor->pointer_touch_up = true; |
512 | dispatch_cursor_button(cursor, event->device, event->time_msec, | 511 | dispatch_cursor_button(cursor, event->device, event->time_msec, |
513 | BTN_LEFT, WLR_BUTTON_RELEASED); | 512 | BTN_LEFT, WLR_BUTTON_RELEASED); |
514 | wlr_seat_pointer_notify_frame(wlr_seat); | ||
515 | transaction_commit_dirty(); | ||
516 | } | 513 | } |
517 | } else { | 514 | } else { |
518 | wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id); | 515 | wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id); |
@@ -553,7 +550,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
553 | dx = lx - cursor->cursor->x; | 550 | dx = lx - cursor->cursor->x; |
554 | dy = ly - cursor->cursor->y; | 551 | dy = ly - cursor->cursor->y; |
555 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); | 552 | pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy); |
556 | transaction_commit_dirty(); | ||
557 | } | 553 | } |
558 | } else if (surface) { | 554 | } else if (surface) { |
559 | wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, | 555 | wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, |
@@ -561,6 +557,24 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
561 | } | 557 | } |
562 | } | 558 | } |
563 | 559 | ||
560 | static void handle_touch_frame(struct wl_listener *listener, void *data) { | ||
561 | struct sway_cursor *cursor = | ||
562 | wl_container_of(listener, cursor, touch_frame); | ||
563 | |||
564 | struct wlr_seat *wlr_seat = cursor->seat->wlr_seat; | ||
565 | |||
566 | if (cursor->simulating_pointer_from_touch) { | ||
567 | wlr_seat_pointer_notify_frame(wlr_seat); | ||
568 | |||
569 | if (cursor->pointer_touch_up) { | ||
570 | cursor->pointer_touch_up = false; | ||
571 | cursor->simulating_pointer_from_touch = false; | ||
572 | } | ||
573 | } else { | ||
574 | wlr_seat_touch_notify_frame(wlr_seat); | ||
575 | } | ||
576 | } | ||
577 | |||
564 | static double apply_mapping_from_coord(double low, double high, double value) { | 578 | static double apply_mapping_from_coord(double low, double high, double value) { |
565 | if (isnan(value)) { | 579 | if (isnan(value)) { |
566 | return value; | 580 | return value; |
@@ -639,8 +653,6 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor, | |||
639 | wlr_tablet_v2_tablet_tool_notify_proximity_out(tool->tablet_v2_tool); | 653 | wlr_tablet_v2_tablet_tool_notify_proximity_out(tool->tablet_v2_tool); |
640 | pointer_motion(cursor, time_msec, input_device->wlr_device, dx, dy, dx, dy); | 654 | pointer_motion(cursor, time_msec, input_device->wlr_device, dx, dy, dx, dy); |
641 | } | 655 | } |
642 | |||
643 | transaction_commit_dirty(); | ||
644 | } | 656 | } |
645 | 657 | ||
646 | static void handle_tool_axis(struct wl_listener *listener, void *data) { | 658 | static void handle_tool_axis(struct wl_listener *listener, void *data) { |
@@ -720,7 +732,6 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { | |||
720 | dispatch_cursor_button(cursor, event->device, event->time_msec, | 732 | dispatch_cursor_button(cursor, event->device, event->time_msec, |
721 | BTN_LEFT, WLR_BUTTON_RELEASED); | 733 | BTN_LEFT, WLR_BUTTON_RELEASED); |
722 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); | 734 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); |
723 | transaction_commit_dirty(); | ||
724 | } else if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) { | 735 | } else if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) { |
725 | // If we started holding the tool tip down on a surface that accepts | 736 | // If we started holding the tool tip down on a surface that accepts |
726 | // tablet v2, we should notify that surface if it gets released over a | 737 | // tablet v2, we should notify that surface if it gets released over a |
@@ -733,7 +744,6 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { | |||
733 | dispatch_cursor_button(cursor, event->device, event->time_msec, | 744 | dispatch_cursor_button(cursor, event->device, event->time_msec, |
734 | BTN_LEFT, WLR_BUTTON_PRESSED); | 745 | BTN_LEFT, WLR_BUTTON_PRESSED); |
735 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); | 746 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); |
736 | transaction_commit_dirty(); | ||
737 | } | 747 | } |
738 | } else { | 748 | } else { |
739 | seatop_tablet_tool_tip(seat, sway_tool, event->time_msec, event->state); | 749 | seatop_tablet_tool_tip(seat, sway_tool, event->time_msec, event->state); |
@@ -820,7 +830,6 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { | |||
820 | break; | 830 | break; |
821 | } | 831 | } |
822 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); | 832 | wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); |
823 | transaction_commit_dirty(); | ||
824 | return; | 833 | return; |
825 | } | 834 | } |
826 | 835 | ||
@@ -837,8 +846,8 @@ static void check_constraint_region(struct sway_cursor *cursor) { | |||
837 | 846 | ||
838 | struct sway_container *con = view->container; | 847 | struct sway_container *con = view->container; |
839 | 848 | ||
840 | double sx = cursor->cursor->x - con->content_x + view->geometry.x; | 849 | double sx = cursor->cursor->x - con->pending.content_x + view->geometry.x; |
841 | double sy = cursor->cursor->y - con->content_y + view->geometry.y; | 850 | double sy = cursor->cursor->y - con->pending.content_y + view->geometry.y; |
842 | 851 | ||
843 | if (!pixman_region32_contains_point(region, | 852 | if (!pixman_region32_contains_point(region, |
844 | floor(sx), floor(sy), NULL)) { | 853 | floor(sx), floor(sy), NULL)) { |
@@ -849,8 +858,8 @@ static void check_constraint_region(struct sway_cursor *cursor) { | |||
849 | double sy = (boxes[0].y1 + boxes[0].y2) / 2.; | 858 | double sy = (boxes[0].y1 + boxes[0].y2) / 2.; |
850 | 859 | ||
851 | wlr_cursor_warp_closest(cursor->cursor, NULL, | 860 | wlr_cursor_warp_closest(cursor->cursor, NULL, |
852 | sx + con->content_x - view->geometry.x, | 861 | sx + con->pending.content_x - view->geometry.x, |
853 | sy + con->content_y - view->geometry.y); | 862 | sy + con->pending.content_y - view->geometry.y); |
854 | 863 | ||
855 | cursor_rebase(cursor); | 864 | cursor_rebase(cursor); |
856 | } | 865 | } |
@@ -1051,6 +1060,7 @@ void sway_cursor_destroy(struct sway_cursor *cursor) { | |||
1051 | wl_list_remove(&cursor->touch_down.link); | 1060 | wl_list_remove(&cursor->touch_down.link); |
1052 | wl_list_remove(&cursor->touch_up.link); | 1061 | wl_list_remove(&cursor->touch_up.link); |
1053 | wl_list_remove(&cursor->touch_motion.link); | 1062 | wl_list_remove(&cursor->touch_motion.link); |
1063 | wl_list_remove(&cursor->touch_frame.link); | ||
1054 | wl_list_remove(&cursor->tool_axis.link); | 1064 | wl_list_remove(&cursor->tool_axis.link); |
1055 | wl_list_remove(&cursor->tool_tip.link); | 1065 | wl_list_remove(&cursor->tool_tip.link); |
1056 | wl_list_remove(&cursor->tool_button.link); | 1066 | wl_list_remove(&cursor->tool_button.link); |
@@ -1126,6 +1136,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
1126 | &cursor->touch_motion); | 1136 | &cursor->touch_motion); |
1127 | cursor->touch_motion.notify = handle_touch_motion; | 1137 | cursor->touch_motion.notify = handle_touch_motion; |
1128 | 1138 | ||
1139 | wl_signal_add(&wlr_cursor->events.touch_frame, &cursor->touch_frame); | ||
1140 | cursor->touch_frame.notify = handle_touch_frame; | ||
1141 | |||
1129 | wl_signal_add(&wlr_cursor->events.tablet_tool_axis, | 1142 | wl_signal_add(&wlr_cursor->events.tablet_tool_axis, |
1130 | &cursor->tool_axis); | 1143 | &cursor->tool_axis); |
1131 | cursor->tool_axis.notify = handle_tool_axis; | 1144 | cursor->tool_axis.notify = handle_tool_axis; |
@@ -1170,8 +1183,8 @@ void cursor_warp_to_container(struct sway_cursor *cursor, | |||
1170 | return; | 1183 | return; |
1171 | } | 1184 | } |
1172 | 1185 | ||
1173 | double x = container->x + container->width / 2.0; | 1186 | double x = container->pending.x + container->pending.width / 2.0; |
1174 | double y = container->y + container->height / 2.0; | 1187 | double y = container->pending.y + container->pending.height / 2.0; |
1175 | 1188 | ||
1176 | wlr_cursor_warp(cursor->cursor, NULL, x, y); | 1189 | wlr_cursor_warp(cursor->cursor, NULL, x, y); |
1177 | cursor_unhide(cursor); | 1190 | cursor_unhide(cursor); |
@@ -1284,8 +1297,8 @@ static void warp_to_constraint_cursor_hint(struct sway_cursor *cursor) { | |||
1284 | struct sway_view *view = view_from_wlr_surface(constraint->surface); | 1297 | struct sway_view *view = view_from_wlr_surface(constraint->surface); |
1285 | struct sway_container *con = view->container; | 1298 | struct sway_container *con = view->container; |
1286 | 1299 | ||
1287 | double lx = sx + con->content_x - view->geometry.x; | 1300 | double lx = sx + con->pending.content_x - view->geometry.x; |
1288 | double ly = sy + con->content_y - view->geometry.y; | 1301 | double ly = sy + con->pending.content_y - view->geometry.y; |
1289 | 1302 | ||
1290 | wlr_cursor_warp(cursor->cursor, NULL, lx, ly); | 1303 | wlr_cursor_warp(cursor->cursor, NULL, lx, ly); |
1291 | 1304 | ||