diff --git a/Cargo.lock b/Cargo.lock index fa109432..9e790e33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -808,6 +808,7 @@ dependencies = [ name = "jay-config-schema" version = "0.1.0" dependencies = [ + "ahash", "jay-config", ] diff --git a/jay-config-schema/Cargo.toml b/jay-config-schema/Cargo.toml index 521a92cc..99bdcac8 100644 --- a/jay-config-schema/Cargo.toml +++ b/jay-config-schema/Cargo.toml @@ -7,4 +7,5 @@ description = "Shared configuration schema declarations for the Jay compositor" repository = "https://github.com/mahkoh/jay" [dependencies] +ahash = "0.8.11" jay-config = { version = "1.10.0", path = "../jay-config" } diff --git a/jay-config-schema/src/lib.rs b/jay-config-schema/src/lib.rs index 74821107..432a7810 100644 --- a/jay-config-schema/src/lib.rs +++ b/jay-config-schema/src/lib.rs @@ -9,6 +9,7 @@ pub mod animations; pub mod command; pub mod input; pub mod keymap; +pub mod model; pub mod options; pub mod output; pub mod rules; @@ -19,6 +20,7 @@ pub use animations::{AnimationCurveConfig, Animations}; pub use command::{Exec, Status}; pub use input::InputMatch; pub use keymap::ConfigKeymap; +pub use model::{Action, ClientRule, Config, Input, InputMode, NamedAction, Shortcut, WindowRule}; pub use options::{ ColorManagement, Float, FocusHistory, Libei, RepeatRate, SimpleIm, Tearing, UiDrag, Vrr, Xwayland, diff --git a/jay-config-schema/src/model.rs b/jay-config-schema/src/model.rs new file mode 100644 index 00000000..4a4bf430 --- /dev/null +++ b/jay-config-schema/src/model.rs @@ -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, + grace_period: Option, + }, + ConfigureInput { + input: Box, + }, + ConfigureOutput { + out: Output, + }, + Exec { + exec: Exec, + }, + MoveToWorkspace { + name: String, + }, + Multi { + actions: Vec, + }, + SetEnv { + env: Vec<(String, String)>, + }, + SetGfxApi { + api: GfxApi, + }, + SetKeymap { + map: ConfigKeymap, + }, + SetLogLevel { + level: LogLevel, + }, + SetRenderDevice { + dev: Box, + }, + SetStatus { + status: Option, + }, + SetTheme { + theme: Box, + }, + ShowWorkspace { + name: String, + output: Option, + }, + SimpleCommand { + cmd: SimpleCommand, + }, + SwitchToVt { + num: u32, + }, + UnsetEnv { + env: Vec, + }, + MoveToOutput { + workspace: Option, + output: Option, + direction: Option, + }, + SetRepeatRate { + rate: RepeatRate, + }, + DefineAction { + name: String, + action: Box, + }, + 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, + pub match_: ClientMatch, + pub action: Option, + pub latch: Option, +} + +#[derive(Debug, Clone)] +pub struct WindowRule { + pub name: Option, + pub match_: WindowMatch, + pub action: Option, + pub latch: Option, + pub auto_focus: Option, + pub initial_tile_state: Option, +} + +#[derive(Debug, Clone)] +pub struct Input { + pub tag: Option, + pub match_: InputMatch, + pub accel_profile: Option, + pub accel_speed: Option, + pub tap_enabled: Option, + pub tap_drag_enabled: Option, + pub tap_drag_lock_enabled: Option, + pub left_handed: Option, + pub natural_scrolling: Option, + pub click_method: Option, + pub middle_button_emulation: Option, + pub px_per_wheel_scroll: Option, + pub transform_matrix: Option<[[f64; 2]; 2]>, + pub keymap: Option, + pub switch_actions: AHashMap, + pub output: Option>, + 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, +} + +#[derive(Debug, Clone)] +pub struct NamedAction { + pub name: Rc, + pub action: Action, +} + +#[derive(Clone, Debug)] +pub struct InputMode { + pub parent: Option, + pub shortcuts: Vec, +} + +#[derive(Debug, Clone)] +pub struct Config { + pub keymap: Option, + pub repeat_rate: Option, + pub shortcuts: Vec, + pub on_graphics_initialized: Option, + pub on_idle: Option, + pub status: Option, + pub connectors: Vec, + pub outputs: Vec, + pub workspace_capture: bool, + pub env: Vec<(String, String)>, + pub on_startup: Option, + pub keymaps: Vec, + pub auto_reload: Option, + pub log_level: Option, + pub clean_logs_older_than: Option, + pub theme: Theme, + pub gfx_api: Option, + pub direct_scanout_enabled: Option, + pub drm_devices: Vec, + pub render_device: Option, + pub inputs: Vec, + pub idle: Option, + pub grace_period: Option, + pub key_press_enables_dpms: Option, + pub mouse_move_enables_dpms: Option, + pub explicit_sync_enabled: Option, + pub focus_follows_mouse: bool, + pub window_management_key: Option, + pub vrr: Option, + pub tearing: Option, + pub libei: Libei, + pub ui_drag: UiDrag, + pub animations: Animations, + pub xwayland: Option, + pub color_management: Option, + pub float: Option, + pub named_actions: Vec, + pub max_action_depth: u64, + pub client_rules: Vec, + pub window_rules: Vec, + pub pointer_revert_key: Option, + pub use_hardware_cursor: Option, + pub show_bar: Option, + pub show_titles: Option, + pub focus_history: Option, + pub middle_click_paste: Option, + pub input_modes: AHashMap, + pub workspace_display_order: Option, + pub simple_im: Option, + pub fallback_output_mode: Option, + pub mouse_follows_focus: Option, +} diff --git a/toml-config/src/config.rs b/toml-config/src/config.rs index a084725e..31e43c14 100644 --- a/toml-config/src/config.rs +++ b/toml-config/src/config.rs @@ -18,252 +18,22 @@ use { toml::{self}, }, 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::{ cell::RefCell, error::Error, - rc::Rc, - time::Duration, }, thiserror::Error, toml::toml_parser, }; pub use jay_config_schema::{ - AnimationCurveConfig, Animations, ClientMatch, ColorManagement, ConfigConnector, - ConfigDrmDevice, ConfigKeymap, ConnectorMatch, DrmDeviceMatch, Exec, Float, FocusHistory, - GenericMatch, InputMatch, Libei, MatchExactly, Mode, Output, OutputMatch, RepeatRate, - SimpleCommand, SimpleIm, Status, Tearing, Theme, UiDrag, Vrr, WindowMatch, Xwayland, + Action, AnimationCurveConfig, Animations, ClientMatch, ClientRule, ColorManagement, Config, + ConfigConnector, ConfigDrmDevice, ConfigKeymap, ConnectorMatch, DrmDeviceMatch, Exec, Float, + FocusHistory, GenericMatch, Input, InputMatch, InputMode, Libei, MatchExactly, Mode, + 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, - grace_period: Option, - }, - ConfigureInput { - input: Box, - }, - ConfigureOutput { - out: Output, - }, - Exec { - exec: Exec, - }, - MoveToWorkspace { - name: String, - }, - Multi { - actions: Vec, - }, - SetEnv { - env: Vec<(String, String)>, - }, - SetGfxApi { - api: GfxApi, - }, - SetKeymap { - map: ConfigKeymap, - }, - SetLogLevel { - level: LogLevel, - }, - SetRenderDevice { - dev: Box, - }, - SetStatus { - status: Option, - }, - SetTheme { - theme: Box, - }, - ShowWorkspace { - name: String, - output: Option, - }, - SimpleCommand { - cmd: SimpleCommand, - }, - SwitchToVt { - num: u32, - }, - UnsetEnv { - env: Vec, - }, - MoveToOutput { - workspace: Option, - output: Option, - direction: Option, - }, - SetRepeatRate { - rate: RepeatRate, - }, - DefineAction { - name: String, - action: Box, - }, - 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, - pub match_: ClientMatch, - pub action: Option, - pub latch: Option, -} - -#[derive(Debug, Clone)] -pub struct WindowRule { - pub name: Option, - pub match_: WindowMatch, - pub action: Option, - pub latch: Option, - pub auto_focus: Option, - pub initial_tile_state: Option, -} - -#[derive(Debug, Clone)] -pub struct Input { - pub tag: Option, - pub match_: InputMatch, - pub accel_profile: Option, - pub accel_speed: Option, - pub tap_enabled: Option, - pub tap_drag_enabled: Option, - pub tap_drag_lock_enabled: Option, - pub left_handed: Option, - pub natural_scrolling: Option, - pub click_method: Option, - pub middle_button_emulation: Option, - pub px_per_wheel_scroll: Option, - pub transform_matrix: Option<[[f64; 2]; 2]>, - pub keymap: Option, - pub switch_actions: AHashMap, - pub output: Option>, - 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, -} - -#[derive(Debug, Clone)] -pub struct NamedAction { - pub name: Rc, - pub action: Action, -} - -#[derive(Clone, Debug)] -pub struct InputMode { - pub parent: Option, - pub shortcuts: Vec, -} - -#[derive(Debug, Clone)] -pub struct Config { - pub keymap: Option, - pub repeat_rate: Option, - pub shortcuts: Vec, - pub on_graphics_initialized: Option, - pub on_idle: Option, - pub status: Option, - pub connectors: Vec, - pub outputs: Vec, - pub workspace_capture: bool, - pub env: Vec<(String, String)>, - pub on_startup: Option, - pub keymaps: Vec, - pub auto_reload: Option, - pub log_level: Option, - pub clean_logs_older_than: Option, - pub theme: Theme, - pub gfx_api: Option, - pub direct_scanout_enabled: Option, - pub drm_devices: Vec, - pub render_device: Option, - pub inputs: Vec, - pub idle: Option, - pub grace_period: Option, - pub key_press_enables_dpms: Option, - pub mouse_move_enables_dpms: Option, - pub explicit_sync_enabled: Option, - pub focus_follows_mouse: bool, - pub window_management_key: Option, - pub vrr: Option, - pub tearing: Option, - pub libei: Libei, - pub ui_drag: UiDrag, - pub animations: Animations, - pub xwayland: Option, - pub color_management: Option, - pub float: Option, - pub named_actions: Vec, - pub max_action_depth: u64, - pub client_rules: Vec, - pub window_rules: Vec, - pub pointer_revert_key: Option, - pub use_hardware_cursor: Option, - pub show_bar: Option, - pub show_titles: Option, - pub focus_history: Option, - pub middle_click_paste: Option, - pub input_modes: AHashMap, - pub workspace_display_order: Option, - pub simple_im: Option, - pub fallback_output_mode: Option, - pub mouse_follows_focus: Option, -} - #[derive(Debug, Error)] pub enum ConfigError { #[error("Could not parse the toml document")] diff --git a/toml-config/src/lib.rs b/toml-config/src/lib.rs index b2475670..67586416 100644 --- a/toml-config/src/lib.rs +++ b/toml-config/src/lib.rs @@ -128,7 +128,17 @@ impl FnBuilder for ShortcutFnBuilder<'_> { } } -impl Action { +trait ActionExt { + fn into_fn(self, state: &Rc) -> Box; + + fn into_rc_fn(self, state: &Rc) -> Rc; + + fn into_shortcut_fn(self, state: &Rc) -> Rc; + + fn into_fn_impl(self, b: &B, state: &Rc) -> B::Output; +} + +impl ActionExt for Action { fn into_fn(self, state: &Rc) -> Box { 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) { if let Some(v) = self.accel_profile { c.set_accel_profile(v); diff --git a/toml-config/src/rules.rs b/toml-config/src/rules.rs index 48029314..f5d6d6d7 100644 --- a/toml-config/src/rules.rs +++ b/toml-config/src/rules.rs @@ -1,6 +1,6 @@ use { crate::{ - State, + ActionExt, State, config::{ClientMatch, ClientRule, GenericMatch, WindowMatch, WindowRule}, }, ahash::{AHashMap, AHashSet}, diff --git a/toml-config/src/shortcuts.rs b/toml-config/src/shortcuts.rs index 7156433c..325beb03 100644 --- a/toml-config/src/shortcuts.rs +++ b/toml-config/src/shortcuts.rs @@ -1,6 +1,6 @@ use { crate::{ - State, + ActionExt, State, config::{Action, InputMode, Shortcut, SimpleCommand}, }, ahash::{AHashMap, AHashSet},