]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Move gesture handling out of cursor.c
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 3 Sep 2023 16:56:20 +0000 (18:56 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 30 Oct 2023 21:14:04 +0000 (21:14 +0000)
include/input/gestures.h [new file with mode: 0644]
include/labwc.h
src/input/cursor.c
src/input/gestures.c [new file with mode: 0644]
src/input/meson.build

diff --git a/include/input/gestures.h b/include/input/gestures.h
new file mode 100644 (file)
index 0000000..2c161b7
--- /dev/null
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LABWC_GESTURES_H
+#define LABWC_GESTURES_H
+
+struct seat;
+
+void gestures_init(struct seat *seat);
+void gestures_finish(struct seat *seat);
+
+#endif /* LABWC_GESTURES_H */
index 9810ac1a272abdcdf5e2324ce217bae22d641b41..ebabb3c6c66ee4ff47e34d61ad7b4228c2fe764c 100644 (file)
@@ -30,7 +30,6 @@
 #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_subcompositor.h>
 #include <wlr/types/wlr_xcursor_manager.h>
index 5261fb30428cebdc85546e82a2d551ac3f47ac0d..c227594438c234c76a8cd88e7b728442eeb00d74 100644 (file)
@@ -13,6 +13,7 @@
 #include "config/mousebind.h"
 #include "dnd.h"
 #include "idle.h"
+#include "input/gestures.h"
 #include "labwc.h"
 #include "menu/menu.h"
 #include "regions.h"
@@ -1140,55 +1141,6 @@ 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_pointer_pinch_begin_event *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_pointer_pinch_update_event *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_pointer_pinch_end_event *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_pointer_swipe_begin_event *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_pointer_swipe_update_event *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_pointer_swipe_end_event *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)
 {
@@ -1248,19 +1200,7 @@ 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);
+       gestures_init(seat);
 
        seat->request_cursor.notify = request_cursor_notify;
        wl_signal_add(&seat->seat->events.request_set_cursor,
@@ -1285,12 +1225,7 @@ 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);
+       gestures_finish(seat);
 
        wl_list_remove(&seat->request_cursor.link);
        wl_list_remove(&seat->request_set_selection.link);
diff --git a/src/input/gestures.c b/src/input/gestures.c
new file mode 100644 (file)
index 0000000..f0ea51b
--- /dev/null
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <wlr/types/wlr_pointer_gestures_v1.h>
+#include "input/gestures.h"
+#include "labwc.h"
+
+static void
+handle_pointer_pinch_begin(struct wl_listener *listener, void *data)
+{
+       struct seat *seat = wl_container_of(listener, seat, pinch_begin);
+       struct wlr_pointer_pinch_begin_event *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_pointer_pinch_update_event *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_pointer_pinch_end_event *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_pointer_swipe_begin_event *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_pointer_swipe_update_event *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_pointer_swipe_end_event *event = data;
+       wlr_pointer_gestures_v1_send_swipe_end(seat->pointer_gestures,
+               seat->seat, event->time_msec, event->cancelled);
+}
+
+void
+gestures_init(struct seat *seat)
+{
+       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);
+}
+
+void
+gestures_finish(struct seat *seat)
+{
+       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);
+}
index e83de9d044c47841a848e02521c7711ee0a1a964..8444656bbc069f86bc5ebb3669cfa1d83adaf9d5 100644 (file)
@@ -1,6 +1,7 @@
 labwc_sources += files(
+  'cursor.c',
+  'gestures.c',
   'keyboard.c',
   'key-state.c',
   'touch.c',
-  'cursor.c',
 )