Add pointer gestures support
444c88587a43cb5579dce31db9a41d8d3b0481ae
1 parent
aae8cac6
swm.c
+116 -0
| 50 | 50 | #include <wlr/types/wlr_output_layout.h> |
|
| 51 | 51 | #include <wlr/types/wlr_output_management_v1.h> |
|
| 52 | 52 | #include <wlr/types/wlr_output_power_management_v1.h> |
|
| 53 | 53 | #include <wlr/types/wlr_pointer.h> |
|
| 54 | 54 | #include <wlr/types/wlr_pointer_constraints_v1.h> |
|
| 55 | + | #include <wlr/types/wlr_pointer_gestures_v1.h> |
|
| 55 | 56 | #include <wlr/types/wlr_presentation_time.h> |
|
| 56 | 57 | #include <wlr/types/wlr_primary_selection.h> |
|
| 57 | 58 | #include <wlr/types/wlr_primary_selection_v1.h> |
|
| 58 | 59 | #include <wlr/types/wlr_relative_pointer_v1.h> |
|
| 59 | 60 | #include <wlr/types/wlr_scene.h> |
| 527 | 528 | double sx_unaccel, |
|
| 528 | 529 | double sy_unaccel, |
|
| 529 | 530 | bool refocus |
|
| 530 | 531 | ); |
|
| 531 | 532 | static void motion_relative(struct wl_listener *listener, void *data); |
|
| 533 | + | static void gesture_swipe_begin(struct wl_listener *listener, void *data); |
|
| 534 | + | static void gesture_swipe_update(struct wl_listener *listener, void *data); |
|
| 535 | + | static void gesture_swipe_end(struct wl_listener *listener, void *data); |
|
| 536 | + | static void gesture_pinch_begin(struct wl_listener *listener, void *data); |
|
| 537 | + | static void gesture_pinch_update(struct wl_listener *listener, void *data); |
|
| 538 | + | static void gesture_pinch_end(struct wl_listener *listener, void *data); |
|
| 539 | + | static void gesture_hold_begin(struct wl_listener *listener, void *data); |
|
| 540 | + | static void gesture_hold_end(struct wl_listener *listener, void *data); |
|
| 532 | 541 | static void move_resize(const arg_t *arg); |
|
| 533 | 542 | static void output_manager_apply(struct wl_listener *listener, void *data); |
|
| 534 | 543 | static void output_manager_apply_or_test(struct wlr_output_configuration_v1 *config, bool test); |
|
| 535 | 544 | static void output_manager_test(struct wl_listener *listener, void *data); |
|
| 536 | 545 | static void pointer_focus( |
| 660 | 669 | static struct wlr_ext_foreign_toplevel_list_v1 *ext_ftl_list; |
|
| 661 | 670 | static struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1 *ext_ftl_capture_mgr; |
|
| 662 | 671 | static struct wl_listener ext_ftl_capture_request = { .notify = ftl_capture_request_notify }; |
|
| 663 | 672 | ||
| 664 | 673 | static struct wlr_pointer_constraints_v1 *pointer_constraints; |
|
| 674 | + | static struct wlr_pointer_gestures_v1 *pointer_gestures; |
|
| 665 | 675 | static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr; |
|
| 666 | 676 | static struct wlr_pointer_constraint_v1 *active_constraint; |
|
| 667 | 677 | ||
| 668 | 678 | static struct wlr_cursor *cursor; |
|
| 669 | 679 | static struct wlr_xcursor_manager *cursor_mgr; |
| 697 | 707 | static struct wl_listener cursor_axis = { .notify = axis_notify }; |
|
| 698 | 708 | static struct wl_listener cursor_button = { .notify = button_press }; |
|
| 699 | 709 | static struct wl_listener cursor_frame_listener = { .notify = cursor_frame }; |
|
| 700 | 710 | static struct wl_listener cursor_motion = { .notify = motion_relative }; |
|
| 701 | 711 | static struct wl_listener cursor_motion_absolute = { .notify = motion_absolute }; |
|
| 712 | + | static struct wl_listener cursor_swipe_begin = { .notify = gesture_swipe_begin }; |
|
| 713 | + | static struct wl_listener cursor_swipe_update = { .notify = gesture_swipe_update }; |
|
| 714 | + | static struct wl_listener cursor_swipe_end = { .notify = gesture_swipe_end }; |
|
| 715 | + | static struct wl_listener cursor_pinch_begin = { .notify = gesture_pinch_begin }; |
|
| 716 | + | static struct wl_listener cursor_pinch_update = { .notify = gesture_pinch_update }; |
|
| 717 | + | static struct wl_listener cursor_pinch_end = { .notify = gesture_pinch_end }; |
|
| 718 | + | static struct wl_listener cursor_hold_begin = { .notify = gesture_hold_begin }; |
|
| 719 | + | static struct wl_listener cursor_hold_end = { .notify = gesture_hold_end }; |
|
| 702 | 720 | static struct wl_listener gpu_reset_listener = { .notify = gpu_reset }; |
|
| 703 | 721 | static struct wl_listener layout_change = { .notify = update_monitors }; |
|
| 704 | 722 | static struct wl_listener new_idle_inhibitor = { .notify = create_idle_inhibitor }; |
|
| 705 | 723 | static struct wl_listener new_input_device = { .notify = input_device }; |
|
| 706 | 724 | static struct wl_listener new_input_method = { .notify = input_method_create_notify }; |
| 1989 | 2007 | wl_list_remove(&cursor_axis.link); |
|
| 1990 | 2008 | wl_list_remove(&cursor_button.link); |
|
| 1991 | 2009 | wl_list_remove(&cursor_frame_listener.link); |
|
| 1992 | 2010 | wl_list_remove(&cursor_motion.link); |
|
| 1993 | 2011 | wl_list_remove(&cursor_motion_absolute.link); |
|
| 2012 | + | wl_list_remove(&cursor_swipe_begin.link); |
|
| 2013 | + | wl_list_remove(&cursor_swipe_update.link); |
|
| 2014 | + | wl_list_remove(&cursor_swipe_end.link); |
|
| 2015 | + | wl_list_remove(&cursor_pinch_begin.link); |
|
| 2016 | + | wl_list_remove(&cursor_pinch_update.link); |
|
| 2017 | + | wl_list_remove(&cursor_pinch_end.link); |
|
| 2018 | + | wl_list_remove(&cursor_hold_begin.link); |
|
| 2019 | + | wl_list_remove(&cursor_hold_end.link); |
|
| 1994 | 2020 | wl_list_remove(&gpu_reset_listener.link); |
|
| 1995 | 2021 | wl_list_remove(&new_idle_inhibitor.link); |
|
| 1996 | 2022 | wl_list_remove(&layout_change.link); |
|
| 1997 | 2023 | wl_list_remove(&new_input_device.link); |
|
| 1998 | 2024 | wl_list_remove(&new_input_method.link); |
| 4130 | 4156 | event->unaccel_dy, |
|
| 4131 | 4157 | 1 |
|
| 4132 | 4158 | ); |
|
| 4133 | 4159 | } |
|
| 4134 | 4160 | ||
| 4161 | + | /* Forward touchpad swipe gestures to clients of the focused surface. */ |
|
| 4162 | + | void gesture_swipe_begin(struct wl_listener *listener, void *data) { |
|
| 4163 | + | struct wlr_pointer_swipe_begin_event *event = data; |
|
| 4164 | + | ||
| 4165 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4166 | + | wlr_pointer_gestures_v1_send_swipe_begin( |
|
| 4167 | + | pointer_gestures, seat, event->time_msec, event->fingers |
|
| 4168 | + | ); |
|
| 4169 | + | } |
|
| 4170 | + | ||
| 4171 | + | void gesture_swipe_update(struct wl_listener *listener, void *data) { |
|
| 4172 | + | struct wlr_pointer_swipe_update_event *event = data; |
|
| 4173 | + | ||
| 4174 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4175 | + | wlr_pointer_gestures_v1_send_swipe_update( |
|
| 4176 | + | pointer_gestures, seat, event->time_msec, event->dx, event->dy |
|
| 4177 | + | ); |
|
| 4178 | + | } |
|
| 4179 | + | ||
| 4180 | + | void gesture_swipe_end(struct wl_listener *listener, void *data) { |
|
| 4181 | + | struct wlr_pointer_swipe_end_event *event = data; |
|
| 4182 | + | ||
| 4183 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4184 | + | wlr_pointer_gestures_v1_send_swipe_end( |
|
| 4185 | + | pointer_gestures, seat, event->time_msec, event->cancelled |
|
| 4186 | + | ); |
|
| 4187 | + | } |
|
| 4188 | + | ||
| 4189 | + | /* Forward touchpad pinch gestures, including scale and rotation. */ |
|
| 4190 | + | void gesture_pinch_begin(struct wl_listener *listener, void *data) { |
|
| 4191 | + | struct wlr_pointer_pinch_begin_event *event = data; |
|
| 4192 | + | ||
| 4193 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4194 | + | wlr_pointer_gestures_v1_send_pinch_begin( |
|
| 4195 | + | pointer_gestures, seat, event->time_msec, event->fingers |
|
| 4196 | + | ); |
|
| 4197 | + | } |
|
| 4198 | + | ||
| 4199 | + | void gesture_pinch_update(struct wl_listener *listener, void *data) { |
|
| 4200 | + | struct wlr_pointer_pinch_update_event *event = data; |
|
| 4201 | + | ||
| 4202 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4203 | + | wlr_pointer_gestures_v1_send_pinch_update( |
|
| 4204 | + | pointer_gestures, |
|
| 4205 | + | seat, |
|
| 4206 | + | event->time_msec, |
|
| 4207 | + | event->dx, |
|
| 4208 | + | event->dy, |
|
| 4209 | + | event->scale, |
|
| 4210 | + | event->rotation |
|
| 4211 | + | ); |
|
| 4212 | + | } |
|
| 4213 | + | ||
| 4214 | + | void gesture_pinch_end(struct wl_listener *listener, void *data) { |
|
| 4215 | + | struct wlr_pointer_pinch_end_event *event = data; |
|
| 4216 | + | ||
| 4217 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4218 | + | wlr_pointer_gestures_v1_send_pinch_end( |
|
| 4219 | + | pointer_gestures, seat, event->time_msec, event->cancelled |
|
| 4220 | + | ); |
|
| 4221 | + | } |
|
| 4222 | + | ||
| 4223 | + | /* Forward touchpad hold gestures to clients of the focused surface. */ |
|
| 4224 | + | void gesture_hold_begin(struct wl_listener *listener, void *data) { |
|
| 4225 | + | struct wlr_pointer_hold_begin_event *event = data; |
|
| 4226 | + | ||
| 4227 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4228 | + | wlr_pointer_gestures_v1_send_hold_begin( |
|
| 4229 | + | pointer_gestures, seat, event->time_msec, event->fingers |
|
| 4230 | + | ); |
|
| 4231 | + | } |
|
| 4232 | + | ||
| 4233 | + | void gesture_hold_end(struct wl_listener *listener, void *data) { |
|
| 4234 | + | struct wlr_pointer_hold_end_event *event = data; |
|
| 4235 | + | ||
| 4236 | + | wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); |
|
| 4237 | + | wlr_pointer_gestures_v1_send_hold_end( |
|
| 4238 | + | pointer_gestures, seat, event->time_msec, event->cancelled |
|
| 4239 | + | ); |
|
| 4240 | + | } |
|
| 4241 | + | ||
| 4135 | 4242 | /* Begin moving or resizing the window under the pointer. */ |
|
| 4136 | 4243 | void move_resize(const arg_t *arg) { |
|
| 4137 | 4244 | if (cursor_mode != CURSOR_NORMAL && cursor_mode != CURSOR_PRESSED) |
|
| 4138 | 4245 | return; |
|
| 4139 | 4246 | point_to_node(cursor->x, cursor->y, nullptr, &grabc, nullptr, nullptr, nullptr); |
| 5382 | 5489 | ||
| 5383 | 5490 | pointer_constraints = wlr_pointer_constraints_v1_create(dpy); |
|
| 5384 | 5491 | wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint); |
|
| 5385 | 5492 | ||
| 5386 | 5493 | relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); |
|
| 5494 | + | pointer_gestures = wlr_pointer_gestures_v1_create(dpy); |
|
| 5387 | 5495 | ||
| 5388 | 5496 | /* Track the pointer across all displays. */ |
|
| 5389 | 5497 | cursor = wlr_cursor_create(); |
|
| 5390 | 5498 | wlr_cursor_attach_output_layout(cursor, output_layout); |
|
| 5391 | 5499 |
| 5397 | 5505 | wl_signal_add(&cursor->events.motion, &cursor_motion); |
|
| 5398 | 5506 | wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute); |
|
| 5399 | 5507 | wl_signal_add(&cursor->events.button, &cursor_button); |
|
| 5400 | 5508 | wl_signal_add(&cursor->events.axis, &cursor_axis); |
|
| 5401 | 5509 | wl_signal_add(&cursor->events.frame, &cursor_frame_listener); |
|
| 5510 | + | wl_signal_add(&cursor->events.swipe_begin, &cursor_swipe_begin); |
|
| 5511 | + | wl_signal_add(&cursor->events.swipe_update, &cursor_swipe_update); |
|
| 5512 | + | wl_signal_add(&cursor->events.swipe_end, &cursor_swipe_end); |
|
| 5513 | + | wl_signal_add(&cursor->events.pinch_begin, &cursor_pinch_begin); |
|
| 5514 | + | wl_signal_add(&cursor->events.pinch_update, &cursor_pinch_update); |
|
| 5515 | + | wl_signal_add(&cursor->events.pinch_end, &cursor_pinch_end); |
|
| 5516 | + | wl_signal_add(&cursor->events.hold_begin, &cursor_hold_begin); |
|
| 5517 | + | wl_signal_add(&cursor->events.hold_end, &cursor_hold_end); |
|
| 5402 | 5518 | ||
| 5403 | 5519 | cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); |
|
| 5404 | 5520 | wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_cursor_shape); |
|
| 5405 | 5521 | ||
| 5406 | 5522 | /* A seat groups the input devices controlled by one user. */ |