diff --git a/Cargo.lock b/Cargo.lock index 2ecee160..5b28329c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1001,6 +1001,7 @@ name = "jay-output-types" version = "0.1.0" dependencies = [ "blake3", + "jay-utils", ] [[package]] diff --git a/input-types/src/lib.rs b/input-types/src/lib.rs index ff43f256..c2537fde 100644 --- a/input-types/src/lib.rs +++ b/input-types/src/lib.rs @@ -110,6 +110,9 @@ impl StaticText for InputDeviceCapability { } linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize); +linear_ids!(InputDeviceIds, InputDeviceId); + +pub type TransformMatrix = [[f64; 2]; 2]; #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum KeyState { diff --git a/output-types/Cargo.toml b/output-types/Cargo.toml index cbc26574..535bda79 100644 --- a/output-types/Cargo.toml +++ b/output-types/Cargo.toml @@ -7,4 +7,6 @@ description = "Output identity types for the Jay compositor" repository = "https://github.com/mahkoh/jay" [dependencies] +jay-utils = { version = "0.1.0", path = "../utils" } + blake3 = "1.8.2" diff --git a/output-types/src/lib.rs b/output-types/src/lib.rs index 9d3bb80e..0ea26cdf 100644 --- a/output-types/src/lib.rs +++ b/output-types/src/lib.rs @@ -1,10 +1,92 @@ use { + jay_utils::numcell::NumCell, std::{ + fmt::{Display, Formatter}, hash::{Hash, Hasher}, rc::Rc, }, }; +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) + } + } + }; +} + +linear_ids!(ConnectorIds, ConnectorId); +linear_ids!(DrmDeviceIds, DrmDeviceId); + +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)] +pub struct Mode { + pub width: i32, + pub height: i32, + pub refresh_rate_millihz: u32, +} + +impl Mode { + pub fn refresh_nsec(&self) -> u64 { + match self.refresh_rate_millihz { + 0 => u64::MAX, + n => 1_000_000_000_000 / (n as u64), + } + } + + pub fn size(&self) -> (i32, i32) { + (self.width, self.height) + } +} + +impl Display for Mode { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}x{}@{}", + self.width, + self.height, + self.refresh_rate_millihz as f64 / 1000.0, + ) + } +} + #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct OutputIdHash(pub [u8; 32]); diff --git a/src/backend.rs b/src/backend.rs index 72509caa..8bb837e7 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -22,7 +22,6 @@ use { any::Any, error::Error, fmt::{Debug, Display, Formatter}, - hash::Hash, rc::Rc, }, uapi::{OwnedFd, Packed, Pod, c}, @@ -30,22 +29,18 @@ use { pub mod transaction; -pub use jay_output_types::OutputId; +pub use jay_output_types::{ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, Mode, OutputId}; pub use jay_input_types::{ AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceCapability, - 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, + InputDeviceClickMethod, InputDeviceGroupId, InputDeviceGroupIds, InputDeviceId, + InputDeviceIds, KeyState, Leds, PadButtonState, ScrollAxis, TabletId, TabletIds, TabletInit, + TabletPadGroupInit, TabletPadId, TabletPadIds, TabletPadInit, TabletRingEventSource, + TabletStripEventSource, TabletTool2dChange, TabletToolCapability, TabletToolChanges, + TabletToolId, TabletToolIds, TabletToolInit, TabletToolPositionChange, TabletToolType, + TabletToolWheelChange, ToolButtonState, TransformMatrix, }; -linear_ids!(ConnectorIds, ConnectorId); -linear_ids!(InputDeviceIds, InputDeviceId); -linear_ids!(DrmDeviceIds, DrmDeviceId); - pub trait Backend: Any { fn run(self: Rc) -> SpawnedFuture>>; fn clear(&self) { @@ -69,38 +64,6 @@ pub trait Backend: Any { } } -#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)] -pub struct Mode { - pub width: i32, - pub height: i32, - pub refresh_rate_millihz: u32, -} - -impl Mode { - pub fn refresh_nsec(&self) -> u64 { - match self.refresh_rate_millihz { - 0 => u64::MAX, - n => 1_000_000_000_000 / (n as u64), - } - } - - pub fn size(&self) -> (i32, i32) { - (self.width, self.height) - } -} - -impl Display for Mode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}x{}@{}", - self.width, - self.height, - self.refresh_rate_millihz as f64 / 1000.0, - ) - } -} - #[derive(Clone, Debug)] pub struct MonitorInfo { pub modes: Option>, @@ -202,8 +165,6 @@ pub trait HardwareCursor: Debug { fn damage(&self); } -pub type TransformMatrix = [[f64; 2]; 2]; - pub trait InputDevice { fn id(&self) -> InputDeviceId; fn removed(&self) -> bool;