From 151dc313ba2172574fda6a3be95454af51494a1e Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 12:03:45 -0400 Subject: [PATCH] input: move shared types into workspace crate --- Cargo.lock | 9 ++++ Cargo.toml | 2 + input-types/Cargo.toml | 12 ++++++ input-types/src/lib.rs | 98 ++++++++++++++++++++++++++++++++++++++++++ src/backend.rs | 75 +++----------------------------- 5 files changed, 126 insertions(+), 70 deletions(-) create mode 100644 input-types/Cargo.toml create mode 100644 input-types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 17cae948..ad7509e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,6 +738,7 @@ dependencies = [ "jay-formats", "jay-geometry", "jay-gfx-types", + "jay-input-types", "jay-io-uring", "jay-layout-animation", "jay-libinput", @@ -908,6 +909,14 @@ dependencies = [ "uapi", ] +[[package]] +name = "jay-input-types" +version = "0.1.0" +dependencies = [ + "jay-utils", + "linearize", +] + [[package]] name = "jay-io-uring" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ad1de779..ff0339e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ members = [ "bugs", "logger", "video-types", + "input-types", "gfx-types", "theme", "clientmem", @@ -97,6 +98,7 @@ jay-pr-caps = { version = "0.1.0", path = "pr-caps" } jay-bugs = { version = "0.1.0", path = "bugs" } jay-logger = { version = "0.1.0", path = "logger" } jay-video-types = { version = "0.1.0", path = "video-types" } +jay-input-types = { version = "0.1.0", path = "input-types" } jay-gfx-types = { version = "0.1.0", path = "gfx-types" } jay-theme = { version = "0.1.0", path = "theme" } jay-clientmem = { version = "0.1.0", path = "clientmem" } diff --git a/input-types/Cargo.toml b/input-types/Cargo.toml new file mode 100644 index 00000000..9d58f348 --- /dev/null +++ b/input-types/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "jay-input-types" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" +description = "Input data types for the Jay compositor" +repository = "https://github.com/mahkoh/jay" + +[dependencies] +jay-utils = { version = "0.1.0", path = "../utils" } + +linearize = { version = "0.1.3", features = ["derive"] } diff --git a/input-types/src/lib.rs b/input-types/src/lib.rs new file mode 100644 index 00000000..92f7d4d5 --- /dev/null +++ b/input-types/src/lib.rs @@ -0,0 +1,98 @@ +use { + jay_utils::static_text::StaticText, + linearize::Linearize, + std::ops::{BitOr, BitOrAssign}, +}; + +#[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, 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; + } +} diff --git a/src/backend.rs b/src/backend.rs index f30582ad..4d1b0e54 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -18,7 +18,6 @@ use { TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit, ToolButtonState, }, - wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL}, }, }, libinput::consts::DeviceCapability, @@ -43,6 +42,11 @@ use { pub mod transaction; +pub use jay_input_types::{ + AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceClickMethod, KeyState, + LED_CAPS_LOCK, LED_COMPOSE, LED_KANA, LED_NUM_LOCK, LED_SCROLL_LOCK, Leds, ScrollAxis, +}; + linear_ids!(ConnectorIds, ConnectorId); linear_ids!(InputDeviceIds, InputDeviceId); linear_ids!(DrmDeviceIds, DrmDeviceId); @@ -316,38 +320,6 @@ impl InputDeviceCapability { } } -#[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", - } - } -} - pub enum BackendEvent { NewDrmDevice(Rc), NewConnector(Rc), @@ -355,43 +327,6 @@ pub enum BackendEvent { DevicesEnumerated, } -#[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 { - Horizontal = HORIZONTAL_SCROLL as _, - Vertical = VERTICAL_SCROLL as _, -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub enum AxisSource { - Wheel = WHEEL as _, - Finger = FINGER as _, - Continuous = CONTINUOUS as _, -} - -pub const AXIS_120: i32 = 120; - -bitflags! { - Leds: u32; - LED_NUM_LOCK, - LED_CAPS_LOCK, - LED_SCROLL_LOCK, - LED_COMPOSE, - LED_KANA, -} - #[derive(Debug)] pub enum InputEvent { Key {