]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: move cursor event listeners from tablet to seat
authorJens Peters <jp7677@gmail.com>
Fri, 9 Aug 2024 07:25:00 +0000 (09:25 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 13 Aug 2024 16:40:34 +0000 (18:40 +0200)
Otherwise we would subscribe multiple times to the
same event when having multiple tablets.

include/input/tablet-pad.h
include/input/tablet-tool.h
include/input/tablet.h
include/labwc.h
src/input/cursor.c
src/input/tablet-pad.c
src/input/tablet-tool.c
src/input/tablet.c
src/seat.c

index 4f39239f2a1c68381502742ac209bcd7ea2e3c43..3ada763418882d1a7a63513dc40527a228132612 100644 (file)
@@ -36,7 +36,7 @@ struct drawing_tablet_pad {
        struct wl_list link; /* seat.tablet_pads */
 };
 
-void tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_input_device);
+void tablet_pad_create(struct seat *seat, struct wlr_input_device *wlr_input_device);
 void tablet_pad_attach_tablet(struct seat *seat);
 void tablet_pad_enter_surface(struct seat *seat, struct wlr_surface *wlr_surface);
 
index 8f7b589df1bdab55238f5c88c1966511c2f1095d..7630687768f65f48c821674c1358be09287c2375 100644 (file)
@@ -17,7 +17,7 @@ struct drawing_tablet_tool {
        struct wl_list link; /* seat.tablet_tools */
 };
 
-void tablet_tool_init(struct seat *seat,
+void tablet_tool_create(struct seat *seat,
        struct wlr_tablet_tool *wlr_tablet_tool);
 bool tablet_tool_has_focused_surface(struct seat *seat);
 
index 0ca11fae8a270720b49db9fb60c07365465094e5..e9145636c3a920613bf93ce2ec9690511bd12e75 100644 (file)
@@ -23,15 +23,13 @@ struct drawing_tablet {
        double slider;
        double wheel_delta;
        struct {
-               struct wl_listener tablet_tool_proximity;
-               struct wl_listener tablet_tool_axis;
-               struct wl_listener tablet_tool_tip;
-               struct wl_listener tablet_tool_button;
                struct wl_listener destroy;
        } handlers;
        struct wl_list link; /* seat.tablets */
 };
 
-void tablet_init(struct seat *seat, struct wlr_input_device *wlr_input_device);
+void tablet_init(struct seat *seat);
+void tablet_finish(struct seat *seat);
+void tablet_create(struct seat *seat, struct wlr_input_device *wlr_input_device);
 
 #endif /* LABWC_TABLET_H */
index 1e577c8654ef0187c48ba7ec2efb11ac7c04a36e..14ce607c90c358d25400deb090ce509f1d02d320 100644 (file)
@@ -192,6 +192,11 @@ struct seat {
        struct wl_listener touch_motion;
        struct wl_listener touch_frame;
 
+       struct wl_listener tablet_tool_proximity;
+       struct wl_listener tablet_tool_axis;
+       struct wl_listener tablet_tool_tip;
+       struct wl_listener tablet_tool_button;
+
        struct wl_list tablets;
        struct wl_list tablet_tools;
        struct wl_list tablet_pads;
index 94e23fdde88316c74fd66903302785c905759e67..3b2583f018694cba0623dfc5eb2cc95529f15d30 100644 (file)
 #include "common/scene-helpers.h"
 #include "common/surface-helpers.h"
 #include "config/mousebind.h"
+#include "config/tablet-tool.h"
 #include "dnd.h"
 #include "idle.h"
 #include "input/gestures.h"
 #include "input/touch.h"
+#include "input/tablet.h"
 #include "input/tablet-tool.h"
-#include "input/tablet-pad.h"
 #include "labwc.h"
 #include "layers.h"
 #include "menu/menu.h"
@@ -1450,6 +1451,8 @@ cursor_init(struct seat *seat)
        gestures_init(seat);
        touch_init(seat);
 
+       tablet_init(seat);
+
        seat->request_cursor.notify = request_cursor_notify;
        wl_signal_add(&seat->seat->events.request_set_cursor,
                &seat->request_cursor);
@@ -1488,6 +1491,8 @@ void cursor_finish(struct seat *seat)
        gestures_finish(seat);
        touch_finish(seat);
 
+       tablet_finish(seat);
+
        wl_list_remove(&seat->request_cursor.link);
        wl_list_remove(&seat->request_set_shape.link);
        wl_list_remove(&seat->request_set_selection.link);
index c5381ef1a67c8218a79d98e530fd1453baf782a6..2453be96b9dfd2601e6441fec3a3726aea8be452 100644 (file)
@@ -175,7 +175,7 @@ handle_destroy(struct wl_listener *listener, void *data)
 }
 
 void
-tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_device)
+tablet_pad_create(struct seat *seat, struct wlr_input_device *wlr_device)
 {
        wlr_log(WLR_DEBUG, "setting up tablet pad");
        struct drawing_tablet_pad *pad = znew(*pad);
index 3e36f5b07e03f4e81513c31d4237021c001e1d07..fcc1e7330aabba3a93747e99f76b9f23fb7b74b0 100644 (file)
@@ -60,7 +60,7 @@ handle_destroy(struct wl_listener *listener, void *data)
 }
 
 void
