1
0
Fork 0
forked from wry/wry

config: move parsed model into schema crate

This commit is contained in:
kossLAN 2026-05-29 17:15:14 -04:00
parent c8a6b69bf1
commit a038855895
No known key found for this signature in database
8 changed files with 266 additions and 239 deletions

1
Cargo.lock generated
View file

@ -808,6 +808,7 @@ dependencies = [
name = "jay-config-schema" name = "jay-config-schema"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ahash",
"jay-config", "jay-config",
] ]

View file

@ -7,4 +7,5 @@ description = "Shared configuration schema declarations for the Jay compositor"
repository = "https://github.com/mahkoh/jay" repository = "https://github.com/mahkoh/jay"
[dependencies] [dependencies]
ahash = "0.8.11"
jay-config = { version = "1.10.0", path = "../jay-config" } jay-config = { version = "1.10.0", path = "../jay-config" }

View file

@ -9,6 +9,7 @@ pub mod animations;
pub mod command; pub mod command;
pub mod input; pub mod input;
pub mod keymap; pub mod keymap;
pub mod model;
pub mod options; pub mod options;
pub mod output; pub mod output;
pub mod rules; pub mod rules;
@ -19,6 +20,7 @@ pub use animations::{AnimationCurveConfig, Animations};
pub use command::{Exec, Status}; pub use command::{Exec, Status};
pub use input::InputMatch; pub use input::InputMatch;
pub use keymap::ConfigKeymap; pub use keymap::ConfigKeymap;
pub use model::{Action, ClientRule, Config, Input, InputMode, NamedAction, Shortcut, WindowRule};
pub use options::{ pub use options::{
ColorManagement, Float, FocusHistory, Libei, RepeatRate, SimpleIm, Tearing, UiDrag, Vrr, ColorManagement, Float, FocusHistory, Libei, RepeatRate, SimpleIm, Tearing, UiDrag, Vrr,
Xwayland, Xwayland,

View file

@ -0,0 +1,239 @@
use {
crate::{
Animations, ClientMatch, ColorManagement, ConfigConnector, ConfigDrmDevice, ConfigKeymap,
DrmDeviceMatch, Exec, Float, FocusHistory, InputMatch, Libei, Output, OutputMatch,
RepeatRate, SimpleCommand, SimpleIm, Status, Tearing, Theme, UiDrag, Vrr, WindowMatch,
Xwayland,
},
ahash::AHashMap,
jay_config::{
Direction, Workspace,
input::{
FallbackOutputMode, SwitchEvent, acceleration::AccelProfile, clickmethod::ClickMethod,
},
keyboard::{ModifiedKeySym, mods::Modifiers, syms::KeySym},
logging::LogLevel,
video::GfxApi,
window::TileState,
workspace::WorkspaceDisplayOrder,
},
std::{rc::Rc, time::Duration},
};
#[derive(Debug, Clone)]
#[expect(clippy::enum_variant_names)]
pub enum Action {
ConfigureConnector {
con: ConfigConnector,
},
ConfigureDirectScanout {
enabled: bool,
},
ConfigureDrmDevice {
dev: ConfigDrmDevice,
},
ConfigureIdle {
idle: Option<Duration>,
grace_period: Option<Duration>,
},
ConfigureInput {
input: Box<Input>,
},
ConfigureOutput {
out: Output,
},
Exec {
exec: Exec,
},
MoveToWorkspace {
name: String,
},
Multi {
actions: Vec<Action>,
},
SetEnv {
env: Vec<(String, String)>,
},
SetGfxApi {
api: GfxApi,
},
SetKeymap {
map: ConfigKeymap,
},
SetLogLevel {
level: LogLevel,
},
SetRenderDevice {
dev: Box<DrmDeviceMatch>,
},
SetStatus {
status: Option<Status>,
},
SetTheme {
theme: Box<Theme>,
},
ShowWorkspace {
name: String,
output: Option<OutputMatch>,
},
SimpleCommand {
cmd: SimpleCommand,
},
SwitchToVt {
num: u32,
},
UnsetEnv {
env: Vec<String>,
},
MoveToOutput {
workspace: Option<Workspace>,
output: Option<OutputMatch>,
direction: Option<Direction>,
},
SetRepeatRate {
rate: RepeatRate,
},
DefineAction {
name: String,
action: Box<Action>,
},
UndefineAction {
name: String,
},
NamedAction {
name: String,
},
CreateMark(u32),
JumpToMark(u32),
CopyMark(u32, u32),
SetMode {
name: String,
latch: bool,
},
CreateVirtualOutput {
name: String,
},
RemoveVirtualOutput {
name: String,
},
Resize {
dx1: i32,
dy1: i32,
dx2: i32,
dy2: i32,
},
}
#[derive(Debug, Clone)]
pub struct ClientRule {
pub name: Option<String>,
pub match_: ClientMatch,
pub action: Option<Action>,
pub latch: Option<Action>,
}
#[derive(Debug, Clone)]
pub struct WindowRule {
pub name: Option<String>,
pub match_: WindowMatch,
pub action: Option<Action>,
pub latch: Option<Action>,
pub auto_focus: Option<bool>,
pub initial_tile_state: Option<TileState>,
}
#[derive(Debug, Clone)]
pub struct Input {
pub tag: Option<String>,
pub match_: InputMatch,
pub accel_profile: Option<AccelProfile>,
pub accel_speed: Option<f64>,
pub tap_enabled: Option<bool>,
pub tap_drag_enabled: Option<bool>,
pub tap_drag_lock_enabled: Option<bool>,
pub left_handed: Option<bool>,
pub natural_scrolling: Option<bool>,
pub click_method: Option<ClickMethod>,
pub middle_button_emulation: Option<bool>,
pub px_per_wheel_scroll: Option<f64>,
pub transform_matrix: Option<[[f64; 2]; 2]>,
pub keymap: Option<ConfigKeymap>,
pub switch_actions: AHashMap<SwitchEvent, Action>,
pub output: Option<Option<OutputMatch>>,
pub calibration_matrix: Option<[[f32; 3]; 2]>,
}
#[derive(Debug, Clone)]
pub struct Shortcut {
pub mask: Modifiers,
pub keysym: ModifiedKeySym,
pub action: Action,
pub latch: Option<Action>,
}
#[derive(Debug, Clone)]
pub struct NamedAction {
pub name: Rc<String>,
pub action: Action,
}
#[derive(Clone, Debug)]
pub struct InputMode {
pub parent: Option<String>,
pub shortcuts: Vec<Shortcut>,
}
#[derive(Debug, Clone)]
pub struct Config {
pub keymap: Option<ConfigKeymap>,
pub repeat_rate: Option<RepeatRate>,
pub shortcuts: Vec<Shortcut>,
pub on_graphics_initialized: Option<Action>,
pub on_idle: Option<Action>,
pub status: Option<Status>,
pub connectors: Vec<ConfigConnector>,
pub outputs: Vec<Output>,
pub workspace_capture: bool,
pub env: Vec<(String, String)>,
pub on_startup: Option<Action>,
pub keymaps: Vec<ConfigKeymap>,
pub auto_reload: Option<bool>,
pub log_level: Option<LogLevel>,
pub clean_logs_older_than: Option<Duration>,
pub theme: Theme,
pub gfx_api: Option<GfxApi>,
pub direct_scanout_enabled: Option<bool>,
pub drm_devices: Vec<ConfigDrmDevice>,
pub render_device: Option<DrmDeviceMatch>,
pub inputs: Vec<Input>,
pub idle: Option<Duration>,
pub grace_period: Option<Duration>,
pub key_press_enables_dpms: Option<bool>,
pub mouse_move_enables_dpms: Option<bool>,
pub explicit_sync_enabled: Option<bool>,
pub focus_follows_mouse: bool,
pub window_management_key: Option<ModifiedKeySym>,
pub vrr: Option<Vrr>,
pub tearing: Option<Tearing>,
pub libei: Libei,
pub ui_drag: UiDrag,
pub animations: Animations,
pub xwayland: Option<Xwayland>,
pub color_management: Option<ColorManagement>,
pub float: Option<Float>,
pub named_actions: Vec<NamedAction>,
pub max_action_depth: u64,
pub client_rules: Vec<ClientRule>,
pub window_rules: Vec<WindowRule>,
pub pointer_revert_key: Option<KeySym>,
pub use_hardware_cursor: Option<bool>,
pub show_bar: Option<bool>,
pub show_titles: Option<bool>,
pub focus_history: Option<FocusHistory>,
pub middle_click_paste: Option<bool>,
pub input_modes: AHashMap<String, InputMode>,
pub workspace_display_order: Option<WorkspaceDisplayOrder>,
pub simple_im: Option<SimpleIm>,
pub fallback_output_mode: Option<FallbackOutputMode>,
pub mouse_follows_focus: Option<bool>,
}

View file

@ -18,252 +18,22 @@ use {
toml::{self}, toml::{self},
}, },
ahash::AHashMap, ahash::AHashMap,
jay_config::{
Direction, Workspace,
input::{
FallbackOutputMode, SwitchEvent, acceleration::AccelProfile, clickmethod::ClickMethod,
},
keyboard::{ModifiedKeySym, mods::Modifiers, syms::KeySym},
logging::LogLevel,
video::GfxApi,
window::TileState,
workspace::WorkspaceDisplayOrder,
},
std::{ std::{
cell::RefCell, cell::RefCell,
error::Error, error::Error,
rc::Rc,
time::Duration,
}, },
thiserror::Error, thiserror::Error,
toml::toml_parser, toml::toml_parser,
}; };
pub use jay_config_schema::{ pub use jay_config_schema::{
AnimationCurveConfig, Animations, ClientMatch, ColorManagement, ConfigConnector, Action, AnimationCurveConfig, Animations, ClientMatch, ClientRule, ColorManagement, Config,
ConfigDrmDevice, ConfigKeymap, ConnectorMatch, DrmDeviceMatch, Exec, Float, FocusHistory, ConfigConnector, ConfigDrmDevice, ConfigKeymap, ConnectorMatch, DrmDeviceMatch, Exec, Float,
GenericMatch, InputMatch, Libei, MatchExactly, Mode, Output, OutputMatch, RepeatRate, FocusHistory, GenericMatch, Input, InputMatch, InputMode, Libei, MatchExactly, Mode,
SimpleCommand, SimpleIm, Status, Tearing, Theme, UiDrag, Vrr, WindowMatch, Xwayland, NamedAction, Output, OutputMatch, RepeatRate, Shortcut, SimpleCommand, SimpleIm, Status,
Tearing, Theme, UiDrag, Vrr, WindowMatch, WindowRule, Xwayland,
}; };
#[derive(Debug, Clone)]
#[expect(clippy::enum_variant_names)]
pub enum Action {
ConfigureConnector {
con: ConfigConnector,
},
ConfigureDirectScanout {
enabled: bool,
},
ConfigureDrmDevice {
dev: ConfigDrmDevice,
},
ConfigureIdle {
idle: Option<Duration>,
grace_period: Option<Duration>,
},
ConfigureInput {
input: Box<Input>,
},
ConfigureOutput {
out: Output,
},
Exec {
exec: Exec,
},
MoveToWorkspace {
name: String,
},
Multi {
actions: Vec<Action>,
},
SetEnv {
env: Vec<(String, String)>,
},
SetGfxApi {
api: GfxApi,
},
SetKeymap {
map: ConfigKeymap,
},
SetLogLevel {
level: LogLevel,
},
SetRenderDevice {
dev: Box<DrmDeviceMatch>,
},
SetStatus {
status: Option<Status>,
},
SetTheme {
theme: Box<Theme>,
},
ShowWorkspace {
name: String,
output: Option<OutputMatch>,
},
SimpleCommand {
cmd: SimpleCommand,
},
SwitchToVt {
num: u32,
},
UnsetEnv {
env: Vec<String>,
},
MoveToOutput {
workspace: Option<Workspace>,
output: Option<OutputMatch>,
direction: Option<Direction>,
},
SetRepeatRate {
rate: RepeatRate,
},
DefineAction {
name: String,
action: Box<Action>,
},
UndefineAction {
name: String,
},
NamedAction {
name: String,
},
CreateMark(u32),
JumpToMark(u32),
CopyMark(u32, u32),
SetMode {
name: String,
latch: bool,
},
CreateVirtualOutput {
name: String,
},
RemoveVirtualOutput {
name: String,
},
Resize {
dx1: i32,
dy1: i32,
dx2: i32,
dy2: i32,
},
}
#[derive(Debug, Clone)]
pub struct ClientRule {
pub name: Option<String>,
pub match_: ClientMatch,
pub action: Option<Action>,
pub latch: Option<Action>,
}
#[derive(Debug, Clone)]
pub struct WindowRule {
pub name: Option<String>,
pub match_: WindowMatch,
pub action: Option<Action>,
pub latch: Option<Action>,
pub auto_focus: Option<bool>,
pub initial_tile_state: Option<TileState>,
}
#[derive(Debug, Clone)]
pub struct Input {
pub tag: Option<String>,
pub match_: InputMatch,
pub accel_profile: Option<AccelProfile>,
pub accel_speed: Option<f64>,
pub tap_enabled: Option<bool>,
pub tap_drag_enabled: Option<bool>,
pub tap_drag_lock_enabled: Option<bool>,
pub left_handed: Option<bool>,
pub natural_scrolling: Option<bool>,
pub click_method: Option<ClickMethod>,
pub middle_button_emulation: Option<bool>,
pub px_per_wheel_scroll: Option<f64>,
pub transform_matrix: Option<[[f64; 2]; 2]>,
pub keymap: Option<ConfigKeymap>,
pub switch_actions: AHashMap<SwitchEvent, Action>,
pub output: Option<Option<OutputMatch>>,
pub calibration_matrix: Option<[[f32; 3]; 2]>,
}
#[derive(Debug, Clone)]
pub struct Shortcut {
pub mask: Modifiers,
pub keysym: ModifiedKeySym,
pub action: Action,
pub latch: Option<Action>,
}
#[derive(Debug, Clone)]
pub struct NamedAction {
pub name: Rc<String>,
pub action: Action,
}
#[derive(Clone, Debug)]
pub struct InputMode {
pub parent: Option<String>,
pub shortcuts: Vec<Shortcut>,
}
#[derive(Debug, Clone)]
pub struct Config {
pub keymap: Option<ConfigKeymap>,
pub repeat_rate: Option<RepeatRate>,
pub shortcuts: Vec<Shortcut>,
pub on_graphics_initialized: Option<Action>,
pub on_idle: Option<Action>,
pub status: Option<Status>,
pub connectors: Vec<ConfigConnector>,
pub outputs: Vec<Output>,
pub workspace_capture: bool,
pub env: Vec<(String, String)>,
pub on_startup: Option<Action>,
pub keymaps: Vec<ConfigKeymap>,
pub auto_reload: Option<bool>,
pub log_level: Option<LogLevel>,
pub clean_logs_older_than: Option<Duration>,
pub theme: Theme,
pub gfx_api: Option<GfxApi>,
pub direct_scanout_enabled: Option<bool>,
pub drm_devices: Vec<ConfigDrmDevice>,
pub render_device: Option<DrmDeviceMatch>,
pub inputs: Vec<Input>,
pub idle: Option<Duration>,
pub grace_period: Option<Duration>,
pub key_press_enables_dpms: Option<bool>,
pub mouse_move_enables_dpms: Option<bool>,
pub explicit_sync_enabled: Option<bool>,
pub focus_follows_mouse: bool,
pub window_management_key: Option<ModifiedKeySym>,
pub vrr: Option<Vrr>,
pub tearing: Option<Tearing>,
pub libei: Libei,
pub ui_drag: UiDrag,
pub animations: Animations,
pub xwayland: Option<Xwayland>,
pub color_management: Option<ColorManagement>,
pub float: Option<Float>,
pub named_actions: Vec<NamedAction>,
pub max_action_depth: u64,
pub client_rules: Vec<ClientRule>,
pub window_rules: Vec<WindowRule>,
pub pointer_revert_key: Option<KeySym>,
pub use_hardware_cursor: Option<bool>,
pub show_bar: Option<bool>,
pub show_titles: Option<bool>,
pub focus_history: Option<FocusHistory>,
pub middle_click_paste: Option<bool>,
pub input_modes: AHashMap<String, InputMode>,
pub workspace_display_order: Option<WorkspaceDisplayOrder>,
pub simple_im: Option<SimpleIm>,
pub fallback_output_mode: Option<FallbackOutputMode>,
pub mouse_follows_focus: Option<bool>,
}
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum ConfigError { pub enum ConfigError {
#[error("Could not parse the toml document")] #[error("Could not parse the toml document")]

View file

@ -128,7 +128,17 @@ impl FnBuilder for ShortcutFnBuilder<'_> {
} }
} }
impl Action { trait ActionExt {
fn into_fn(self, state: &Rc<State>) -> Box<dyn Fn()>;
fn into_rc_fn(self, state: &Rc<State>) -> Rc<dyn Fn()>;
fn into_shortcut_fn(self, state: &Rc<State>) -> Rc<dyn Fn()>;
fn into_fn_impl<B: FnBuilder>(self, b: &B, state: &Rc<State>) -> B::Output;
}
impl ActionExt for Action {
fn into_fn(self, state: &Rc<State>) -> Box<dyn Fn()> { fn into_fn(self, state: &Rc<State>) -> Box<dyn Fn()> {
self.into_fn_impl(&BoxFnBuilder, state) self.into_fn_impl(&BoxFnBuilder, state)
} }
@ -723,7 +733,11 @@ impl InputMatchExt for InputMatch {
} }
} }
impl Input { trait InputExt {
fn apply(&self, c: InputDevice, state: &State);
}
impl InputExt for Input {
fn apply(&self, c: InputDevice, state: &State) { fn apply(&self, c: InputDevice, state: &State) {
if let Some(v) = self.accel_profile { if let Some(v) = self.accel_profile {
c.set_accel_profile(v); c.set_accel_profile(v);

View file

@ -1,6 +1,6 @@
use { use {
crate::{ crate::{
State, ActionExt, State,
config::{ClientMatch, ClientRule, GenericMatch, WindowMatch, WindowRule}, config::{ClientMatch, ClientRule, GenericMatch, WindowMatch, WindowRule},
}, },
ahash::{AHashMap, AHashSet}, ahash::{AHashMap, AHashSet},

View file

@ -1,6 +1,6 @@
use { use {
crate::{ crate::{
State, ActionExt, State,
config::{Action, InputMode, Shortcut, SimpleCommand}, config::{Action, InputMode, Shortcut, SimpleCommand},
}, },
ahash::{AHashMap, AHashSet}, ahash::{AHashMap, AHashSet},