]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: add tablet pad setup and button handler
authorJens Peters <jp7677@gmail.com>
Tue, 2 Jan 2024 17:26:25 +0000 (18:26 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 2 Jan 2024 21:28:42 +0000 (21:28 +0000)
Split pad initialization from tablet initialization to
avoid conflicting handler names.
Also reuse 'get_mapped_button'.

include/input/tablet.h
include/input/tablet_pad.h [new file with mode: 0644]
src/input/meson.build
src/input/tablet.c
src/input/tablet_pad.c [new file with mode: 0644]
src/seat.c

index 4d6c50badc50bee9dac15e283759ecb53e7c690a..df8537d5ffcc4b776623b340d5d3f1418a23ede4 100644 (file)
@@ -20,6 +20,7 @@ struct drawing_tablet {
        } handlers;
 };
 
-void tablet_setup_handlers(struct seat *seat, struct wlr_input_device *wlr_input_device);
+uint32_t tablet_get_mapped_button(uint32_t src_button);
+void tablet_init(struct seat *seat, struct wlr_input_device *wlr_input_device);
 
 #endif /* LABWC_TABLET_H */
diff --git a/include/input/tablet_pad.h b/include/input/tablet_pad.h
new file mode 100644 (file)
index 0000000..144bec7
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LABWC_TABLET_PAD_H
+#define LABWC_TABLET_PAD_H
+
+#include <wayland-server-core.h>
+struct seat;
+struct wlr_device;
+struct wlr_input_device;
+
+struct drawing_tablet_pad {
+       struct seat *seat;
+       struct wlr_tablet_pad *tablet;
+       struct {
+               struct wl_listener button;
+               struct wl_listener destroy;
+       } handlers;
+};
+
+void tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_input_device);
+
+#endif /* LABWC_TABLET_PAD_H */
index 9b8b9a20d6aeca1e365b323903b2a0dabd4ed9e5..c8b7717c981f041788390049998e08d9fea5c281 100644 (file)
@@ -1,6 +1,7 @@
 labwc_sources += files(
   'cursor.c',
   'tablet.c',
+  'tablet_pad.c',
   'gestures.c',
   'input.c',
   'keyboard.c',
index 662ce0c70ffc7c2e65290cd481c503b6fc2b9bb5..0a24d619393397d383f14c0c4033183f4c2b5d2f 100644 (file)
@@ -86,8 +86,8 @@ handle_axis(struct wl_listener *listener, void *data)
        // Ignore other events
 }
 
-static uint32_t
-get_mapped_button(uint32_t src_button)
+uint32_t
+tablet_get_mapped_button(uint32_t src_button)
 {
        struct button_map_entry *map_entry;
        for (size_t i = 0; i < rc.tablet.button_map_count; i++) {
@@ -106,7 +106,7 @@ handle_tip(struct wl_listener *listener, void *data)
        struct wlr_tablet_tool_tip_event *ev = data;
        struct drawing_tablet *tablet = ev->tablet->data;
 
-       uint32_t button = get_mapped_button(BTN_TOOL_PEN);
+       uint32_t button = tablet_get_mapped_button(BTN_TOOL_PEN);
        if (!button) {
                return;
        }
@@ -125,7 +125,7 @@ handle_button(struct wl_listener *listener, void *data)
        struct wlr_tablet_tool_button_event *ev = data;
        struct drawing_tablet *tablet = ev->tablet->data;
 
-       uint32_t button = get_mapped_button(ev->button);
+       uint32_t button = tablet_get_mapped_button(ev->button);
        if (!button) {
                return;
        }
@@ -141,14 +141,8 @@ handle_destroy(struct wl_listener *listener, void *data)
        free(tablet);
 }
 
-static void
-setup_pad(struct seat *seat, struct wlr_input_device *wlr_device)
-{
-       wlr_log(WLR_INFO, "not setting up pad");
-}
-
-static void
-setup_pen(struct seat *seat, struct wlr_input_device *wlr_device)
+void
+tablet_init(struct seat *seat, struct wlr_input_device *wlr_device)
 {
        wlr_log(WLR_DEBUG, "setting up tablet");
        struct drawing_tablet *tablet = znew(*tablet);
@@ -164,18 +158,3 @@ setup_pen(struct seat *seat, struct wlr_input_device *wlr_device)
        CONNECT_SIGNAL(tablet->tablet, &tablet->handlers, button);
        CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy);
 }
