diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 444fe81d..53ff3a22 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -590,6 +590,23 @@ void cursor_rebase(struct sway_cursor *cursor) { | |||
590 | cursor_do_rebase(cursor, time_msec, cursor->previous.node, surface, sx, sy); | 590 | cursor_do_rebase(cursor, time_msec, cursor->previous.node, surface, sx, sy); |
591 | } | 591 | } |
592 | 592 | ||
593 | static int hide_notify(void *data) { | ||
594 | struct sway_cursor *cursor = data; | ||
595 | wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); | ||
596 | cursor->hidden = true; | ||
597 | return 1; | ||
598 | } | ||
599 | |||
600 | static void handle_activity(struct sway_cursor *cursor) { | ||
601 | wl_event_source_timer_update(cursor->hide_source, | ||
602 | config->hide_cursor_timeout); | ||
603 | wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); | ||
604 | if (cursor->hidden) { | ||
605 | cursor->hidden = false; | ||
606 | cursor_set_image(cursor, NULL, cursor->image_client); | ||
607 | } | ||
608 | } | ||
609 | |||
593 | void cursor_send_pointer_motion(struct sway_cursor *cursor, | 610 | void cursor_send_pointer_motion(struct sway_cursor *cursor, |
594 | uint32_t time_msec) { | 611 | uint32_t time_msec) { |
595 | if (time_msec == 0) { | 612 | if (time_msec == 0) { |
@@ -680,11 +697,11 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
680 | 697 | ||
681 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { | 698 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { |
682 | struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); | 699 | struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); |
683 | wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); | ||
684 | struct wlr_event_pointer_motion *event = data; | 700 | struct wlr_event_pointer_motion *event = data; |
685 | wlr_cursor_move(cursor->cursor, event->device, | 701 | wlr_cursor_move(cursor->cursor, event->device, |
686 | event->delta_x, event->delta_y); | 702 | event->delta_x, event->delta_y); |
687 | cursor_send_pointer_motion(cursor, event->time_msec); | 703 | cursor_send_pointer_motion(cursor, event->time_msec); |
704 | handle_activity(cursor); | ||
688 | transaction_commit_dirty(); | 705 | transaction_commit_dirty(); |
689 | } | 706 | } |
690 | 707 | ||
@@ -692,10 +709,10 @@ static void handle_cursor_motion_absolute( | |||
692 | struct wl_listener *listener, void *data) { | 709 | struct wl_listener *listener, void *data) { |
693 | struct sway_cursor *cursor = | 710 | struct sway_cursor *cursor = |
694 | wl_container_of(listener, cursor, motion_absolute); | 711 | wl_container_of(listener, cursor, motion_absolute); |
695 | wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); | ||
696 | struct wlr_event_pointer_motion_absolute *event = data; | 712 | struct wlr_event_pointer_motion_absolute *event = data; |
697 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); | 713 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); |
698 | cursor_send_pointer_motion(cursor, event->time_msec); | 714 | cursor_send_pointer_motion(cursor, event->time_msec); |
715 | handle_activity(cursor); | ||
699 | transaction_commit_dirty(); | 716 | transaction_commit_dirty(); |
700 | } | 717 | } |
701 | 718 | ||
@@ -976,10 +993,10 @@ void dispatch_cursor_button(struct sway_cursor *cursor, | |||
976 | 993 | ||
977 | static void handle_cursor_button(struct wl_listener *listener, void *data) { | 994 | static void handle_cursor_button(struct wl_listener *listener, void *data) { |
978 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); | 995 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); |
979 | wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); | ||
980 | struct wlr_event_pointer_button *event = data; | 996 | struct wlr_event_pointer_button *event = data; |
981 | dispatch_cursor_button(cursor, event->device, | 997 | dispatch_cursor_button(cursor, event->device, |
982 | event->time_msec, event->button, event->state); | 998 | event->time_msec, event->button, event->state); |
999 | handle_activity(cursor); | ||
983 | transaction_commit_dirty(); | 1000 | transaction_commit_dirty(); |
984 | } | 1001 | } |
985 | 1002 | ||
@@ -1087,9 +1104,9 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor, | |||
1087 | 1104 | ||
1088 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { | 1105 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { |
1089 | struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); | 1106 | struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); |
1090 | wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); | ||
1091 | struct wlr_event_pointer_axis *event = data; | 1107 | struct wlr_event_pointer_axis *event = data; |
1092 | dispatch_cursor_axis(cursor, event); | 1108 | dispatch_cursor_axis(cursor, event); |
1109 | handle_activity(cursor); | ||
1093 | transaction_commit_dirty(); | 1110 | transaction_commit_dirty(); |
1094 | } | 1111 | } |
1095 | 1112 | ||
@@ -1280,10 +1297,12 @@ static void handle_request_set_cursor(struct wl_listener *listener, | |||
1280 | return; | 1297 | return; |
1281 | } | 1298 | } |
1282 | 1299 | ||
1283 | wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x, | ||
1284 | event->hotspot_y); | ||
1285 | cursor->image = NULL; | 1300 | cursor->image = NULL; |
1286 | cursor->image_client = focused_client; | 1301 | cursor->image_client = focused_client; |
1302 | cursor->image_surface = event->surface; | ||
1303 | cursor->hotspot_x = event->hotspot_x; | ||
1304 | cursor->hotspot_y = event->hotspot_y; | ||
1305 | cursor_set_image(cursor, NULL, cursor->image_client); | ||
1287 | } | 1306 | } |
1288 | 1307 | ||
1289 | void cursor_set_image(struct sway_cursor *cursor, const char *image, | 1308 | void cursor_set_image(struct sway_cursor *cursor, const char *image, |
@@ -1291,9 +1310,16 @@ void cursor_set_image(struct sway_cursor *cursor, const char *image, | |||
1291 | if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { | 1310 | if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { |
1292 | return; | 1311 | return; |
1293 | } | 1312 | } |
1294 | if (!image) { | 1313 | if (cursor->hidden) { |
1314 | return; | ||
1315 | } | ||
1316 | if (!image && cursor->image_surface) { | ||
1317 | wlr_cursor_set_surface(cursor->cursor, cursor->image_surface, | ||
1318 | cursor->hotspot_x, cursor->hotspot_y); | ||
1319 | } else if (!image) { | ||
1295 | wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); | 1320 | wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); |
1296 | } else if (!cursor->image || strcmp(cursor->image, image) != 0) { | 1321 | } else if (!cursor->image || strcmp(cursor->image, image) != 0) { |
1322 | cursor->image_surface = NULL; | ||
1297 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, | 1323 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, |
1298 | cursor->cursor); | 1324 | cursor->cursor); |
1299 | } | 1325 | } |
@@ -1306,6 +1332,8 @@ void sway_cursor_destroy(struct sway_cursor *cursor) { | |||
1306 | return; | 1332 | return; |
1307 | } | 1333 | } |
1308 | 1334 | ||
1335 | wl_event_source_remove(cursor->hide_source); | ||
1336 | |||
1309 | wlr_xcursor_manager_destroy(cursor->xcursor_manager); | 1337 | wlr_xcursor_manager_destroy(cursor->xcursor_manager); |
1310 | wlr_cursor_destroy(cursor->cursor); | 1338 | wlr_cursor_destroy(cursor->cursor); |
1311 | free(cursor); | 1339 | free(cursor); |
@@ -1329,6 +1357,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
1329 | cursor->seat = seat; | 1357 | cursor->seat = seat; |
1330 | wlr_cursor_attach_output_layout(wlr_cursor, root->output_layout); | 1358 | wlr_cursor_attach_output_layout(wlr_cursor, root->output_layout); |
1331 | 1359 | ||
1360 | cursor->hide_source = wl_event_loop_add_timer(server.wl_event_loop, | ||
1361 | hide_notify, cursor); | ||
1362 | |||
1332 | // input events | 1363 | // input events |
1333 | wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); | 1364 | wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); |
1334 | cursor->motion.notify = handle_cursor_motion; | 1365 | cursor->motion.notify = handle_cursor_motion; |