aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index d6c50acc..f4ac74b4 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -253,11 +253,32 @@ int cursor_get_timeout(struct sway_cursor *cursor) {
253 return timeout; 253 return timeout;
254} 254}
255 255
256static enum sway_input_idle_source idle_source_from_device(
257 struct wlr_input_device *device) {
258 switch (device->type) {
259 case WLR_INPUT_DEVICE_KEYBOARD:
260 return IDLE_SOURCE_KEYBOARD;
261 case WLR_INPUT_DEVICE_POINTER:
262 return IDLE_SOURCE_POINTER;
263 case WLR_INPUT_DEVICE_TOUCH:
264 return IDLE_SOURCE_TOUCH;
265 case WLR_INPUT_DEVICE_TABLET_TOOL:
266 return IDLE_SOURCE_TABLET_TOOL;
267 case WLR_INPUT_DEVICE_TABLET_PAD:
268 return IDLE_SOURCE_TABLET_PAD;
269 case WLR_INPUT_DEVICE_SWITCH:
270 return IDLE_SOURCE_SWITCH;
271 }
272
273 assert(false);
274}
275
256void cursor_handle_activity(struct sway_cursor *cursor, 276void cursor_handle_activity(struct sway_cursor *cursor,
257 enum sway_input_idle_source idle_source) { 277 struct wlr_input_device *device) {
258 wl_event_source_timer_update( 278 wl_event_source_timer_update(
259 cursor->hide_source, cursor_get_timeout(cursor)); 279 cursor->hide_source, cursor_get_timeout(cursor));
260 280
281 enum sway_input_idle_source idle_source = idle_source_from_device(device);
261 seat_idle_notify_activity(cursor->seat, idle_source); 282 seat_idle_notify_activity(cursor->seat, idle_source);
262 if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) { 283 if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) {
263 cursor_unhide(cursor); 284 cursor_unhide(cursor);
@@ -283,10 +304,6 @@ void cursor_unhide(struct sway_cursor *cursor) {
283static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, 304static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
284 struct wlr_input_device *device, double dx, double dy, 305 struct wlr_input_device *device, double dx, double dy,
285 double dx_unaccel, double dy_unaccel) { 306 double dx_unaccel, double dy_unaccel) {
286 if (device->type == WLR_INPUT_DEVICE_POINTER) {
287 cursor_handle_activity(cursor, IDLE_SOURCE_POINTER);
288 }
289
290 wlr_relative_pointer_manager_v1_send_relative_motion( 307 wlr_relative_pointer_manager_v1_send_relative_motion(
291 server.relative_pointer_manager, 308 server.relative_pointer_manager,
292 cursor->seat->wlr_seat, (uint64_t)time_msec * 1000, 309 cursor->seat->wlr_seat, (uint64_t)time_msec * 1000,
@@ -322,6 +339,7 @@ static void handle_pointer_motion_relative(
322 struct wl_listener *listener, void *data) { 339 struct wl_listener *listener, void *data) {
323 struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); 340 struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
324 struct wlr_event_pointer_motion *e = data; 341 struct wlr_event_pointer_motion *e = data;
342 cursor_handle_activity(cursor, e->device);
325 343
326 pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y, 344 pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y,
327 e->unaccel_dx, e->unaccel_dy); 345 e->unaccel_dx, e->unaccel_dy);
@@ -333,6 +351,7 @@ static void handle_pointer_motion_absolute(
333 struct sway_cursor *cursor = 351 struct sway_cursor *cursor =
334 wl_container_of(listener, cursor, motion_absolute); 352 wl_container_of(listener, cursor, motion_absolute);
335 struct wlr_event_pointer_motion_absolute *event = data; 353 struct wlr_event_pointer_motion_absolute *event = data;
354 cursor_handle_activity(cursor, event->device);
336 355
337 double lx, ly; 356 double lx, ly;
338 wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, 357 wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
@@ -358,6 +377,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
358static void handle_pointer_button(struct wl_listener *listener, void *data) { 377static void handle_pointer_button(struct wl_listener *listener, void *data) {
359 struct sway_cursor *cursor = wl_container_of(listener, cursor, button); 378 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
360 struct wlr_event_pointer_button *event = data; 379 struct wlr_event_pointer_button *event = data;
380 cursor_handle_activity(cursor, event->device);
361 381
362 if (event->state == WLR_BUTTON_PRESSED) { 382 if (event->state == WLR_BUTTON_PRESSED) {
363 cursor->pressed_button_count++; 383 cursor->pressed_button_count++;
@@ -369,7 +389,6 @@ static void handle_pointer_button(struct wl_listener *listener, void *data) {
369 } 389 }
370 } 390 }
371 391
372 cursor_handle_activity(cursor, IDLE_SOURCE_POINTER);
373 dispatch_cursor_button(cursor, event->device, 392 dispatch_cursor_button(cursor, event->device,
374 event->time_msec, event->button, event->state); 393 event->time_msec, event->button, event->state);
375 transaction_commit_dirty(); 394 transaction_commit_dirty();
@@ -383,20 +402,21 @@ void dispatch_cursor_axis(struct sway_cursor *cursor,
383static void handle_pointer_axis(struct wl_listener *listener, void *data) { 402static void handle_pointer_axis(struct wl_listener *listener, void *data) {
384 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); 403 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
385 struct wlr_event_pointer_axis *event = data; 404 struct wlr_event_pointer_axis *event = data;
386 cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); 405 cursor_handle_activity(cursor, event->device);
387 dispatch_cursor_axis(cursor, event); 406 dispatch_cursor_axis(cursor, event);
388 transaction_commit_dirty(); 407 transaction_commit_dirty();
389} 408}
390 409
391static void handle_pointer_frame(struct wl_listener *listener, void *data) { 410static void handle_pointer_frame(struct wl_listener *listener, void *data) {
392 struct sway_cursor *cursor = wl_container_of(listener, cursor, frame); 411 struct sway_cursor *cursor = wl_container_of(listener, cursor, frame);
393 cursor_handle_activity(cursor, IDLE_SOURCE_POINTER);
394 wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); 412 wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
395} 413}
396 414
397static void handle_touch_down(struct wl_listener *listener, void *data) { 415static void handle_touch_down(struct wl_listener *listener, void *data) {
398 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); 416 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
399 struct wlr_event_touch_down *event = data; 417 struct wlr_event_touch_down *event = data;
418 cursor_handle_activity(cursor, event->device);
419 cursor_hide(cursor);
400 420
401 struct sway_seat *seat = cursor->seat; 421 struct sway_seat *seat = cursor->seat;
402 struct wlr_seat *wlr_seat = seat->wlr_seat; 422 struct wlr_seat *wlr_seat = seat->wlr_seat;
@@ -414,8 +434,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
414 434
415 if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) { 435 if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) {
416 if (seat_is_input_allowed(seat, surface)) { 436 if (seat_is_input_allowed(seat, surface)) {
417 cursor_hide(cursor);
418 cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
419 wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, 437 wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
420 event->touch_id, sx, sy); 438 event->touch_id, sx, sy);
421 439
@@ -444,19 +462,19 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
444static void handle_touch_up(struct wl_listener *listener, void *data) { 462static void handle_touch_up(struct wl_listener *listener, void *data) {
445 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); 463 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
446 struct wlr_event_touch_up *event = data; 464 struct wlr_event_touch_up *event = data;
465 cursor_handle_activity(cursor, event->device);
466
447 struct wlr_seat *wlr_seat = cursor->seat->wlr_seat; 467 struct wlr_seat *wlr_seat = cursor->seat->wlr_seat;
448 468
449 if (cursor->simulating_pointer_from_touch) { 469 if (cursor->simulating_pointer_from_touch) {
450 if (cursor->pointer_touch_id == cursor->seat->touch_id) { 470 if (cursor->pointer_touch_id == cursor->seat->touch_id) {
451 cursor->simulating_pointer_from_touch = false; 471 cursor->simulating_pointer_from_touch = false;
452 cursor_handle_activity(cursor, IDLE_SOURCE_POINTER);
453 dispatch_cursor_button(cursor, event->device, event->time_msec, 472 dispatch_cursor_button(cursor, event->device, event->time_msec,
454 BTN_LEFT, WLR_BUTTON_RELEASED); 473 BTN_LEFT, WLR_BUTTON_RELEASED);
455 wlr_seat_pointer_notify_frame(wlr_seat); 474 wlr_seat_pointer_notify_frame(wlr_seat);
456 transaction_commit_dirty(); 475 transaction_commit_dirty();
457 } 476 }
458 } else { 477 } else {
459 cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
460 wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id); 478 wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id);
461 } 479 }
462} 480}
@@ -465,6 +483,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
465 struct sway_cursor *cursor = 483 struct sway_cursor *cursor =
466 wl_container_of(listener, cursor, touch_motion); 484 wl_container_of(listener, cursor, touch_motion);
467 struct wlr_event_touch_motion *event = data; 485 struct wlr_event_touch_motion *event = data;
486 cursor_handle_activity(cursor, event->device);
468 487
469 struct sway_seat *seat = cursor->seat; 488 struct sway_seat *seat = cursor->seat;
470 struct wlr_seat *wlr_seat = seat->wlr_seat; 489 struct wlr_seat *wlr_seat = seat->wlr_seat;
@@ -497,7 +516,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
497 transaction_commit_dirty(); 516 transaction_commit_dirty();
498 } 517 }
499 } else if (surface) { 518 } else if (surface) {
500 cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
501 wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, 519 wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
502 event->touch_id, sx, sy); 520 event->touch_id, sx, sy);
503 } 521 }
@@ -535,7 +553,6 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor,
535 bool change_x, bool change_y, 553 bool change_x, bool change_y,
536 double x, double y, double dx, double dy, 554 double x, double y, double dx, double dy,
537 int32_t time_msec) { 555 int32_t time_msec) {
538 cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
539 556
540 if (!change_x && !change_y) { 557 if (!change_x && !change_y) {
541 return; 558 return;
@@ -587,10 +604,10 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor,
587 604
588static void handle_tool_axis(struct wl_listener *listener, void *data) { 605static void handle_tool_axis(struct wl_listener *listener, void *data) {
589 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); 606 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
590 cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
591 struct wlr_event_tablet_tool_axis *event = data; 607 struct wlr_event_tablet_tool_axis *event = data;
592 struct sway_tablet_tool *sway_tool = event->tool->data; 608 cursor_handle_activity(cursor, event->device);
593 609
610 struct sway_tablet_tool *sway_tool = event->tool->data;
594 if (!sway_tool) { 611 if (!sway_tool) {
595 sway_log(SWAY_DEBUG, "tool axis before proximity"); 612 sway_log(SWAY_DEBUG, "tool axis before proximity");
596 return; 613 return;
@@ -643,12 +660,14 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
643 660
644static void handle_tool_tip(struct wl_listener *listener, void *data) { 661static void handle_tool_tip(struct wl_listener *listener, void *data) {
645 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); 662 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
646 cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
647 struct wlr_event_tablet_tool_tip *event = data; 663 struct wlr_event_tablet_tool_tip *event = data;
664 cursor_handle_activity(cursor, event->device);
665
648 struct sway_tablet_tool *sway_tool = event->tool->data; 666 struct sway_tablet_tool *sway_tool = event->tool->data;
649 struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; 667 struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2;
650 struct sway_seat *seat = cursor->seat; 668 struct sway_seat *seat = cursor->seat;
651 669
670
652 double sx, sy; 671 double sx, sy;
653 struct wlr_surface *surface = NULL; 672 struct wlr_surface *surface = NULL;
654 node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, 673 node_at_coords(seat, cursor->cursor->x, cursor->cursor->y,
@@ -692,9 +711,10 @@ static struct sway_tablet *get_tablet_for_device(struct sway_cursor *cursor,
692} 711}
693 712
694static void handle_tool_proximity(struct wl_listener *listener, void *data) { 713static void handle_tool_proximity(struct wl_listener *listener, void *data) {
695 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); 714 struct sway_cursor *cursor =
696 cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); 715 wl_container_of(listener, cursor, tool_proximity);
697 struct wlr_event_tablet_tool_proximity *event = data; 716 struct wlr_event_tablet_tool_proximity *event = data;
717 cursor_handle_activity(cursor, event->device);
698 718
699 struct wlr_tablet_tool *tool = event->tool; 719 struct wlr_tablet_tool *tool = event->tool;
700 if (!tool->data) { 720 if (!tool->data) {
@@ -723,10 +743,9 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) {
723 743
724static void handle_tool_button(struct wl_listener *listener, void *data) { 744static void handle_tool_button(struct wl_listener *listener, void *data) {
725 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); 745 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
726 struct sway_seat *seat = cursor->seat;
727 cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
728
729 struct wlr_event_tablet_tool_button *event = data; 746 struct wlr_event_tablet_tool_button *event = data;
747 cursor_handle_activity(cursor, event->device);
748
730 struct sway_tablet_tool *sway_tool = event->tool->data; 749 struct sway_tablet_tool *sway_tool = event->tool->data;
731 if (!sway_tool) { 750 if (!sway_tool) {
732 sway_log(SWAY_DEBUG, "tool button before proximity"); 751 sway_log(SWAY_DEBUG, "tool button before proximity");
@@ -737,7 +756,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) {
737 double sx, sy; 756 double sx, sy;
738 struct wlr_surface *surface = NULL; 757 struct wlr_surface *surface = NULL;
739 758
740 node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, 759 node_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y,
741 &surface, &sx, &sy); 760 &surface, &sx, &sy);
742 761
743 if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) { 762 if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) {