diff options
author | Stacy Harper <contact@stacyharper.net> | 2021-08-21 16:04:08 +0200 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2023-02-20 10:35:10 -0500 |
commit | 4666d1785bfb6635e6e8604de383c91714bceebc (patch) | |
tree | e940606bd8e735c26b4239342afe88116bf9f457 /sway/input/cursor.c | |
parent | layer-shell: enter output before surface is mapped (diff) | |
download | sway-4666d1785bfb6635e6e8604de383c91714bceebc.tar.gz sway-4666d1785bfb6635e6e8604de383c91714bceebc.tar.zst sway-4666d1785bfb6635e6e8604de383c91714bceebc.zip |
Implement seatop_touch
Atm we got issue with the touch position sent to the clients. While
holding contact, leaving the initial container will continue to send
motion event to the client but with the new local position from the new
container.
This seatop goal is to send the position of the touch event, relatively
to the initial container layout position.
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index ad69e7c3..15687993 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -364,7 +364,7 @@ void cursor_unhide(struct sway_cursor *cursor) { | |||
364 | wl_event_source_timer_update(cursor->hide_source, cursor_get_timeout(cursor)); | 364 | wl_event_source_timer_update(cursor->hide_source, cursor_get_timeout(cursor)); |
365 | } | 365 | } |
366 | 366 | ||
367 | static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | 367 | void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, |
368 | struct wlr_input_device *device, double dx, double dy, | 368 | struct wlr_input_device *device, double dx, double dy, |
369 | double dx_unaccel, double dy_unaccel) { | 369 | double dx_unaccel, double dy_unaccel) { |
370 | wlr_relative_pointer_manager_v1_send_relative_motion( | 370 | wlr_relative_pointer_manager_v1_send_relative_motion( |
@@ -479,43 +479,16 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { | |||
479 | cursor_hide(cursor); | 479 | cursor_hide(cursor); |
480 | 480 | ||
481 | struct sway_seat *seat = cursor->seat; | 481 | struct sway_seat *seat = cursor->seat; |
482 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
483 | struct wlr_surface *surface = NULL; | ||
484 | 482 | ||
485 | double lx, ly; | 483 | double lx, ly; |
486 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base, | 484 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base, |
487 | event->x, event->y, &lx, &ly); | 485 | event->x, event->y, &lx, &ly); |
488 | double sx, sy; | ||
489 | struct sway_node *focused_node = node_at_coords(seat, lx, ly, &surface, &sx, &sy); | ||
490 | 486 | ||
491 | seat->touch_id = event->touch_id; | 487 | seat->touch_id = event->touch_id; |
492 | seat->touch_x = lx; | 488 | seat->touch_x = lx; |
493 | seat->touch_y = ly; | 489 | seat->touch_y = ly; |
494 | 490 | ||
495 | if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) { | 491 | seatop_touch_down(seat, event, lx, ly); |
496 | if (seat_is_input_allowed(seat, surface)) { | ||
497 | wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, | ||
498 | event->touch_id, sx, sy); | ||
499 | |||
500 | if (focused_node) { | ||
501 | seat_set_focus(seat, focused_node); | ||
502 | } | ||
503 | } | ||
504 | } else if (!cursor->simulating_pointer_from_touch && | ||
505 | (!surface || seat_is_input_allowed(seat, surface))) { | ||
506 | // Fallback to cursor simulation. | ||
507 | // The pointer_touch_id state is needed, so drags are not aborted when over | ||
508 | // a surface supporting touch and multi touch events don't interfere. | ||
509 | cursor->simulating_pointer_from_touch = true; | ||
510 | cursor->pointer_touch_id = seat->touch_id; | ||
511 | double dx, dy; | ||
512 | dx = lx - cursor->cursor->x; | ||
513 | dy = ly - cursor->cursor->y; | ||
514 | pointer_motion(cursor, event->time_msec, &event->touch->base, dx, dy, | ||
515 | dx, dy); | ||
516 | dispatch_cursor_button(cursor, &event->touch->base, event->time_msec, | ||
517 | BTN_LEFT, WLR_BUTTON_PRESSED); | ||
518 | } | ||
519 | } | 492 | } |
520 | 493 | ||
521 | static void handle_touch_up(struct wl_listener *listener, void *data) { | 494 | static void handle_touch_up(struct wl_listener *listener, void *data) { |
@@ -523,7 +496,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { | |||
523 | struct wlr_touch_up_event *event = data; | 496 | struct wlr_touch_up_event *event = data; |
524 | cursor_handle_activity_from_device(cursor, &event->touch->base); | 497 | cursor_handle_activity_from_device(cursor, &event->touch->base); |
525 | 498 | ||
526 | struct wlr_seat *wlr_seat = cursor->seat->wlr_seat; | 499 | struct sway_seat *seat = cursor->seat; |
527 | 500 | ||
528 | if (cursor->simulating_pointer_from_touch) { | 501 | if (cursor->simulating_pointer_from_touch) { |
529 | if (cursor->pointer_touch_id == cursor->seat->touch_id) { | 502 | if (cursor->pointer_touch_id == cursor->seat->touch_id) { |
@@ -532,7 +505,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { | |||
532 | event->time_msec, BTN_LEFT, WLR_BUTTON_RELEASED); | 505 | event->time_msec, BTN_LEFT, WLR_BUTTON_RELEASED); |
533 | } | 506 | } |
534 | } else { | 507 | } else { |
535 | wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id); | 508 | seatop_touch_up(seat, event); |
536 | } | 509 | } |
537 | } | 510 | } |
538 | 511 | ||
@@ -543,19 +516,14 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
543 | cursor_handle_activity_from_device(cursor, &event->touch->base); | 516 | cursor_handle_activity_from_device(cursor, &event->touch->base); |
544 | 517 | ||
545 | struct sway_seat *seat = cursor->seat; | 518 | struct sway_seat *seat = cursor->seat; |
546 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
547 | struct wlr_surface *surface = NULL; | ||
548 | 519 | ||
549 | double lx, ly; | 520 | double lx, ly; |
550 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base, | 521 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base, |
551 | event->x, event->y, &lx, &ly); | 522 | event->x, event->y, &lx, &ly); |
552 | double sx, sy; | ||
553 | node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); | ||
554 | 523 | ||
555 | if (seat->touch_id == event->touch_id) { | 524 | if (seat->touch_id == event->touch_id) { |
556 | seat->touch_x = lx; | 525 | seat->touch_x = lx; |
557 | seat->touch_y = ly; | 526 | seat->touch_y = ly; |
558 | |||
559 | struct sway_drag_icon *drag_icon; | 527 | struct sway_drag_icon *drag_icon; |
560 | wl_list_for_each(drag_icon, &root->drag_icons, link) { | 528 | wl_list_for_each(drag_icon, &root->drag_icons, link) { |
561 | if (drag_icon->seat == seat) { | 529 | if (drag_icon->seat == seat) { |
@@ -572,9 +540,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
572 | pointer_motion(cursor, event->time_msec, &event->touch->base, | 540 | pointer_motion(cursor, event->time_msec, &event->touch->base, |
573 | dx, dy, dx, dy); | 541 | dx, dy, dx, dy); |
574 | } | 542 | } |
575 | } else if (surface) { | 543 | } else { |
576 | wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, | 544 | seatop_touch_motion(seat, event, lx, ly); |
577 | event->touch_id, sx, sy); | ||
578 | } | 545 | } |
579 | } | 546 | } |
580 | 547 | ||