fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 1 | //! The TOML config. Parsing and validation only, the compositor applies it. |
57f44a63d99f | atagen | 2026-10-16 05:34 UTC | 2 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 3 | use monolith_ipc::Command; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 4 | use regex::Regex; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 5 | use serde::Deserialize; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 6 | use std::collections::BTreeMap; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 7 | use std::fmt; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 8 | use std::path::{Path, PathBuf}; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 9 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 10 | pub const DEFAULT: &str = include_str!("../default.toml"); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 11 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 12 | #[derive(Debug, Clone)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 13 | pub struct Config { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 14 | pub general: General, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 15 | pub output: Outputs, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 16 | pub decoration: Decoration, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 17 | pub animation: Animation, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 18 | pub keyboard: Keyboard, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 19 | pub binds: Vec<Bind>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 20 | pub rules: Vec<Rule>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 21 | pub startup: Vec<Vec<String>>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 22 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 23 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 24 | #[derive(Deserialize, Debug, Clone, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 25 | #[serde(default, deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 26 | pub struct General { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 27 | /// What `Mod` means in binds. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 28 | #[serde(rename = "mod")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 29 | pub mod_key: Modifier, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 30 | pub gaps: Gaps, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 31 | /// What a window move does when it meets a neighbour. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 32 | #[serde(rename = "move")] |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 33 | pub move_mode: MoveMode, |
24fca1aad608 | atagen | 2026-10-17 09:56 UTC | 34 | pub focus_follows_mouse: bool, |
24fca1aad608 | atagen | 2026-10-17 09:56 UTC | 35 | pub mouse_follows_focus: bool, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 36 | /// The first window on an empty tag nobody is viewing brings that tag |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 37 | /// into view on its output. |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 38 | pub view_tag_on_first_window: bool, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 39 | } |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 40 | |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 41 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)] |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 42 | #[serde(rename_all = "lowercase")] |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 43 | pub enum MoveMode { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 44 | /// Trade places with it. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 45 | #[default] |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 46 | Swap, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 47 | /// Join its lane, stacking with it if it is alone. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 48 | Merge, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 49 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 50 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 51 | impl Default for General { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 52 | fn default() -> Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 53 | Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 54 | mod_key: Modifier::Super, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 55 | gaps: Gaps::default(), |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 56 | move_mode: MoveMode::Swap, |
24fca1aad608 | atagen | 2026-10-17 09:56 UTC | 57 | focus_follows_mouse: false, |
24fca1aad608 | atagen | 2026-10-17 09:56 UTC | 58 | mouse_follows_focus: false, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 59 | view_tag_on_first_window: true, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 60 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 61 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 62 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 63 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 64 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 65 | #[serde(default, deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 66 | pub struct Gaps { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 67 | pub inner: f64, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 68 | pub outer: f64, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 69 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 70 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 71 | impl Default for Gaps { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 72 | fn default() -> Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 73 | Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 74 | inner: 8.0, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 75 | outer: 8.0, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 76 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 77 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 78 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 79 | |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 80 | #[derive(Deserialize, Debug, Clone, PartialEq, Default)] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 81 | #[serde(default, deny_unknown_fields)] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 82 | pub struct Outputs { |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 83 | pub vrr: Vrr, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 84 | } |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 85 | |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 86 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 87 | #[serde(rename_all = "lowercase")] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 88 | pub enum Vrr { |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 89 | Off, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 90 | On, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 91 | /// Only while a fullscreen window is shown, where a game sets the pace. |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 92 | #[default] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 93 | Fullscreen, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 94 | } |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 95 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 96 | #[derive(Deserialize, Debug, Clone, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 97 | #[serde(default, deny_unknown_fields)] |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 98 | pub struct Decoration { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 99 | /// Border width in logical pixels, drawn in the gap around each window. |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 100 | pub border: u32, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 101 | pub radius: Corners, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 102 | pub focused: Color, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 103 | pub unfocused: Color, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 104 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 105 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 106 | /// Corner radii in logical pixels, top left, top right, bottom right and |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 107 | /// bottom left. One number rounds every corner alike. |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 108 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)] |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 109 | #[serde(from = "CornersToml")] |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 110 | pub struct Corners(pub [u32; 4]); |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 111 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 112 | #[derive(Deserialize)] |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 113 | #[serde(untagged)] |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 114 | enum CornersToml { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 115 | All(u32), |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 116 | Each([u32; 4]), |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 117 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 118 | |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 119 | impl From<CornersToml> for Corners { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 120 | fn from(c: CornersToml) -> Self { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 121 | match c { |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 122 | CornersToml::All(r) => Self([r; 4]), |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 123 | CornersToml::Each(r) => Self(r), |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 124 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 125 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 126 | } |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 127 | |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 128 | impl Default for Decoration { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 129 | fn default() -> Self { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 130 | Self { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 131 | border: 2, |
47259c39793f | atagen | 2026-10-17 10:13 UTC | 132 | radius: Corners([0; 4]), |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 133 | focused: Color::rgb(0x88, 0xbf, 0xd1), |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 134 | unfocused: Color::rgb(0x3b, 0x42, 0x52), |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 135 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 136 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 137 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 138 | |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 139 | /// Straight RGBA from `#rrggbb` or `#rrggbbaa`. |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 140 | #[derive(Debug, Clone, Copy, PartialEq)] |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 141 | pub struct Color(pub [f32; 4]); |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 142 | |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 143 | impl Color { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 144 | pub const fn rgb(r: u8, g: u8, b: u8) -> Self { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 145 | Self([r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0]) |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 146 | } |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 147 | } |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 148 | |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 149 | impl<'de> Deserialize<'de> for Color { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 150 | fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 151 | let s = String::deserialize(d)?; |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 152 | let hex = s.strip_prefix('#').unwrap_or(&s); |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 153 | let bad = |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 154 | || serde::de::Error::custom(format!("bad colour {s:?}, use #rrggbb or #rrggbbaa")); |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 155 | if !matches!(hex.len(), 6 | 8) || !hex.is_ascii() { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 156 | return Err(bad()); |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 157 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 158 | let mut c = [1.0f32; 4]; |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 159 | for (i, v) in c.iter_mut().enumerate().take(hex.len() / 2) { |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 160 | let byte = u8::from_str_radix(&hex[i * 2..i * 2 + 2], 16).map_err(|_| bad())?; |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 161 | *v = f32::from(byte) / 255.0; |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 162 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 163 | Ok(Self(c)) |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 164 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 165 | } |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 166 | |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 167 | #[derive(Deserialize, Debug, Clone, PartialEq)] |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 168 | #[serde(default, deny_unknown_fields)] |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 169 | pub struct Animation { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 170 | pub enabled: bool, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 171 | pub style: AnimationStyle, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 172 | /// Every phase of a planned transition lasts this long. |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 173 | pub phase_ms: u64, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 174 | /// A cubic bezier, as in CSS. |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 175 | pub curve: [f64; 4], |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 176 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 177 | |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 178 | impl Default for Animation { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 179 | fn default() -> Self { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 180 | Self { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 181 | enabled: true, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 182 | style: AnimationStyle::Orthogonal, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 183 | phase_ms: 160, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 184 | curve: [0.45, 0.0, 0.2, 1.0], |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 185 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 186 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 187 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 188 | |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 189 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 190 | #[serde(rename_all = "lowercase")] |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 191 | pub enum AnimationStyle { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 192 | Orthogonal, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 193 | Direct, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 194 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 195 | |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 196 | #[derive(Deserialize, Debug, Clone, PartialEq)] |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 197 | #[serde(default, deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 198 | pub struct Keyboard { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 199 | pub rules: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 200 | pub model: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 201 | pub layout: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 202 | pub variant: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 203 | pub options: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 204 | pub repeat_delay: i32, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 205 | pub repeat_rate: i32, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 206 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 207 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 208 | impl Default for Keyboard { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 209 | fn default() -> Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 210 | Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 211 | rules: String::new(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 212 | model: String::new(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 213 | layout: String::new(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 214 | variant: String::new(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 215 | options: None, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 216 | repeat_delay: 200, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 217 | repeat_rate: 25, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 218 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 219 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 220 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 221 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 222 | #[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 223 | #[serde(rename_all = "lowercase")] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 224 | pub enum Modifier { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 225 | Super, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 226 | Alt, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 227 | Ctrl, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 228 | Shift, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 229 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 230 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 231 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 232 | pub struct Mods { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 233 | pub logo: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 234 | pub alt: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 235 | pub ctrl: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 236 | pub shift: bool, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 237 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 238 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 239 | impl Mods { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 240 | pub fn has(&self, m: Modifier) -> bool { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 241 | match m { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 242 | Modifier::Super => self.logo, |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 243 | Modifier::Alt => self.alt, |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 244 | Modifier::Ctrl => self.ctrl, |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 245 | Modifier::Shift => self.shift, |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 246 | } |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 247 | } |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 248 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 249 | fn set(&mut self, m: Modifier) { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 250 | match m { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 251 | Modifier::Super => self.logo = true, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 252 | Modifier::Alt => self.alt = true, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 253 | Modifier::Ctrl => self.ctrl = true, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 254 | Modifier::Shift => self.shift = true, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 255 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 256 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 257 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 258 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 259 | #[derive(Debug, Clone, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 260 | pub struct Bind { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 261 | pub mods: Mods, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 262 | /// An xkb keysym name, resolved by the compositor. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 263 | pub key: String, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 264 | pub command: Command, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 265 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 266 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 267 | #[derive(Debug, Clone)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 268 | pub struct Rule { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 269 | pub app_id: Option<Regex>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 270 | pub title: Option<Regex>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 271 | pub tag: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 272 | pub output: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 273 | pub floating: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 274 | pub sticky: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 275 | pub scratchpad: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 276 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 277 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 278 | /// Everything the matching rules say about a window, later rules winning. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 279 | #[derive(Debug, Clone, Default, PartialEq)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 280 | pub struct Placement { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 281 | pub tag: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 282 | pub output: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 283 | pub floating: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 284 | pub sticky: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 285 | pub scratchpad: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 286 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 287 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 288 | #[derive(Debug)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 289 | pub enum Error { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 290 | Io(PathBuf, std::io::Error), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 291 | Toml(toml::de::Error), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 292 | Bind(String, String), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 293 | Regex(String, regex::Error), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 294 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 295 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 296 | impl fmt::Display for Error { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 297 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 298 | match self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 299 | Error::Io(p, e) => write!(f, "{}: {e}", p.display()), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 300 | Error::Toml(e) => write!(f, "{e}"), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 301 | Error::Bind(k, e) => write!(f, "bind {k:?}: {e}"), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 302 | Error::Regex(r, e) => write!(f, "rule pattern {r:?}: {e}"), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 303 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 304 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 305 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 306 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 307 | impl std::error::Error for Error {} |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 308 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 309 | #[derive(Deserialize)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 310 | #[serde(deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 311 | struct Raw { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 312 | #[serde(default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 313 | startup: Vec<Vec<String>>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 314 | #[serde(default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 315 | general: General, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 316 | #[serde(default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 317 | keyboard: Keyboard, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 318 | #[serde(default)] |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 319 | animation: Animation, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 320 | #[serde(default)] |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 321 | decoration: Decoration, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 322 | #[serde(default)] |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 323 | output: Outputs, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 324 | #[serde(default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 325 | binds: BTreeMap<String, Words>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 326 | #[serde(default)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 327 | rules: Vec<RawRule>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 328 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 329 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 330 | #[derive(Deserialize)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 331 | #[serde(untagged)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 332 | enum Words { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 333 | Line(String), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 334 | List(Vec<String>), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 335 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 336 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 337 | #[derive(Deserialize)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 338 | #[serde(deny_unknown_fields)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 339 | struct RawRule { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 340 | app_id: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 341 | title: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 342 | tag: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 343 | output: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 344 | floating: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 345 | sticky: Option<bool>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 346 | scratchpad: Option<String>, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 347 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 348 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 349 | impl Config { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 350 | /// `$MONOLITH_CONFIG`, else `$XDG_CONFIG_HOME/monolith/config.toml`. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 351 | pub fn path() -> Option<PathBuf> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 352 | if let Some(p) = std::env::var_os("MONOLITH_CONFIG") { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 353 | return Some(p.into()); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 354 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 355 | let base = std::env::var_os("XDG_CONFIG_HOME") |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 356 | .map(PathBuf::from) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 357 | .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".config")))?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 358 | Some(base.join("monolith/config.toml")) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 359 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 360 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 361 | /// Loads `path`, or the built-in default when it does not exist. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 362 | pub fn load(path: Option<&Path>) -> Result<Self, Error> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 363 | match path { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 364 | Some(p) => match std::fs::read_to_string(p) { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 365 | Ok(text) => Self::parse(&text), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 366 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => Self::parse(DEFAULT), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 367 | Err(e) => Err(Error::Io(p.to_owned(), e)), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 368 | }, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 369 | None => Self::parse(DEFAULT), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 370 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 371 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 372 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 373 | pub fn parse(text: &str) -> Result<Self, Error> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 374 | let raw: Raw = toml::from_str(text).map_err(Error::Toml)?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 375 | let mod_key = raw.general.mod_key; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 376 | let binds = raw |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 377 | .binds |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 378 | .into_iter() |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 379 | .map(|(combo, words)| parse_bind(&combo, words, mod_key)) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 380 | .collect::<Result<_, _>>()?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 381 | let regex = |p: Option<String>| { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 382 | p.map(|p| Regex::new(&p).map_err(|e| Error::Regex(p, e))) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 383 | .transpose() |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 384 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 385 | let rules = raw |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 386 | .rules |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 387 | .into_iter() |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 388 | .map(|r| { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 389 | Ok(Rule { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 390 | app_id: regex(r.app_id)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 391 | title: regex(r.title)?, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 392 | tag: r.tag, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 393 | output: r.output, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 394 | floating: r.floating, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 395 | sticky: r.sticky, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 396 | scratchpad: r.scratchpad, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 397 | }) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 398 | }) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 399 | .collect::<Result<_, Error>>()?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 400 | Ok(Self { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 401 | general: raw.general, |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 402 | animation: raw.animation, |
7ce6ae4e5a85 | atagen | 2026-10-16 12:16 UTC | 403 | decoration: raw.decoration, |
8e6f96f0a32d | atagen | 2026-10-16 22:17 UTC | 404 | output: raw.output, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 405 | keyboard: raw.keyboard, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 406 | binds, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 407 | rules, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 408 | startup: raw.startup, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 409 | }) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 410 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 411 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 412 | pub fn placement(&self, app_id: &str, title: &str) -> Placement { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 413 | let mut p = Placement::default(); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 414 | let hit = |re: &Option<Regex>, s: &str| re.as_ref().is_none_or(|re| re.is_match(s)); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 415 | for r in &self.rules { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 416 | if !hit(&r.app_id, app_id) || !hit(&r.title, title) { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 417 | continue; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 418 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 419 | p.tag = r.tag.clone().or(p.tag); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 420 | p.output = r.output.clone().or(p.output); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 421 | p.floating = r.floating.or(p.floating); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 422 | p.sticky = r.sticky.or(p.sticky); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 423 | p.scratchpad = r.scratchpad.clone().or(p.scratchpad); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 424 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 425 | p |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 426 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 427 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 428 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 429 | fn parse_bind(combo: &str, words: Words, mod_key: Modifier) -> Result<Bind, Error> { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 430 | let bad = |m: String| Error::Bind(combo.to_owned(), m); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 431 | let parts: Vec<&str> = combo.split('+').map(str::trim).collect(); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 432 | let Some((&key, mods)) = parts.split_last().filter(|(k, _)| !k.is_empty()) else { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 433 | return Err(bad("no key".into())); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 434 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 435 | let mut set = Mods::default(); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 436 | for m in mods { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 437 | let m = match m.to_ascii_lowercase().as_str() { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 438 | "mod" => mod_key, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 439 | "super" | "logo" | "win" => Modifier::Super, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 440 | "alt" => Modifier::Alt, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 441 | "ctrl" | "control" => Modifier::Ctrl, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 442 | "shift" => Modifier::Shift, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 443 | other => return Err(bad(format!("unknown modifier {other}"))), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 444 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 445 | set.set(m); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 446 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 447 | let words: Vec<String> = match words { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 448 | Words::Line(s) => s.split_whitespace().map(str::to_owned).collect(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 449 | Words::List(v) => v, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 450 | }; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 451 | let command = Command::parse(&words).map_err(|e| bad(e.0))?; |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 452 | Ok(Bind { |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 453 | mods: set, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 454 | key: key.to_owned(), |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 455 | command, |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 456 | }) |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 457 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 458 | |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 459 | #[cfg(test)] |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 460 | mod tests { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 461 | use super::*; |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 462 | |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 463 | /// default.toml documents the defaults for users, and the Default impls |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 464 | /// apply them to sections a user config leaves out. They must agree. |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 465 | #[test] |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 466 | fn default_toml_states_the_defaults() { |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 467 | let c = Config::parse(DEFAULT).unwrap(); |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 468 | assert_eq!(c.general, General::default()); |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 469 | assert_eq!(c.output, Outputs::default()); |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 470 | assert_eq!(c.decoration, Decoration::default()); |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 471 | assert_eq!(c.animation, Animation::default()); |
b22c0511d5af | atagen | 2026-10-17 03:48 UTC | 472 | assert_eq!(c.keyboard, Keyboard::default()); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 473 | assert!(c.binds.len() > 40); |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 474 | } |
fe835aed6c8d | atagen | 2026-10-16 10:05 UTC | 475 | } |