From 59e4e6dfb74c8f203de073f53a53c09933da2438 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 12:42:59 -0400 Subject: [PATCH] input: decouple tablet contracts from wayland seat --- input-types/src/lib.rs | 177 +++++++++++++++++++++++++++++++++++- src/backend.rs | 21 ++--- src/backends/metal.rs | 10 +- src/backends/metal/input.rs | 10 +- src/ifs/wl_seat/tablet.rs | 135 ++------------------------- src/state.rs | 3 +- 6 files changed, 201 insertions(+), 155 deletions(-) diff --git a/input-types/src/lib.rs b/input-types/src/lib.rs index 92f7d4d5..81eadb4c 100644 --- a/input-types/src/lib.rs +++ b/input-types/src/lib.rs @@ -1,9 +1,57 @@ use { - jay_utils::static_text::StaticText, + jay_utils::{numcell::NumCell, static_text::StaticText}, linearize::Linearize, - std::ops::{BitOr, BitOrAssign}, + std::{ + fmt::{Display, Formatter}, + ops::{BitOr, BitOrAssign}, + }, }; +macro_rules! linear_ids { + ($ids:ident, $id:ident $(,)?) => { + linear_ids!($ids, $id, u32); + }; + ($ids:ident, $id:ident, $ty:ty $(,)?) => { + #[derive(Debug)] + pub struct $ids { + next: NumCell<$ty>, + } + + impl Default for $ids { + fn default() -> Self { + Self { + next: NumCell::new(1), + } + } + } + + impl $ids { + pub fn next(&self) -> $id { + $id(self.next.fetch_add(1)) + } + } + + #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] + pub struct $id($ty); + + impl $id { + pub fn raw(&self) -> $ty { + self.0 + } + + pub fn from_raw(id: $ty) -> Self { + Self(id) + } + } + + impl Display for $id { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Display::fmt(&self.0, f) + } + } + }; +} + #[derive(Debug, Copy, Clone, PartialEq, Linearize)] pub enum InputDeviceAccelProfile { Flat, @@ -36,6 +84,8 @@ impl StaticText for InputDeviceClickMethod { } } +linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize); + #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum KeyState { Released, @@ -96,3 +146,126 @@ impl BitOrAssign for Leds { self.0 |= rhs.0; } } + +linear_ids!(TabletIds, TabletId); + +#[derive(Debug, Clone)] +pub struct TabletInit { + pub id: TabletId, + pub group: InputDeviceGroupId, + pub name: String, + pub pid: u32, + pub vid: u32, + pub bustype: Option, + pub path: String, +} + +linear_ids!(TabletToolIds, TabletToolId, usize); + +#[derive(Debug, Clone)] +pub struct TabletToolInit { + pub tablet_id: TabletId, + pub id: TabletToolId, + pub type_: TabletToolType, + pub hardware_serial: u64, + pub hardware_id_wacom: u64, + pub capabilities: Vec, +} + +linear_ids!(TabletPadIds, TabletPadId); + +#[derive(Debug, Clone)] +pub struct TabletPadInit { + pub id: TabletPadId, + pub group: InputDeviceGroupId, + pub path: String, + pub buttons: u32, + pub strips: u32, + pub rings: u32, + pub dials: u32, + pub groups: Vec, +} + +#[derive(Debug, Clone)] +pub struct TabletPadGroupInit { + pub buttons: Vec, + pub rings: Vec, + pub strips: Vec, + pub dials: Vec, + pub modes: u32, + pub mode: u32, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum PadButtonState { + Released, + Pressed, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum ToolButtonState { + Released, + Pressed, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum TabletToolType { + Pen, + Eraser, + Brush, + Pencil, + Airbrush, + Finger, + Mouse, + Lens, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum TabletToolCapability { + Tilt, + Pressure, + Distance, + Rotation, + Slider, + Wheel, +} + +#[derive(Copy, Clone, Debug)] +pub enum TabletRingEventSource { + Finger, +} + +#[derive(Copy, Clone, Debug)] +pub enum TabletStripEventSource { + Finger, +} + +#[derive(Debug, Default)] +pub struct TabletToolChanges { + pub down: Option, + pub pos: Option>, + pub pressure: Option, + pub distance: Option, + pub tilt: Option>, + pub rotation: Option, + pub slider: Option, + pub wheel: Option, +} + +#[derive(Copy, Clone, Debug)] +pub struct TabletTool2dChange { + pub x: T, + pub y: T, +} + +#[derive(Copy, Clone, Debug)] +pub struct TabletToolPositionChange { + pub x: f64, + pub dx: f64, +} + +#[derive(Copy, Clone, Debug)] +pub struct TabletToolWheelChange { + pub degrees: f64, + pub clicks: i32, +} diff --git a/src/backend.rs b/src/backend.rs index 34fc2bbc..55aa6e8e 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -10,16 +10,7 @@ use { fixed::Fixed, format::Format, gfx_api::{FdSync, GfxApi, GfxFramebuffer}, - ifs::{ - wl_output::OutputId, - wl_seat::{ - tablet::{ - PadButtonState, TabletInit, TabletPadId, TabletPadInit, TabletRingEventSource, - TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit, - ToolButtonState, - }, - }, - }, + ifs::wl_output::OutputId, libinput::consts::DeviceCapability, utils::static_text::StaticText, video::drm::{ @@ -43,8 +34,12 @@ use { pub mod transaction; pub use jay_input_types::{ - AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceClickMethod, KeyState, - Leds, ScrollAxis, + AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceClickMethod, + InputDeviceGroupId, InputDeviceGroupIds, KeyState, Leds, PadButtonState, ScrollAxis, TabletId, + TabletIds, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadIds, TabletPadInit, + TabletRingEventSource, TabletStripEventSource, TabletTool2dChange, TabletToolCapability, + TabletToolChanges, TabletToolId, TabletToolIds, TabletToolInit, TabletToolPositionChange, + TabletToolType, TabletToolWheelChange, ToolButtonState, }; linear_ids!(ConnectorIds, ConnectorId); @@ -209,8 +204,6 @@ pub trait HardwareCursor: Debug { pub type TransformMatrix = [[f64; 2]; 2]; -linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize); - pub trait InputDevice { fn id(&self) -> InputDeviceId; fn removed(&self) -> bool; diff --git a/src/backends/metal.rs b/src/backends/metal.rs index 3bdc7422..7f2cdb09 100644 --- a/src/backends/metal.rs +++ b/src/backends/metal.rs @@ -11,7 +11,8 @@ use { backend::{ Backend, ButtonState, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceClickMethod, InputDeviceGroupId, InputDeviceId, InputEvent, KeyState, Leds, - TransformMatrix, transaction::BackendConnectorTransactionError, + TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit, TransformMatrix, + transaction::BackendConnectorTransactionError, }, backends::metal::{ allocator::{RenderBufferError, ScanoutBufferError, ScanoutBufferErrors}, @@ -23,12 +24,7 @@ use { dbus::{DbusError, SignalHandler}, drm_feedback::DrmFeedback, gfx_api::{GfxError, SyncFile}, - ifs::{ - wl_output::OutputId, - wl_seat::tablet::{ - TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit, - }, - }, + ifs::wl_output::OutputId, libinput::{ LibInput, LibInputAdapter, LibInputError, consts::{ diff --git a/src/backends/metal/input.rs b/src/backends/metal/input.rs index baa05259..3e9d8107 100644 --- a/src/backends/metal/input.rs +++ b/src/backends/metal/input.rs @@ -1,13 +1,13 @@ use { crate::{ - backend::{AxisSource, ButtonState, InputEvent, KeyState, ScrollAxis}, - backends::metal::MetalBackend, - fixed::Fixed, - ifs::wl_seat::tablet::{ - PadButtonState, TabletRingEventSource, TabletStripEventSource, TabletTool2dChange, + backend::{ + AxisSource, ButtonState, InputEvent, KeyState, PadButtonState, ScrollAxis, + TabletRingEventSource, TabletStripEventSource, TabletTool2dChange, TabletToolCapability, TabletToolChanges, TabletToolId, TabletToolInit, TabletToolPositionChange, TabletToolType, TabletToolWheelChange, ToolButtonState, }, + backends::metal::MetalBackend, + fixed::Fixed, libinput::{ consts::{ LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_BUTTON_STATE_RELEASED, diff --git a/src/ifs/wl_seat/tablet.rs b/src/ifs/wl_seat/tablet.rs index 3148f040..b68a47db 100644 --- a/src/ifs/wl_seat/tablet.rs +++ b/src/ifs/wl_seat/tablet.rs @@ -1,6 +1,6 @@ use { crate::{ - backend::{InputDeviceGroupId, InputDeviceId}, + backend::InputDeviceId, cursor_user::CursorUser, ifs::{ wl_seat::{ @@ -30,6 +30,15 @@ use { }, }; +#[allow(unused_imports)] +pub use jay_input_types::{ + InputDeviceGroupId, PadButtonState, TabletId, TabletIds, TabletInit, TabletPadGroupInit, + TabletPadId, TabletPadIds, TabletPadInit, TabletRingEventSource, TabletStripEventSource, + TabletTool2dChange, TabletToolCapability, TabletToolChanges, TabletToolId, TabletToolIds, + TabletToolInit, TabletToolPositionChange, TabletToolType, TabletToolWheelChange, + ToolButtonState, +}; + mod pad; mod pad_owner; mod tablet_bindings; @@ -53,63 +62,6 @@ pub struct TabletSeatData { pads: CopyHashMap>, } -#[derive(Debug, Clone)] -pub struct TabletInit { - pub id: TabletId, - pub group: InputDeviceGroupId, - pub name: String, - pub pid: u32, - pub vid: u32, - pub bustype: Option, - pub path: String, -} - -#[derive(Debug, Clone)] -pub struct TabletToolInit { - pub tablet_id: TabletId, - pub id: TabletToolId, - pub type_: TabletToolType, - pub hardware_serial: u64, - pub hardware_id_wacom: u64, - pub capabilities: Vec, -} - -#[derive(Debug, Clone)] -pub struct TabletPadInit { - pub id: TabletPadId, - pub group: InputDeviceGroupId, - pub path: String, - pub buttons: u32, - pub strips: u32, - pub rings: u32, - pub dials: u32, - pub groups: Vec, -} - -#[derive(Debug, Clone)] -pub struct TabletPadGroupInit { - pub buttons: Vec, - pub rings: Vec, - pub strips: Vec, - pub dials: Vec, - pub modes: u32, - pub mode: u32, -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum PadButtonState { - Released, - Pressed, -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum ToolButtonState { - Released, - Pressed, -} - -linear_ids!(TabletIds, TabletId); - pub struct Tablet { _id: TabletId, dev: InputDeviceId, @@ -126,31 +78,6 @@ pub struct Tablet { seat: Rc, } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum TabletToolType { - Pen, - Eraser, - Brush, - Pencil, - Airbrush, - #[expect(dead_code)] - Finger, - Mouse, - Lens, -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum TabletToolCapability { - Tilt, - Pressure, - Distance, - Rotation, - Slider, - Wheel, -} - -linear_ids!(TabletToolIds, TabletToolId, usize); - #[derive(Default)] pub struct TabletToolOpt { tool: CloneCell>>, @@ -178,8 +105,6 @@ pub struct TabletTool { slider: Cell, } -linear_ids!(TabletPadIds, TabletPadId); - pub struct TabletPad { pub id: TabletPadId, dev: InputDeviceId, @@ -219,46 +144,6 @@ pub struct TabletPadDial { bindings: TabletBindings, } -#[derive(Copy, Clone, Debug)] -pub enum TabletRingEventSource { - Finger, -} - -#[derive(Copy, Clone, Debug)] -pub enum TabletStripEventSource { - Finger, -} - -#[derive(Debug, Default)] -pub struct TabletToolChanges { - pub down: Option, - pub pos: Option>, - pub pressure: Option, - pub distance: Option, - pub tilt: Option>, - pub rotation: Option, - pub slider: Option, - pub wheel: Option, -} - -#[derive(Copy, Clone, Debug)] -pub struct TabletTool2dChange { - pub x: T, - pub y: T, -} - -#[derive(Copy, Clone, Debug)] -pub struct TabletToolPositionChange { - pub x: f64, - pub dx: f64, -} - -#[derive(Copy, Clone, Debug)] -pub struct TabletToolWheelChange { - pub degrees: f64, - pub clicks: i32, -} - impl WlSeatGlobal { fn tablet_add_seat(&self, seat: &Rc) { self.tablet.seats.add(&seat.client, seat); diff --git a/src/state.rs b/src/state.rs index 6ec3475c..46ecbcfc 100644 --- a/src/state.rs +++ b/src/state.rs @@ -18,7 +18,7 @@ use { Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice, BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds, - MonitorInfo, + MonitorInfo, TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds, transaction::{BackendConnectorTransactionError, ConnectorTransaction}, }, backends::dummy::DummyBackend, @@ -76,7 +76,6 @@ use { wl_seat::{ PhysicalKeyboardId, PhysicalKeyboardIds, PositionHintRequest, SeatIds, WlSeatGlobal, - tablet::{TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds}, }, wl_surface::{ NoneSurfaceExt,