use { jay_utils::{numcell::NumCell, static_text::StaticText}, linearize::Linearize, 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, Adaptive, } impl StaticText for InputDeviceAccelProfile { fn text(&self) -> &'static str { match self { InputDeviceAccelProfile::Flat => "Flat", InputDeviceAccelProfile::Adaptive => "Adaptive", } } } #[derive(Debug, Copy, Clone, PartialEq, Linearize)] pub enum InputDeviceClickMethod { None, ButtonAreas, Clickfinger, } impl StaticText for InputDeviceClickMethod { fn text(&self) -> &'static str { match self { InputDeviceClickMethod::None => "none", InputDeviceClickMethod::ButtonAreas => "button-areas", InputDeviceClickMethod::Clickfinger => "clickfinger", } } } #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Linearize)] pub enum InputDeviceCapability { Keyboard, Pointer, Touch, TabletTool, TabletPad, Gesture, Switch, } impl StaticText for InputDeviceCapability { fn text(&self) -> &'static str { match self { InputDeviceCapability::Keyboard => "keyboard", InputDeviceCapability::Pointer => "pointer", InputDeviceCapability::Touch => "touch", InputDeviceCapability::TabletTool => "tablet tool", InputDeviceCapability::TabletPad => "tablet pad", InputDeviceCapability::Gesture => "gesture", InputDeviceCapability::Switch => "switch", } } } linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize); #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum KeyState { Released, Pressed, Repeated, } #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum ButtonState { Released, Pressed, } #[derive(Debug, Copy, Clone, Eq, PartialEq, Linearize)] pub enum ScrollAxis { Vertical = 0, Horizontal = 1, } #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum AxisSource { Wheel, Finger, Continuous, } pub const AXIS_120: i32 = 120; #[derive(Debug, Copy, Clone, Default, Eq, PartialEq)] pub struct Leds(pub u32); pub const LED_NUM_LOCK: Leds = Leds(1 << 0); pub const LED_CAPS_LOCK: Leds = Leds(1 << 1); pub const LED_SCROLL_LOCK: Leds = Leds(1 << 2); pub const LED_COMPOSE: Leds = Leds(1 << 3); pub const LED_KANA: Leds = Leds(1 << 4); impl Leds { pub const fn none() -> Self { Self(0) } pub const fn raw(self) -> u32 { self.0 } } impl BitOr for Leds { type Output = Self; fn bitor(self, rhs: Self) -> Self::Output { Self(self.0 | rhs.0) } } impl BitOrAssign for Leds { fn bitor_assign(&mut self, rhs: Self) { 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, }