-
-void
-tablet_setup_handlers(struct seat *seat, struct wlr_input_device *device)
-{
-       switch (device->type) {
-       case WLR_INPUT_DEVICE_TABLET_PAD:
-               setup_pad(seat, device);
-               break;
-       case WLR_INPUT_DEVICE_TABLET_TOOL:
-               setup_pen(seat, device);
-               break;
-       default:
-               assert(false && "tried to add non-tablet as tablet");
-       }
-}
diff --git a/src/input/tablet_pad.c b/src/input/tablet_pad.c
new file mode 100644 (file)
index 0000000..3c1b2a9
--- /dev/null
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <assert.h>
+#include <stdlib.h>
+#include <wlr/types/wlr_tablet_pad.h>
+#include <wlr/util/log.h>
+#include "common/macros.h"
+#include "common/mem.h"
+#include "config/rcxml.h"
+#include "input/cursor.h"
+#include "input/tablet.h"
+#include "input/tablet_pad.h"
+
+static void
+handle_button(struct wl_listener *listener, void *data)
+{
+       struct drawing_tablet_pad *tablet_pad =
+               wl_container_of(listener, tablet_pad, handlers.button);
+       struct wlr_tablet_pad_button_event *ev = data;
+
+       uint32_t button = tablet_get_mapped_button(ev->button);
+       if (!button) {
+               return;
+       }
+
+       cursor_emulate_button(tablet_pad->seat, button, ev->state, ev->time_msec);
+}
+
+static void
+handle_destroy(struct wl_listener *listener, void *data)
+{
+       struct drawing_tablet_pad *tablet =
+               wl_container_of(listener, tablet, handlers.destroy);
+       free(tablet);
+}
+
+void
+tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_device)
+{
+       wlr_log(WLR_DEBUG, "setting up tablet pad");
+       struct drawing_tablet_pad *tablet = znew(*tablet);
+       tablet->seat = seat;
+       tablet->tablet = wlr_tablet_pad_from_input_device(wlr_device);
+       tablet->tablet->data = tablet;
+       CONNECT_SIGNAL(tablet->tablet, &tablet->handlers, button);
+       CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy);
+}
index 2f207a90cce608790a0dc05c72613266cc2968f1..b8fb636dc86b01fb9a2aa46b1b1364664b81bb6b 100644 (file)
@@ -10,6 +10,7 @@
 #include <wlr/util/log.h>
 #include "common/mem.h"
 #include "input/tablet.h"
+#include "input/tablet_pad.h"
 #include "input/input.h"
 #include "input/keyboard.h"
 #include "input/key-state.h"
@@ -283,7 +284,17 @@ new_tablet(struct seat *seat, struct wlr_input_device *dev)
 {
        struct input *input = znew(*input);
        input->wlr_input_device = dev;
-       tablet_setup_handlers(seat, dev);
+       tablet_init(seat, dev);
+
+       return input;
+}
+
+static struct input *
+new_tablet_pad(struct seat *seat, struct wlr_input_device *dev)
+{
+       struct input *input = znew(*input);
+       input->wlr_input_device = dev;
+       tablet_pad_init(seat, dev);
 
        return input;
 }
@@ -341,6 +352,8 @@ new_input_notify(struct wl_listener *listener, void *data)
                input = new_touch(seat, device);
                break;
        case WLR_INPUT_DEVICE_TABLET_PAD:
+               input = new_tablet_pad(seat, device);
+               break;
        case WLR_INPUT_DEVICE_TABLET_TOOL:
                input = new_tablet(seat, device);
                break;