backend: move interface ids into type crates
This commit is contained in:
parent
46d39becd4
commit
be1511a7be
5 changed files with 95 additions and 46 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1001,6 +1001,7 @@ name = "jay-output-types"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"jay-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Self>) -> SpawnedFuture<Result<(), Box<dyn Error>>>;
|
||||
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<Vec<Mode>>,
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue