1
0
Fork 0
forked from wry/wry

input: decouple tablet contracts from wayland seat

This commit is contained in:
kossLAN 2026-05-29 12:42:59 -04:00
parent e996d9528a
commit 59e4e6dfb7
No known key found for this signature in database
6 changed files with 201 additions and 155 deletions

View file

@ -1,9 +1,57 @@
use { use {
jay_utils::static_text::StaticText, jay_utils::{numcell::NumCell, static_text::StaticText},
linearize::Linearize, 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)] #[derive(Debug, Copy, Clone, PartialEq, Linearize)]
pub enum InputDeviceAccelProfile { pub enum InputDeviceAccelProfile {
Flat, Flat,
@ -36,6 +84,8 @@ impl StaticText for InputDeviceClickMethod {
} }
} }
linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize);
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum KeyState { pub enum KeyState {
Released, Released,
@ -96,3 +146,126 @@ impl BitOrAssign for Leds {
self.0 |= rhs.0; 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<u32>,
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<TabletToolCapability>,
}
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<TabletPadGroupInit>,
}
#[derive(Debug, Clone)]
pub struct TabletPadGroupInit {
pub buttons: Vec<u32>,
pub rings: Vec<u32>,
pub strips: Vec<u32>,
pub dials: Vec<u32>,
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<bool>,
pub pos: Option<TabletTool2dChange<TabletToolPositionChange>>,
pub pressure: Option<f64>,
pub distance: Option<f64>,
pub tilt: Option<TabletTool2dChange<f64>>,
pub rotation: Option<f64>,
pub slider: Option<f64>,
pub wheel: Option<TabletToolWheelChange>,
}
#[derive(Copy, Clone, Debug)]
pub struct TabletTool2dChange<T> {
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,
}

View file

@ -10,16 +10,7 @@ use {
fixed::Fixed, fixed::Fixed,
format::Format, format::Format,
gfx_api::{FdSync, GfxApi, GfxFramebuffer}, gfx_api::{FdSync, GfxApi, GfxFramebuffer},
ifs::{ ifs::wl_output::OutputId,
wl_output::OutputId,
wl_seat::{
tablet::{
PadButtonState, TabletInit, TabletPadId, TabletPadInit, TabletRingEventSource,
TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit,
ToolButtonState,
},
},
},
libinput::consts::DeviceCapability, libinput::consts::DeviceCapability,
utils::static_text::StaticText, utils::static_text::StaticText,
video::drm::{ video::drm::{
@ -43,8 +34,12 @@ use {
pub mod transaction; pub mod transaction;
pub use jay_input_types::{ pub use jay_input_types::{
AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceClickMethod, KeyState, AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceClickMethod,
Leds, ScrollAxis, 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); linear_ids!(ConnectorIds, ConnectorId);
@ -209,8 +204,6 @@ pub trait HardwareCursor: Debug {
pub type TransformMatrix = [[f64; 2]; 2]; pub type TransformMatrix = [[f64; 2]; 2];
linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize);
pub trait InputDevice { pub trait InputDevice {
fn id(&self) -> InputDeviceId; fn id(&self) -> InputDeviceId;
fn removed(&self) -> bool; fn removed(&self) -> bool;

View file

@ -11,7 +11,8 @@ use {
backend::{ backend::{
Backend, ButtonState, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, Backend, ButtonState, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
InputDeviceClickMethod, InputDeviceGroupId, InputDeviceId, InputEvent, KeyState, Leds, InputDeviceClickMethod, InputDeviceGroupId, InputDeviceId, InputEvent, KeyState, Leds,
TransformMatrix, transaction::BackendConnectorTransactionError, TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit, TransformMatrix,
transaction::BackendConnectorTransactionError,
}, },
backends::metal::{ backends::metal::{
allocator::{RenderBufferError, ScanoutBufferError, ScanoutBufferErrors}, allocator::{RenderBufferError, ScanoutBufferError, ScanoutBufferErrors},
@ -23,12 +24,7 @@ use {
dbus::{DbusError, SignalHandler}, dbus::{DbusError, SignalHandler},
drm_feedback::DrmFeedback, drm_feedback::DrmFeedback,
gfx_api::{GfxError, SyncFile}, gfx_api::{GfxError, SyncFile},
ifs::{ ifs::wl_output::OutputId,
wl_output::OutputId,
wl_seat::tablet::{
TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit,
},
},
libinput::{ libinput::{
LibInput, LibInputAdapter, LibInputError, LibInput, LibInputAdapter, LibInputError,
consts::{ consts::{

View file

@ -1,13 +1,13 @@
use { use {
crate::{ crate::{
backend::{AxisSource, ButtonState, InputEvent, KeyState, ScrollAxis}, backend::{
backends::metal::MetalBackend, AxisSource, ButtonState, InputEvent, KeyState, PadButtonState, ScrollAxis,
fixed::Fixed, TabletRingEventSource, TabletStripEventSource, TabletTool2dChange,
ifs::wl_seat::tablet::{
PadButtonState, TabletRingEventSource, TabletStripEventSource, TabletTool2dChange,
TabletToolCapability, TabletToolChanges, TabletToolId, TabletToolInit, TabletToolCapability, TabletToolChanges, TabletToolId, TabletToolInit,
TabletToolPositionChange, TabletToolType, TabletToolWheelChange, ToolButtonState, TabletToolPositionChange, TabletToolType, TabletToolWheelChange, ToolButtonState,
}, },
backends::metal::MetalBackend,
fixed::Fixed,
libinput::{ libinput::{
consts::{ consts::{
LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_BUTTON_STATE_RELEASED, LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_BUTTON_STATE_RELEASED,

View file

@ -1,6 +1,6 @@
use { use {
crate::{ crate::{
backend::{InputDeviceGroupId, InputDeviceId}, backend::InputDeviceId,
cursor_user::CursorUser, cursor_user::CursorUser,
ifs::{ ifs::{
wl_seat::{ 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;
mod pad_owner; mod pad_owner;
mod tablet_bindings; mod tablet_bindings;
@ -53,63 +62,6 @@ pub struct TabletSeatData {
pads: CopyHashMap<TabletPadId, Rc<TabletPad>>, pads: CopyHashMap<TabletPadId, Rc<TabletPad>>,
} }
#[derive(Debug, Clone)]
pub struct TabletInit {
pub id: TabletId,
pub group: InputDeviceGroupId,
pub name: String,
pub pid: u32,
pub vid: u32,
pub bustype: Option<u32>,
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<TabletToolCapability>,
}
#[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<TabletPadGroupInit>,
}
#[derive(Debug, Clone)]
pub struct TabletPadGroupInit {
pub buttons: Vec<u32>,
pub rings: Vec<u32>,
pub strips: Vec<u32>,
pub dials: Vec<u32>,
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 { pub struct Tablet {
_id: TabletId, _id: TabletId,
dev: InputDeviceId, dev: InputDeviceId,
@ -126,31 +78,6 @@ pub struct Tablet {
seat: Rc<WlSeatGlobal>, seat: Rc<WlSeatGlobal>,
} }
#[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)] #[derive(Default)]
pub struct TabletToolOpt { pub struct TabletToolOpt {
tool: CloneCell<Option<Rc<TabletTool>>>, tool: CloneCell<Option<Rc<TabletTool>>>,
@ -178,8 +105,6 @@ pub struct TabletTool {
slider: Cell<f64>, slider: Cell<f64>,
} }
linear_ids!(TabletPadIds, TabletPadId);
pub struct TabletPad { pub struct TabletPad {
pub id: TabletPadId, pub id: TabletPadId,
dev: InputDeviceId, dev: InputDeviceId,
@ -219,46 +144,6 @@ pub struct TabletPadDial {
bindings: TabletBindings<ZwpTabletPadDialV2>, bindings: TabletBindings<ZwpTabletPadDialV2>,
} }
#[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<bool>,
pub pos: Option<TabletTool2dChange<TabletToolPositionChange>>,
pub pressure: Option<f64>,
pub distance: Option<f64>,
pub tilt: Option<TabletTool2dChange<f64>>,
pub rotation: Option<f64>,
pub slider: Option<f64>,
pub wheel: Option<TabletToolWheelChange>,
}
#[derive(Copy, Clone, Debug)]
pub struct TabletTool2dChange<T> {
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 { impl WlSeatGlobal {
fn tablet_add_seat(&self, seat: &Rc<ZwpTabletSeatV2>) { fn tablet_add_seat(&self, seat: &Rc<ZwpTabletSeatV2>) {
self.tablet.seats.add(&seat.client, seat); self.tablet.seats.add(&seat.client, seat);

View file

@ -18,7 +18,7 @@ use {
Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice, Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice,
BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds,
HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds, HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds,
MonitorInfo, MonitorInfo, TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds,
transaction::{BackendConnectorTransactionError, ConnectorTransaction}, transaction::{BackendConnectorTransactionError, ConnectorTransaction},
}, },
backends::dummy::DummyBackend, backends::dummy::DummyBackend,
@ -76,7 +76,6 @@ use {
wl_seat::{ wl_seat::{
PhysicalKeyboardId, PhysicalKeyboardIds, PositionHintRequest, SeatIds, PhysicalKeyboardId, PhysicalKeyboardIds, PositionHintRequest, SeatIds,
WlSeatGlobal, WlSeatGlobal,
tablet::{TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds},
}, },
wl_surface::{ wl_surface::{
NoneSurfaceExt, NoneSurfaceExt,