-tablet_tool_init(struct seat *seat,
+tablet_tool_create(struct seat *seat,
                struct wlr_tablet_tool *wlr_tablet_tool)
 {
        wlr_log(WLR_DEBUG, "setting up tablet tool");
index 1d280e717b0aa203527f411a858b272da7daac54..489da6fa62e535429147b0f1b084c4bc52819235 100644 (file)
@@ -266,7 +266,7 @@ handle_tablet_tool_proximity(struct wl_listener *listener, void *data)
                 * Unfortunately `wlr_tool` is only present in the events, so
                 * use proximity for creating a `wlr_tablet_v2_tablet_tool`.
                 */
-               tablet_tool_init(tablet->seat, ev->tool);
+               tablet_tool_create(tablet->seat, ev->tool);
        }
 
        /*
@@ -604,16 +604,12 @@ handle_destroy(struct wl_listener *listener, void *data)
        wl_list_remove(&tablet->link);
        tablet_pad_attach_tablet(tablet->seat);
 
-       wl_list_remove(&tablet->handlers.tablet_tool_tip.link);
-       wl_list_remove(&tablet->handlers.tablet_tool_button.link);
-       wl_list_remove(&tablet->handlers.tablet_tool_proximity.link);
-       wl_list_remove(&tablet->handlers.tablet_tool_axis.link);
        wl_list_remove(&tablet->handlers.destroy.link);
        free(tablet);
 }
 
 void
-tablet_init(struct seat *seat, struct wlr_input_device *wlr_device)
+tablet_create(struct seat *seat, struct wlr_input_device *wlr_device)
 {
        wlr_log(WLR_DEBUG, "setting up tablet");
        struct drawing_tablet *tablet = znew(*tablet);
@@ -636,12 +632,26 @@ tablet_init(struct seat *seat, struct wlr_input_device *wlr_device)
        tablet->wheel_delta = 0.0;
        wlr_log(WLR_INFO, "tablet dimensions: %.2fmm x %.2fmm",
                tablet->tablet->width_mm, tablet->tablet->height_mm);
-       CONNECT_SIGNAL(seat->cursor, &tablet->handlers, tablet_tool_axis);
-       CONNECT_SIGNAL(seat->cursor, &tablet->handlers, tablet_tool_proximity);
-       CONNECT_SIGNAL(seat->cursor, &tablet->handlers, tablet_tool_tip);
-       CONNECT_SIGNAL(seat->cursor, &tablet->handlers, tablet_tool_button);
        CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy);
 
        wl_list_insert(&seat->tablets, &tablet->link);
        tablet_pad_attach_tablet(tablet->seat);
 }
+
+void
+tablet_init(struct seat *seat)
+{
+       CONNECT_SIGNAL(seat->cursor, seat, tablet_tool_axis);
+       CONNECT_SIGNAL(seat->cursor, seat, tablet_tool_proximity);
+       CONNECT_SIGNAL(seat->cursor, seat, tablet_tool_tip);
+       CONNECT_SIGNAL(seat->cursor, seat, tablet_tool_button);
+}
+
+void
+tablet_finish(struct seat *seat)
+{
+       wl_list_remove(&seat->tablet_tool_axis.link);
+       wl_list_remove(&seat->tablet_tool_proximity.link);
+       wl_list_remove(&seat->tablet_tool_tip.link);
+       wl_list_remove(&seat->tablet_tool_button.link);
+}
index 7987b5a32f38ac10c7253f87dfa2447307bff699..49f317cccb5408a0bee6ecc3986d4aa52ec7d3e6 100644 (file)
@@ -367,7 +367,7 @@ new_tablet(struct seat *seat, struct wlr_input_device *dev)
 {
        struct input *input = znew(*input);
        input->wlr_input_device = dev;
-       tablet_init(seat, dev);
+       tablet_create(seat, dev);
        wlr_cursor_attach_input_device(seat->cursor, dev);
        wlr_log(WLR_INFO, "map tablet to output %s\n", rc.tablet.output_name);
        map_input_to_output(seat, dev, rc.tablet.output_name);
@@ -380,7 +380,7 @@ 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);
+       tablet_pad_create(seat, dev);
 
        return input;
 }