]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: support pointer gestures (pinch/swipe)
authorbi4k8 <bi4k8@github>
Fri, 31 Dec 2021 23:34:08 +0000 (23:34 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 1 Jan 2022 19:24:27 +0000 (19:24 +0000)
include/labwc.h
src/cursor.c

index 7459b455e5a43da5ac692ae56f8a5c8e21118d32..e6a579fcd6a2435fb9fd6b4bd1e5add41e9877e6 100644 (file)
@@ -30,6 +30,7 @@
 #include <wlr/types/wlr_relative_pointer_v1.h>
 #include <wlr/types/wlr_pointer.h>
 #include <wlr/types/wlr_pointer_constraints_v1.h>
+#include <wlr/types/wlr_pointer_gestures_v1.h>
 #include <wlr/types/wlr_seat.h>
 #include <wlr/types/wlr_server_decoration.h>
 #include <wlr/types/wlr_xcursor_manager.h>
@@ -87,6 +88,14 @@ struct seat {
        struct wl_listener cursor_axis;
        struct wl_listener cursor_frame;
 
+       struct wlr_pointer_gestures_v1 *pointer_gestures;
+       struct wl_listener pinch_begin;
+       struct wl_listener pinch_update;
+       struct wl_listener pinch_end;
+       struct wl_listener swipe_begin;
+       struct wl_listener swipe_update;
+       struct wl_listener swipe_end;
+
        struct wl_listener request_cursor;
        struct wl_listener request_set_selection;
        struct wl_listener request_set_primary_selection;
index a6a51418fd9705ffcb9f5c17279b6805300f568e..6c845004671505ef1c15ee4b20bedfa31a605eea 100644 (file)
@@ -675,6 +675,61 @@ cursor_frame(struct wl_listener *listener, void *data)
        wlr_seat_pointer_notify_frame(seat->seat);
 }
 
+static void handle_pointer_pinch_begin(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, pinch_begin);
+       struct wlr_event_pointer_pinch_begin *event = data;
+       wlr_pointer_gestures_v1_send_pinch_begin(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->fingers);
+}
+
+static void handle_pointer_pinch_update(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, pinch_update);
+       struct wlr_event_pointer_pinch_update *event = data;
+       wlr_pointer_gestures_v1_send_pinch_update(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->dx, event->dy,
+                       event->scale, event->rotation);
+}
+
+static void handle_pointer_pinch_end(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, pinch_end);
+       struct wlr_event_pointer_pinch_end *event = data;
+       wlr_pointer_gestures_v1_send_pinch_end(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->cancelled);
+}
+
+static void handle_pointer_swipe_begin(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, swipe_begin);
+       struct wlr_event_pointer_swipe_begin *event = data;
+       wlr_pointer_gestures_v1_send_swipe_begin(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->fingers);
+}
+
+static void handle_pointer_swipe_update(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, swipe_update);
+       struct wlr_event_pointer_swipe_update *event = data;
+       wlr_pointer_gestures_v1_send_swipe_update(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->dx, event->dy);
+}
+
+static void handle_pointer_swipe_end(struct wl_listener *listener, void *data) {
+       struct seat *seat = wl_container_of(
+                       listener, seat, swipe_end);
+       struct wlr_event_pointer_swipe_end *event = data;
+       wlr_pointer_gestures_v1_send_swipe_end(
+                       seat->pointer_gestures, seat->seat,
+                       event->time_msec, event->cancelled);
+}
+
 void
 cursor_init(struct seat *seat)
 {
@@ -697,6 +752,20 @@ cursor_init(struct seat *seat)
        seat->cursor_frame.notify = cursor_frame;
        wl_signal_add(&seat->cursor->events.frame, &seat->cursor_frame);
 
+       seat->pointer_gestures = wlr_pointer_gestures_v1_create(seat->server->wl_display);
+       seat->pinch_begin.notify = handle_pointer_pinch_begin;
+       wl_signal_add(&seat->cursor->events.pinch_begin, &seat->pinch_begin);
+       seat->pinch_update.notify = handle_pointer_pinch_update;
+       wl_signal_add(&seat->cursor->events.pinch_update, &seat->pinch_update);
+       seat->pinch_end.notify = handle_pointer_pinch_end;
+       wl_signal_add(&seat->cursor->events.pinch_end, &seat->pinch_end);
+       seat->swipe_begin.notify = handle_pointer_swipe_begin;
+       wl_signal_add(&seat->cursor->events.swipe_begin, &seat->swipe_begin);
+       seat->swipe_update.notify = handle_pointer_swipe_update;
+       wl_signal_add(&seat->cursor->events.swipe_update, &seat->swipe_update);
+       seat->swipe_end.notify = handle_pointer_swipe_end;
+       wl_signal_add(&seat->cursor->events.swipe_end, &seat->swipe_end);
+
        seat->request_cursor.notify = request_cursor_notify;
        wl_signal_add(&seat->seat->events.request_set_cursor,
                &seat->request_cursor);
@@ -724,6 +793,13 @@ void cursor_finish(struct seat *seat) {
        wl_list_remove(&seat->cursor_axis.link);
        wl_list_remove(&seat->cursor_frame.link);
 
+       wl_list_remove(&seat->pinch_begin.link);
+       wl_list_remove(&seat->pinch_update.link);
+       wl_list_remove(&seat->pinch_end.link);
+       wl_list_remove(&seat->swipe_begin.link);
+       wl_list_remove(&seat->swipe_update.link);
+       wl_list_remove(&seat->swipe_end.link);
+
        wl_list_remove(&seat->request_cursor.link);
        wl_list_remove(&seat->request_set_selection.link);