469 lines
12 KiB
Rust
469 lines
12 KiB
Rust
mod context;
|
|
pub mod error;
|
|
mod extractor;
|
|
mod keycodes;
|
|
mod parser;
|
|
mod parsers;
|
|
mod spanned;
|
|
mod value;
|
|
|
|
pub use crate::config::parsers::input_mode::InputMode;
|
|
use {
|
|
crate::{
|
|
config::{
|
|
context::Context,
|
|
parsers::{
|
|
config::{ConfigParser, ConfigParserError},
|
|
},
|
|
},
|
|
toml::{self},
|
|
},
|
|
ahash::AHashMap,
|
|
jay_config::{
|
|
Direction, Workspace,
|
|
input::{
|
|
FallbackOutputMode, LayerDirection, SwitchEvent, Timeline, acceleration::AccelProfile,
|
|
clickmethod::ClickMethod,
|
|
},
|
|
keyboard::{Keymap, ModifiedKeySym, mods::Modifiers, syms::KeySym},
|
|
logging::LogLevel,
|
|
video::GfxApi,
|
|
window::{ContentType, TileState, WindowType},
|
|
workspace::WorkspaceDisplayOrder,
|
|
},
|
|
std::{
|
|
cell::RefCell,
|
|
error::Error,
|
|
rc::Rc,
|
|
time::Duration,
|
|
},
|
|
thiserror::Error,
|
|
toml::toml_parser,
|
|
};
|
|
|
|
pub use jay_config_schema::{
|
|
AnimationCurveConfig, Animations, ColorManagement, ConfigConnector, ConfigDrmDevice,
|
|
ConnectorMatch, DrmDeviceMatch, Exec, Float, FocusHistory, InputMatch, Libei, Mode, Output,
|
|
OutputMatch, RepeatRate, SimpleIm, Status, Tearing, Theme, UiDrag, Vrr, Xwayland,
|
|
};
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub enum SimpleCommand {
|
|
Close,
|
|
DisablePointerConstraint,
|
|
Focus(Direction),
|
|
FocusParent,
|
|
Move(Direction),
|
|
None,
|
|
Quit,
|
|
ReloadConfigToml,
|
|
ToggleFloating,
|
|
SetFloating(bool),
|
|
ToggleFullscreen,
|
|
SetFullscreen(bool),
|
|
Forward(bool),
|
|
EnableWindowManagement(bool),
|
|
SetFloatAboveFullscreen(bool),
|
|
ToggleFloatAboveFullscreen,
|
|
SetFloatPinned(bool),
|
|
ToggleFloatPinned,
|
|
KillClient,
|
|
ShowBar(bool),
|
|
ToggleBar,
|
|
ShowTitles(bool),
|
|
ToggleTitles,
|
|
FloatTitles(bool),
|
|
ToggleFloatTitles,
|
|
FocusHistory(Timeline),
|
|
FocusLayerRel(LayerDirection),
|
|
FocusTiles,
|
|
ToggleFocusFloatTiled,
|
|
CreateMark,
|
|
JumpToMark,
|
|
PopMode(bool),
|
|
EnableSimpleIm(bool),
|
|
ToggleSimpleImEnabled,
|
|
ReloadSimpleIm,
|
|
EnableUnicodeInput,
|
|
WarpMouseToFocus,
|
|
ToggleTab,
|
|
MakeGroupH,
|
|
MakeGroupV,
|
|
MakeGroupTab,
|
|
ChangeGroupOpposite,
|
|
Equalize,
|
|
EqualizeRecursive,
|
|
MoveTabLeft,
|
|
MoveTabRight,
|
|
SetAutotile(bool),
|
|
ToggleAutotile,
|
|
}
|
|
|
|
#[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(Default, Debug, Clone)]
|
|
pub struct GenericMatch<Match> {
|
|
pub name: Option<String>,
|
|
pub not: Option<Box<Match>>,
|
|
pub all: Option<Vec<Match>>,
|
|
pub any: Option<Vec<Match>>,
|
|
pub exactly: Option<MatchExactly<Match>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct MatchExactly<Match> {
|
|
pub num: usize,
|
|
pub list: Vec<Match>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct ClientRule {
|
|
pub name: Option<String>,
|
|
pub match_: ClientMatch,
|
|
pub action: Option<Action>,
|
|
pub latch: Option<Action>,
|
|
}
|
|
|
|
#[derive(Default, Debug, Clone)]
|
|
pub struct ClientMatch {
|
|
pub generic: GenericMatch<Self>,
|
|
pub sandbox_engine: Option<String>,
|
|
pub sandbox_engine_regex: Option<String>,
|
|
pub sandbox_app_id: Option<String>,
|
|
pub sandbox_app_id_regex: Option<String>,
|
|
pub sandbox_instance_id: Option<String>,
|
|
pub sandbox_instance_id_regex: Option<String>,
|
|
pub sandboxed: Option<bool>,
|
|
pub uid: Option<i32>,
|
|
pub pid: Option<i32>,
|
|
pub is_xwayland: Option<bool>,
|
|
pub comm: Option<String>,
|
|
pub comm_regex: Option<String>,
|
|
pub exe: Option<String>,
|
|
pub exe_regex: Option<String>,
|
|
}
|
|
|
|
#[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(Default, Debug, Clone)]
|
|
pub struct WindowMatch {
|
|
pub generic: GenericMatch<Self>,
|
|
pub types: Option<WindowType>,
|
|
pub client: Option<ClientMatch>,
|
|
pub title: Option<String>,
|
|
pub title_regex: Option<String>,
|
|
pub app_id: Option<String>,
|
|
pub app_id_regex: Option<String>,
|
|
pub floating: Option<bool>,
|
|
pub visible: Option<bool>,
|
|
pub urgent: Option<bool>,
|
|
pub focused: Option<bool>,
|
|
pub fullscreen: Option<bool>,
|
|
pub just_mapped: Option<bool>,
|
|
pub tag: Option<String>,
|
|
pub tag_regex: Option<String>,
|
|
pub x_class: Option<String>,
|
|
pub x_class_regex: Option<String>,
|
|
pub x_instance: Option<String>,
|
|
pub x_instance_regex: Option<String>,
|
|
pub x_role: Option<String>,
|
|
pub x_role_regex: Option<String>,
|
|
pub workspace: Option<String>,
|
|
pub workspace_regex: Option<String>,
|
|
pub content_types: Option<ContentType>,
|
|
}
|
|
|
|
#[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 enum ConfigKeymap {
|
|
Named(String),
|
|
Literal(Keymap),
|
|
Defined { name: String, map: Keymap },
|
|
}
|
|
|
|
#[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(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)]
|
|
pub enum ConfigError {
|
|
#[error("Could not parse the toml document")]
|
|
Toml(#[from] toml_parser::ParserError),
|
|
#[error("Could not interpret the toml as a config document")]
|
|
Parser(#[from] ConfigParserError),
|
|
}
|
|
|
|
pub fn parse_config<F>(
|
|
input: &[u8],
|
|
mark_names: &RefCell<AHashMap<String, u32>>,
|
|
handle_error: F,
|
|
) -> Option<Config>
|
|
where
|
|
F: FnOnce(&dyn Error),
|
|
{
|
|
let cx = Context {
|
|
input,
|
|
used: Default::default(),
|
|
mark_names,
|
|
};
|
|
macro_rules! fatal {
|
|
($e:expr) => {{
|
|
let e = ConfigError::from($e.value);
|
|
let e = cx.error2($e.span, e);
|
|
handle_error(&e);
|
|
return None;
|
|
}};
|
|
}
|
|
let toml = match toml_parser::parse(input, &cx) {
|
|
Ok(t) => t,
|
|
Err(e) => fatal!(e),
|
|
};
|
|
let config = match toml.parse(&mut ConfigParser(&cx)) {
|
|
Ok(c) => c,
|
|
Err(e) => fatal!(e),
|
|
};
|
|
let used = cx.used.take();
|
|
macro_rules! check_defined {
|
|
($name:expr, $used:ident, $defined:ident) => {
|
|
for spanned in &used.$used {
|
|
if !used.$defined.contains(spanned) {
|
|
log::warn!(
|
|
"{} {} used but not defined: {}",
|
|
$name,
|
|
spanned.value,
|
|
cx.error3(spanned.span),
|
|
);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
check_defined!("Keymap", keymaps, defined_keymaps);
|
|
check_defined!("DRM device", drm_devices, defined_drm_devices);
|
|
check_defined!("Output", outputs, defined_outputs);
|
|
check_defined!("Input", inputs, defined_inputs);
|
|
Some(config)
|
|
}
|
|
|
|
#[test]
|
|
fn default_config_parses() {
|
|
let input = include_bytes!("default-config.toml");
|
|
parse_config(input, &Default::default(), |_| ()).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn custom_animation_curve_parses() {
|
|
let input = b"
|
|
[animations]
|
|
curve = [0.25, 0.1, 0.25, 1.0]
|
|
";
|
|
let config = parse_config(input, &Default::default(), |_| ()).unwrap();
|
|
assert_eq!(
|
|
config.animations.curve,
|
|
Some(AnimationCurveConfig::CubicBezier([0.25, 0.1, 0.25, 1.0]))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn animation_style_parses() {
|
|
let input = b"
|
|
[animations]
|
|
style = \"plain\"
|
|
";
|
|
let config = parse_config(input, &Default::default(), |_| ()).unwrap();
|
|
assert_eq!(config.animations.style.as_deref(), Some("plain"));
|
|
}
|