From fb65585bfaa482c55f9be07941bdac8251b8c952 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 17:04:27 -0400 Subject: [PATCH] config: move output schema into schema crate --- jay-config-schema/src/lib.rs | 4 ++ jay-config-schema/src/output.rs | 88 +++++++++++++++++++++++++++++++ toml-config/src/config.rs | 91 ++------------------------------- toml-config/src/lib.rs | 50 +++++++++++++++--- 4 files changed, 140 insertions(+), 93 deletions(-) create mode 100644 jay-config-schema/src/output.rs diff --git a/jay-config-schema/src/lib.rs b/jay-config-schema/src/lib.rs index f3e43b4f..2706de60 100644 --- a/jay-config-schema/src/lib.rs +++ b/jay-config-schema/src/lib.rs @@ -6,6 +6,7 @@ pub mod animations; pub mod options; +pub mod output; pub mod theme; pub use animations::{AnimationCurveConfig, Animations}; @@ -13,4 +14,7 @@ pub use options::{ ColorManagement, Float, FocusHistory, Libei, RepeatRate, SimpleIm, Tearing, UiDrag, Vrr, Xwayland, }; +pub use output::{ + ConfigConnector, ConfigDrmDevice, ConnectorMatch, DrmDeviceMatch, Mode, Output, OutputMatch, +}; pub use theme::Theme; diff --git a/jay-config-schema/src/output.rs b/jay-config-schema/src/output.rs new file mode 100644 index 00000000..93c1343f --- /dev/null +++ b/jay-config-schema/src/output.rs @@ -0,0 +1,88 @@ +use { + crate::{Tearing, Vrr}, + jay_config::video::{BlendSpace, ColorSpace, Eotf, Format, GfxApi, Transform}, + std::fmt::{Display, Formatter}, +}; + +#[derive(Debug, Clone)] +pub enum OutputMatch { + Any(Vec), + All { + name: Option, + connector: Option, + serial_number: Option, + manufacturer: Option, + model: Option, + }, +} + +#[derive(Debug, Clone)] +pub enum DrmDeviceMatch { + Any(Vec), + All { + name: Option, + syspath: Option, + vendor: Option, + vendor_name: Option, + model: Option, + model_name: Option, + devnode: Option, + }, +} + +#[derive(Debug, Clone)] +pub struct Mode { + pub width: i32, + pub height: i32, + pub refresh_rate: Option, +} + +impl Display for Mode { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{} x {}", self.width, self.height)?; + if let Some(rr) = self.refresh_rate { + write!(f, " @ {rr}")?; + } + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct Output { + pub name: Option, + pub match_: OutputMatch, + pub x: Option, + pub y: Option, + pub scale: Option, + pub transform: Option, + pub mode: Option, + pub vrr: Option, + pub tearing: Option, + pub format: Option, + pub color_space: Option, + pub eotf: Option, + pub brightness: Option>, + pub blend_space: Option, + pub use_native_gamut: Option, +} + +#[derive(Debug, Clone)] +pub enum ConnectorMatch { + Any(Vec), + All { connector: Option }, +} + +#[derive(Debug, Clone)] +pub struct ConfigConnector { + pub match_: ConnectorMatch, + pub enabled: bool, +} + +#[derive(Debug, Clone)] +pub struct ConfigDrmDevice { + pub name: Option, + pub match_: DrmDeviceMatch, + pub gfx_api: Option, + pub direct_scanout_enabled: Option, + pub flip_margin_ms: Option, +} diff --git a/toml-config/src/config.rs b/toml-config/src/config.rs index 65fd1eca..49249b2b 100644 --- a/toml-config/src/config.rs +++ b/toml-config/src/config.rs @@ -28,14 +28,13 @@ use { keyboard::{Keymap, ModifiedKeySym, mods::Modifiers, syms::KeySym}, logging::LogLevel, status::MessageFormat, - video::{BlendSpace, ColorSpace, Eotf, Format, GfxApi, Transform}, + video::GfxApi, window::{ContentType, TileState, WindowType}, workspace::WorkspaceDisplayOrder, }, std::{ cell::RefCell, error::Error, - fmt::{Display, Formatter}, rc::Rc, time::Duration, }, @@ -44,8 +43,9 @@ use { }; pub use jay_config_schema::{ - AnimationCurveConfig, Animations, ColorManagement, Float, FocusHistory, Libei, RepeatRate, - SimpleIm, Tearing, Theme, UiDrag, Vrr, Xwayland, + AnimationCurveConfig, Animations, ColorManagement, ConfigConnector, ConfigDrmDevice, + ConnectorMatch, DrmDeviceMatch, Float, FocusHistory, Libei, Mode, Output, OutputMatch, + RepeatRate, SimpleIm, Tearing, Theme, UiDrag, Vrr, Xwayland, }; #[derive(Debug, Copy, Clone)] @@ -211,18 +211,6 @@ pub struct Status { pub separator: Option, } -#[derive(Debug, Clone)] -pub enum OutputMatch { - Any(Vec), - All { - name: Option, - connector: Option, - serial_number: Option, - manufacturer: Option, - model: Option, - }, -} - #[derive(Default, Debug, Clone)] pub struct GenericMatch { pub name: Option, @@ -303,62 +291,6 @@ pub struct WindowMatch { pub content_types: Option, } -#[derive(Debug, Clone)] -pub enum DrmDeviceMatch { - Any(Vec), - All { - name: Option, - syspath: Option, - vendor: Option, - vendor_name: Option, - model: Option, - model_name: Option, - devnode: Option, - }, -} - -#[derive(Debug, Clone)] -pub struct Mode { - pub width: i32, - pub height: i32, - pub refresh_rate: Option, -} - -impl Display for Mode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{} x {}", self.width, self.height)?; - if let Some(rr) = self.refresh_rate { - write!(f, " @ {rr}")?; - } - Ok(()) - } -} - -#[derive(Debug, Clone)] -pub struct Output { - pub name: Option, - pub match_: OutputMatch, - pub x: Option, - pub y: Option, - pub scale: Option, - pub transform: Option, - pub mode: Option, - pub vrr: Option, - pub tearing: Option, - pub format: Option, - pub color_space: Option, - pub eotf: Option, - pub brightness: Option>, - pub blend_space: Option, - pub use_native_gamut: Option, -} - -#[derive(Debug, Clone)] -pub enum ConnectorMatch { - Any(Vec), - All { connector: Option }, -} - #[derive(Debug, Clone)] pub enum InputMatch { Any(Vec), @@ -405,21 +337,6 @@ pub struct Exec { pub envs: Vec<(String, String)>, } -#[derive(Debug, Clone)] -pub struct ConfigConnector { - pub match_: ConnectorMatch, - pub enabled: bool, -} - -#[derive(Debug, Clone)] -pub struct ConfigDrmDevice { - pub name: Option, - pub match_: DrmDeviceMatch, - pub gfx_api: Option, - pub direct_scanout_enabled: Option, - pub flip_margin_ms: Option, -} - #[derive(Debug, Clone)] pub enum ConfigKeymap { Named(String), diff --git a/toml-config/src/lib.rs b/toml-config/src/lib.rs index c85474e3..4a6d5381 100644 --- a/toml-config/src/lib.rs +++ b/toml-config/src/lib.rs @@ -538,7 +538,11 @@ fn apply_recursive_match<'a, U>( } } -impl ConfigDrmDevice { +trait ConfigDrmDeviceExt { + fn apply(&self, d: DrmDevice); +} + +impl ConfigDrmDeviceExt for ConfigDrmDevice { fn apply(&self, d: DrmDevice) { if let Some(api) = self.gfx_api { d.set_gfx_api(api); @@ -552,7 +556,18 @@ impl ConfigDrmDevice { } } -impl DrmDeviceMatch { +trait DrmDeviceMatchExt { + fn matches(&self, d: DrmDevice, state: &State) -> bool; + + fn matches_<'a>( + &'a self, + d: DrmDevice, + state: &'a State, + active: &mut AHashSet<&'a str>, + ) -> bool; +} + +impl DrmDeviceMatchExt for DrmDeviceMatch { fn matches(&self, d: DrmDevice, state: &State) -> bool { self.matches_(d, state, &mut AHashSet::new()) } @@ -754,7 +769,18 @@ impl Input { } } -impl OutputMatch { +trait OutputMatchExt { + fn matches(&self, c: Connector, state: &State) -> bool; + + fn matches_<'a>( + &'a self, + c: Connector, + state: &'a State, + active: &mut AHashSet<&'a str>, + ) -> bool; +} + +impl OutputMatchExt for OutputMatch { fn matches(&self, c: Connector, state: &State) -> bool { if !c.connected() { return false; @@ -815,7 +841,11 @@ impl OutputMatch { } } -impl ConnectorMatch { +trait ConnectorMatchExt { + fn matches(&self, c: Connector) -> bool; +} + +impl ConnectorMatchExt for ConnectorMatch { fn matches(&self, c: Connector) -> bool { if !c.exists() { return false; @@ -834,13 +864,21 @@ impl ConnectorMatch { } } -impl ConfigConnector { +trait ConfigConnectorExt { + fn apply(&self, c: Connector); +} + +impl ConfigConnectorExt for ConfigConnector { fn apply(&self, c: Connector) { c.set_enabled(self.enabled); } } -impl Output { +trait OutputExt { + fn apply(&self, c: Connector); +} + +impl OutputExt for Output { fn apply(&self, c: Connector) { if self.x.is_some() || self.y.is_some() { let (old_x, old_y) = c.position();