From 6f6fcbc2e1c8ba8b62c6bf3dfd494c8bde0bc57c Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Tue, 10 Jun 2025 19:37:17 +0200 Subject: [PATCH] input: move tablet tool functions into tablet.c Just a big move and a rename of the tablet tool destroy handler. --- include/input/tablet-tool.h | 40 ------------------ include/input/tablet.h | 28 +++++++++++++ src/input/cursor.c | 1 - src/input/meson.build | 1 - src/input/tablet-tool.c | 83 ------------------------------------- src/input/tablet.c | 74 ++++++++++++++++++++++++++++++++- 6 files changed, 101 insertions(+), 126 deletions(-) delete mode 100644 include/input/tablet-tool.h delete mode 100644 src/input/tablet-tool.c diff --git a/include/input/tablet-tool.h b/include/input/tablet-tool.h deleted file mode 100644 index 5ca94045..00000000 --- a/include/input/tablet-tool.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef LABWC_TABLET_TOOL_H -#define LABWC_TABLET_TOOL_H - -#include -#include - -struct seat; - -struct drawing_tablet_tool { - struct seat *seat; - struct wlr_tablet_v2_tablet_tool *tool_v2; - - /* - * Force mouse emulation just for a specific tool, - * even when global mouse emulation for tablet input - * is off. - */ - bool force_mouse_emulation; - - enum motion motion_mode; - double x, y, dx, dy; - double distance; - double pressure; - double tilt_x, tilt_y; - double rotation; - double slider; - double wheel_delta; - struct { - struct wl_listener set_cursor; - struct wl_listener destroy; - } handlers; - struct wl_list link; /* seat.tablet_tools */ -}; - -void tablet_tool_create(struct seat *seat, - struct wlr_tablet_tool *wlr_tablet_tool); -bool tablet_tool_has_focused_surface(struct seat *seat); - -#endif /* LABWC_TABLET_TOOL_H */ diff --git a/include/input/tablet.h b/include/input/tablet.h index 8ef465ee..55bdd0c9 100644 --- a/include/input/tablet.h +++ b/include/input/tablet.h @@ -9,6 +9,32 @@ struct seat; struct wlr_device; struct wlr_input_device; +struct drawing_tablet_tool { + struct seat *seat; + struct wlr_tablet_v2_tablet_tool *tool_v2; + + /* + * Force mouse emulation just for a specific tool, + * even when global mouse emulation for tablet input + * is off. + */ + bool force_mouse_emulation; + + enum motion motion_mode; + double x, y, dx, dy; + double distance; + double pressure; + double tilt_x, tilt_y; + double rotation; + double slider; + double wheel_delta; + struct { + struct wl_listener set_cursor; + struct wl_listener destroy; + } handlers; + struct wl_list link; /* seat.tablet_tools */ +}; + struct drawing_tablet { struct wlr_input_device *wlr_input_device; struct seat *seat; @@ -23,5 +49,7 @@ struct drawing_tablet { 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); +void tablet_tool_create(struct seat *seat, struct wlr_tablet_tool *wlr_tablet_tool); +bool tablet_tool_has_focused_surface(struct seat *seat); #endif /* LABWC_TABLET_H */ diff --git a/src/input/cursor.c b/src/input/cursor.c index 217f6be2..c9a22480 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -20,7 +20,6 @@ #include "input/gestures.h" #include "input/keyboard.h" #include "input/tablet.h" -#include "input/tablet-tool.h" #include "input/touch.h" #include "labwc.h" #include "layers.h" diff --git a/src/input/meson.build b/src/input/meson.build index a9a6f5e3..4d56f00d 100644 --- a/src/input/meson.build +++ b/src/input/meson.build @@ -2,7 +2,6 @@ labwc_sources += files( 'cursor.c', 'tablet.c', 'tablet-pad.c', - 'tablet-tool.c', 'gestures.c', 'input.c', 'keyboard.c', diff --git a/src/input/tablet-tool.c b/src/input/tablet-tool.c deleted file mode 100644 index fcc1e733..00000000 --- a/src/input/tablet-tool.c +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include -#include -#include -#include -#include -#include "common/macros.h" -#include "common/mem.h" -#include "config/rcxml.h" -#include "input/cursor.h" -#include "input/tablet-tool.h" -#include "labwc.h" - -bool -tablet_tool_has_focused_surface(struct seat *seat) -{ - struct drawing_tablet_tool *tool; - wl_list_for_each(tool, &seat->tablet_tools, link) { - if (tool->tool_v2->focused_surface) { - return true; - } - } - - return false; -} - -static void -handle_set_cursor(struct wl_listener *listener, void *data) -{ - struct drawing_tablet_tool *tool = - wl_container_of(listener, tool, handlers.set_cursor); - struct wlr_tablet_v2_event_cursor *ev = data; - - struct seat *seat = tool->seat; - struct wlr_seat_client *focused_client = - seat->seat->pointer_state.focused_client; - - if (seat->server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) { - return; - } - - if (ev->seat_client != focused_client) { - return; - } - - wlr_cursor_set_surface(seat->cursor, ev->surface, - ev->hotspot_x, ev->hotspot_y); -} - -static void -handle_destroy(struct wl_listener *listener, void *data) -{ - struct drawing_tablet_tool *tool = - wl_container_of(listener, tool, handlers.destroy); - - wl_list_remove(&tool->link); - wl_list_remove(&tool->handlers.set_cursor.link); - wl_list_remove(&tool->handlers.destroy.link); - free(tool); -} - -void -tablet_tool_create(struct seat *seat, - struct wlr_tablet_tool *wlr_tablet_tool) -{ - wlr_log(WLR_DEBUG, "setting up tablet tool"); - struct drawing_tablet_tool *tool = znew(*tool); - tool->seat = seat; - tool->tool_v2 = - wlr_tablet_tool_create(seat->server->tablet_manager, - seat->seat, wlr_tablet_tool); - wlr_tablet_tool->data = tool; - wlr_log(WLR_INFO, "tablet tool capabilities:%s%s%s%s%s%s", - wlr_tablet_tool->tilt ? " tilt" : "", - wlr_tablet_tool->pressure ? " pressure" : "", - wlr_tablet_tool->distance ? " distance" : "", - wlr_tablet_tool->rotation ? " rotation" : "", - wlr_tablet_tool->slider ? " slider" : "", - wlr_tablet_tool->wheel ? " wheel" : ""); - CONNECT_SIGNAL(tool->tool_v2, &tool->handlers, set_cursor); - CONNECT_SIGNAL(wlr_tablet_tool, &tool->handlers, destroy); - wl_list_insert(&seat->tablet_tools, &tool->link); -} diff --git a/src/input/tablet.c b/src/input/tablet.c index 47e69723..49d2aaeb 100644 --- a/src/input/tablet.c +++ b/src/input/tablet.c @@ -13,12 +13,84 @@ #include "config/mousebind.h" #include "input/cursor.h" #include "input/tablet.h" -#include "input/tablet-tool.h" #include "input/tablet-pad.h" #include "labwc.h" #include "idle.h" #include "action.h" +bool +tablet_tool_has_focused_surface(struct seat *seat) +{ + struct drawing_tablet_tool *tool; + wl_list_for_each(tool, &seat->tablet_tools, link) { + if (tool->tool_v2->focused_surface) { + return true; + } + } + + return false; +} + +static void +handle_set_cursor(struct wl_listener *listener, void *data) +{ + struct drawing_tablet_tool *tool = + wl_container_of(listener, tool, handlers.set_cursor); + struct wlr_tablet_v2_event_cursor *ev = data; + + struct seat *seat = tool->seat; + struct wlr_seat_client *focused_client = + seat->seat->pointer_state.focused_client; + + if (seat->server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) { + return; + } + + if (ev->seat_client != focused_client) { + return; + } + + wlr_cursor_set_surface(seat->cursor, ev->surface, + ev->hotspot_x, ev->hotspot_y); +} + +static void +handle_tablet_tool_destroy(struct wl_listener *listener, void *data) +{ + struct drawing_tablet_tool *tool = + wl_container_of(listener, tool, handlers.destroy); + + wl_list_remove(&tool->link); + wl_list_remove(&tool->handlers.set_cursor.link); + wl_list_remove(&tool->handlers.destroy.link); + free(tool); +} + +void +tablet_tool_create(struct seat *seat, + struct wlr_tablet_tool *wlr_tablet_tool) +{ + wlr_log(WLR_DEBUG, "setting up tablet tool"); + struct drawing_tablet_tool *tool = znew(*tool); + tool->seat = seat; + tool->tool_v2 = + wlr_tablet_tool_create(seat->server->tablet_manager, + seat->seat, wlr_tablet_tool); + wlr_tablet_tool->data = tool; + wlr_log(WLR_INFO, "tablet tool capabilities:%s%s%s%s%s%s", + wlr_tablet_tool->tilt ? " tilt" : "", + wlr_tablet_tool->pressure ? " pressure" : "", + wlr_tablet_tool->distance ? " distance" : "", + wlr_tablet_tool->rotation ? " rotation" : "", + wlr_tablet_tool->slider ? " slider" : "", + wlr_tablet_tool->wheel ? " wheel" : ""); + CONNECT_SIGNAL(tool->tool_v2, &tool->handlers, set_cursor); + wl_signal_add(&wlr_tablet_tool->events.destroy, &tool->handlers.destroy); + tool->handlers.destroy.notify = handle_tablet_tool_destroy; + + wl_list_insert(&seat->tablet_tools, &tool->link); +} + static enum motion tool_motion_mode(enum motion motion, struct wlr_tablet_tool *tool) { -- 2.52.0