forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

lib.rs3038 lines, 104.5 KiBHistoryRawDownload
1//! niri config parsing.
2//!
3//! The config can be constructed from multiple files (includes). To support this, many types are
4//! split into two. For example, `Layout` and `LayoutPart` where `Layout` is the final config and
5//! `LayoutPart` is one part parsed from one config file.
6//!
7//! The convention for `Default` impls is to set the initial values before the parsing occurs.
8//! Then, parsing will update the values with those parsed from the config.
9//!
10//! The `Default` values match those from `default-config.kdl` in almost all cases, with a notable
11//! exception of `binds {}` and some window rules.
12
13#[macro_use]
14extern crate tracing;
15
16use std::cell::{Cell, RefCell};
17use std::collections::HashSet;
18use std::ffi::OsStr;
19use std::fs::{self, File};
20use std::io::Write as _;
21use std::path::{Path, PathBuf};
22use std::rc::Rc;
23
24use knuffel::errors::DecodeError;
25use knuffel::Decode as _;
26use miette::{miette, Context as _, IntoDiagnostic as _};
27
28#[macro_use]
29pub mod macros;
30
31pub mod animations;
32pub mod appearance;
33pub mod binds;
34pub mod debug;
35pub mod error;
36pub mod gestures;
37pub mod input;
38pub mod layer_rule;
39pub mod layout;
40pub mod misc;
41pub mod output;
42pub mod recent_windows;
43pub mod utils;
44pub mod window_rule;
45pub mod workspace;
46
47pub use crate::animations::{Animation, Animations};
48pub use crate::appearance::*;
49pub use crate::binds::*;
50pub use crate::debug::Debug;
51pub use crate::error::{ConfigIncludeError, ConfigParseResult};
52pub use crate::gestures::Gestures;
53pub use crate::input::{Input, ModKey, ScrollMethod, TrackLayout, WarpMouseToFocusMode, Xkb};
54pub use crate::layer_rule::LayerRule;
55pub use crate::layout::*;
56pub use crate::misc::*;
57pub use crate::output::{Output, OutputName, Outputs, Position, Vrr};
58use crate::recent_windows::RecentWindowsPart;
59pub use crate::recent_windows::{MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows};
60pub use crate::utils::FloatOrInt;
61use crate::utils::{expand_home_path, Flag, MergeWith as _};
62pub use crate::window_rule::{
63 FloatingPosition, OnXdgActivate, PopupsRule, RelativeTo, ResolvedPopupsRules, WindowRule,
64};
65pub use crate::workspace::{Workspace, WorkspaceLayoutPart};
66
67const RECURSION_LIMIT: u8 = 10;
68
69#[derive(Debug, Default, PartialEq)]
70pub struct Config {
71 pub input: Input,
72 pub outputs: Outputs,
73 pub spawn_at_startup: Vec<SpawnAtStartup>,
74 pub spawn_sh_at_startup: Vec<SpawnShAtStartup>,
75 pub layout: Layout,
76 pub prefer_no_csd: bool,
77 pub cursor: Cursor,
78 pub screenshot_path: ScreenshotPath,
79 pub clipboard: Clipboard,
80 pub hotkey_overlay: HotkeyOverlay,
81 pub config_notification: ConfigNotification,
82 pub animations: Animations,
83 pub blur: Blur,
84 pub gestures: Gestures,
85 pub overview: Overview,
86 pub environment: Environment,
87 pub xwayland_satellite: XwaylandSatellite,
88 pub window_rules: Vec<WindowRule>,
89 pub layer_rules: Vec<LayerRule>,
90 pub binds: Binds,
91 pub switch_events: SwitchBinds,
92 pub debug: Debug,
93 pub workspaces: Vec<Workspace>,
94 pub recent_windows: RecentWindows,
95}
96
97#[derive(Debug, Clone)]
98pub enum ConfigPath {
99 /// Explicitly set config path.
100 ///
101 /// Load the config only from this path, never create it.
102 Explicit(PathBuf),
103
104 /// Default config path.
105 ///
106 /// Prioritize the user path, fallback to the system path, fallback to creating the user path
107 /// at compositor startup.
108 Regular {
109 /// User config path, usually `$XDG_CONFIG_HOME/niri/config.kdl`.
110 user_path: PathBuf,
111 /// System config path, usually `/etc/niri/config.kdl`.
112 system_path: PathBuf,
113 },
114}
115
116// Newtypes for putting information into the knuffel context.
117struct BasePath(PathBuf);
118struct RootBase(PathBuf);
119struct Recursion(u8);
120
121// FIXME: This is currently used to track all the files that needed to be watched. The name
122// `Includes` is not really correct and should be renamed in the future.
123#[derive(Default)]
124struct Includes(Vec<PathBuf>);
125
126#[derive(Default)]
127struct IncludeErrors(Vec<knuffel::Error>);
128// Used for recursive include detection.
129//
130// We don't *need* it because we have a recursion limit, but it makes for nicer error messages.
131struct IncludeStack(HashSet<PathBuf>);
132struct SawMruBinds(Rc<Cell<bool>>);
133
134// Rather than listing all fields and deriving knuffel::Decode, we implement
135// knuffel::DecodeChildren by hand, since we need custom logic for every field anyway: we want to
136// merge the values into the config from the context as we go to support the positionality of
137// includes. The reason we need this type at all is because knuffel's only entry point that allows
138// setting default values on a context is `parse_with_context()` that needs a type to parse.
139pub struct ConfigPart;
140
141impl<S> knuffel::DecodeChildren<S> for ConfigPart
142where
143 S: knuffel::traits::ErrorSpan,
144{
145 fn decode_children(
146 nodes: &[knuffel::ast::SpannedNode<S>],
147 ctx: &mut knuffel::decode::Context<S>,
148 ) -> Result<Self, DecodeError<S>> {
149 let _span = tracy_client::span!("decode config file");
150
151 let config = ctx.get::<Rc<RefCell<Config>>>().unwrap().clone();
152 let includes = ctx.get::<Rc<RefCell<Includes>>>().unwrap().clone();
153 let include_errors = ctx.get::<Rc<RefCell<IncludeErrors>>>().unwrap().clone();
154 let recursion = ctx.get::<Recursion>().unwrap().0;
155 let saw_mru_binds = ctx.get::<SawMruBinds>().unwrap().0.clone();
156
157 let mut seen = HashSet::new();
158
159 for node in nodes {
160 let name = &**node.node_name;
161
162 // Within one config file, splitting sections into multiple parts is not allowed to
163 // reduce confusion. The exceptions here aren't multipart; they all add new values.
164 if !matches!(
165 name,
166 "output"
167 | "spawn-at-startup"
168 | "spawn-sh-at-startup"
169 | "window-rule"
170 | "layer-rule"
171 | "workspace"
172 | "include"
173 ) && !seen.insert(name)
174 {
175 ctx.emit_error(DecodeError::unexpected(
176 &node.node_name,
177 "node",
178 format!("duplicate node `{name}`, single node expected"),
179 ));
180 continue;
181 }
182
183 macro_rules! m_merge {
184 ($field:ident) => {{
185 let part = knuffel::Decode::decode_node(node, ctx)?;
186 config.borrow_mut().$field.merge_with(&part);
187 }};
188 }
189
190 macro_rules! m_push {
191 ($field:ident) => {{
192 let part = knuffel::Decode::decode_node(node, ctx)?;
193 config.borrow_mut().$field.push(part);
194 }};
195 }
196
197 match name {
198 "input" => m_merge!(input),
199 "cursor" => m_merge!(cursor),
200 "clipboard" => m_merge!(clipboard),
201 "hotkey-overlay" => m_merge!(hotkey_overlay),
202 "config-notification" => m_merge!(config_notification),
203 "animations" => m_merge!(animations),
204 "blur" => m_merge!(blur),
205 "gestures" => m_merge!(gestures),
206 "overview" => m_merge!(overview),
207 "xwayland-satellite" => m_merge!(xwayland_satellite),
208 "switch-events" => m_merge!(switch_events),
209 "debug" => m_merge!(debug),
210
211 // Multipart sections.
212 "output" => {
213 let part = Output::decode_node(node, ctx)?;
214 config.borrow_mut().outputs.0.push(part);
215 }
216 "spawn-at-startup" => m_push!(spawn_at_startup),
217 "spawn-sh-at-startup" => m_push!(spawn_sh_at_startup),
218 "window-rule" => m_push!(window_rules),
219 "layer-rule" => m_push!(layer_rules),
220 "workspace" => m_push!(workspaces),
221
222 // Single-part sections.
223 "binds" => {
224 let part = Binds::decode_node(node, ctx)?;
225
226 // We replace conflicting binds, rather than error, to support the use-case
227 // where you import some preconfigured-dots.kdl, then override some binds with
228 // your own.
229 let mut config = config.borrow_mut();
230 let binds = &mut config.binds.0;
231 // Remove existing binds matching any new bind.
232 binds
233 .retain(|bind| !part.0.iter().any(|new| new.key.conflicts_with(&bind.key)));
234 // Add all new binds.
235 binds.extend(part.0);
236 }
237 "environment" => {
238 let part = Environment::decode_node(node, ctx)?;
239 config.borrow_mut().environment.0.extend(part.0);
240 }
241
242 "prefer-no-csd" => {
243 config.borrow_mut().prefer_no_csd = Flag::decode_node(node, ctx)?.0
244 }
245
246 "screenshot-path" => {
247 let part = knuffel::Decode::decode_node(node, ctx)?;
248 config.borrow_mut().screenshot_path = part;
249 }
250
251 "layout" => {
252 let mut part = LayoutPart::decode_node(node, ctx)?;
253
254 // Preserve the behavior we'd always had for the border section:
255 // - `layout {}` gives border = off
256 // - `layout { border {} }` gives border = on
257 // - `layout { border { off } }` gives border = off
258 //
259 // This behavior is inconsistent with the rest of the config where adding an
260 // empty section generally doesn't change the outcome. Particularly, shadows
261 // are also disabled by default (like borders), and they always had an `on`
262 // instead of an `off` for this reason, so that writing `layout { shadow {} }`
263 // still results in shadow = off, as it should.
264 //
265 // Unfortunately, the default config has always had wording that heavily
266 // implies that `layout { border {} }` enables the borders. This wording is
267 // sure to be present in a lot of users' configs by now, which we can't change.
268 //
269 // Another way to make things consistent would be to default borders to on.
270 // However, that is annoying because it would mean changing many tests that
271 // rely on borders being off by default. This would also contradict the
272 // intended default borders value (off).
273 //
274 // So, let's just work around the problem here, preserving the original
275 // behavior.
276 if recursion == 0 {
277 if let Some(border) = part.border.as_mut() {
278 if !border.on && !border.off {
279 border.on = true;
280 }
281 }
282 }
283
284 config.borrow_mut().layout.merge_with(&part);
285 }
286
287 "recent-windows" => {
288 let part = RecentWindowsPart::decode_node(node, ctx)?;
289
290 let mut config = config.borrow_mut();
291
292 // When an MRU binds section is encountered for the first time, clear out the
293 // default MRU binds.
294 if !saw_mru_binds.get() && part.binds.is_some() {
295 saw_mru_binds.set(true);
296 config.recent_windows.binds.clear();
297 }
298
299 config.recent_windows.merge_with(&part);
300 }
301
302 "include" => {
303 // Parse the path argument
304 let mut iter_args = node.arguments.iter();
305 let path_val = iter_args.next().ok_or_else(|| {
306 DecodeError::missing(
307 node,
308 "additional argument for include path is required",
309 )
310 })?;
311 // Check for extra arguments
312 if let Some(val) = iter_args.next() {
313 ctx.emit_error(DecodeError::unexpected(
314 &val.literal,
315 "argument",
316 "unexpected argument",
317 ));
318 }
319
320 // Parse the optional property
321 let mut optional = false;
322 for (name, val) in &node.properties {
323 match &***name {
324 "optional" => {
325 optional = knuffel::traits::DecodeScalar::decode(val, ctx)?;
326 }
327 name_str => {
328 ctx.emit_error(DecodeError::unexpected(
329 name,
330 "property",
331 format!("unexpected property `{}`", name_str.escape_default()),
332 ));
333 }
334 }
335 }
336
337 // Check for unexpected children
338 for child in node.children() {
339 ctx.emit_error(DecodeError::unexpected(
340 child,
341 "node",
342 format!("unexpected node `{}`", child.node_name.escape_default()),
343 ));
344 }
345
346 // We use DecodeError::Missing throughout this block because it results in the
347 // least confusing error messages while still allowing to provide a span.
348
349 let decoded_path = knuffel::traits::DecodeScalar::decode(path_val, ctx)?;
350
351 // Expand ~ into the home dir
352 let Some(path) = expand_home_path(decoded_path, node, ctx) else {
353 continue;
354 };
355
356 let recursion = ctx.get::<Recursion>().unwrap().0 + 1;
357 if recursion == RECURSION_LIMIT {
358 ctx.emit_error(DecodeError::missing(
359 node,
360 format!(
361 "reached the recursion limit; \
362 includes cannot be {RECURSION_LIMIT} levels deep"
363 ),
364 ));
365 continue;
366 }
367
368 let Some(filename) = path.file_name().and_then(OsStr::to_str) else {
369 ctx.emit_error(DecodeError::missing(
370 node,
371 "include path doesn't have a valid file name",
372 ));
373 continue;
374 };
375 let base = path.parent().map(Path::to_path_buf).unwrap_or_default();
376
377 // Check for recursive include for a nicer error message.
378 let mut include_stack = ctx.get::<IncludeStack>().unwrap().0.clone();
379 if !include_stack.insert(path.to_path_buf()) {
380 ctx.emit_error(DecodeError::missing(
381 node,
382 "recursive include (file includes itself)",
383 ));
384 continue;
385 }
386
387 // Store even if the include fails to read or parse, so it gets watched.
388 includes.borrow_mut().0.push(path.to_path_buf());
389
390 match fs::read_to_string(&path) {
391 Ok(text) => {
392 // Try to get filename relative to the root base config folder for
393 // clearer error messages.
394 let root_base = &ctx.get::<RootBase>().unwrap().0;
395 // Failing to strip prefix usually means absolute path; show it in full.
396 let relative_path = path.strip_prefix(root_base).ok().unwrap_or(&path);
397 let filename = relative_path.to_str().unwrap_or(filename);
398
399 let part = knuffel::parse_with_context::<
400 ConfigPart,
401 knuffel::span::Span,
402 _,
403 >(filename, &text, |ctx| {
404 ctx.set(BasePath(base));
405 ctx.set(RootBase(root_base.clone()));
406 ctx.set(Recursion(recursion));
407 ctx.set(includes.clone());
408 ctx.set(include_errors.clone());
409 ctx.set(IncludeStack(include_stack));
410 ctx.set(SawMruBinds(saw_mru_binds.clone()));
411 ctx.set(config.clone());
412 });
413
414 match part {
415 Ok(_) => {}
416 Err(err) => {
417 include_errors.borrow_mut().0.push(err);
418
419 ctx.emit_error(DecodeError::missing(
420 node,
421 "failed to parse included config",
422 ));
423 }
424 }
425 }
426 Err(err) => {
427 if optional && err.kind() == std::io::ErrorKind::NotFound {
428 // Warn about missing optional includes
429 warn!("optional include not found: {path:?}");
430 } else {
431 // Report all other errors normally
432 ctx.emit_error(DecodeError::missing(
433 node,
434 format!("failed to read included config from {path:?}: {err}"),
435 ));
436 }
437 }
438 }
439 }
440
441 name => {
442 ctx.emit_error(DecodeError::unexpected(
443 node,
444 "node",
445 format!("unexpected node `{}`", name.escape_default()),
446 ));
447 }
448 }
449 }
450
451 Ok(Self)
452 }
453}
454
455impl Config {
456 pub fn load_default() -> Self {
457 let res = Config::parse(
458 Path::new("default-config.kdl"),
459 include_str!("../../resources/default-config.kdl"),
460 );
461
462 // Includes in the default config can break its parsing at runtime.
463 assert!(
464 res.includes.is_empty(),
465 "default config must not have includes",
466 );
467
468 res.config.unwrap()
469 }
470
471 pub fn load(path: &Path) -> ConfigParseResult<Self, miette::Report> {
472 let contents = match fs::read_to_string(path) {
473 Ok(x) => x,
474 Err(err) => {
475 return ConfigParseResult::from_err(
476 miette!(err).context(format!("error reading {path:?}")),
477 );
478 }
479 };
480
481 Self::parse(path, &contents).map_config_res(|res| {
482 let config = res.context("error parsing")?;
483 debug!("loaded config from {path:?}");
484 Ok(config)
485 })
486 }
487
488 pub fn parse(path: &Path, text: &str) -> ConfigParseResult<Self, ConfigIncludeError> {
489 let base = path.parent().map(Path::to_path_buf).unwrap_or_default();
490 let filename = path
491 .file_name()
492 .and_then(OsStr::to_str)
493 .unwrap_or("config.kdl");
494
495 let config = Rc::new(RefCell::new(Config::default()));
496 let includes = Rc::new(RefCell::new(Includes(Vec::new())));
497 let include_errors = Rc::new(RefCell::new(IncludeErrors(Vec::new())));
498 let include_stack = HashSet::from([path.to_path_buf()]);
499
500 let part = knuffel::parse_with_context::<ConfigPart, knuffel::span::Span, _>(
501 filename,
502 text,
503 |ctx| {
504 ctx.set(BasePath(base.clone()));
505 ctx.set(RootBase(base));
506 ctx.set(Recursion(0));
507 ctx.set(includes.clone());
508 ctx.set(include_errors.clone());
509 ctx.set(IncludeStack(include_stack));
510 ctx.set(SawMruBinds(Rc::new(Cell::new(false))));
511 ctx.set(config.clone());
512 },
513 );
514
515 let includes = includes.take().0;
516 let include_errors = include_errors.take().0;
517 let config = part
518 .map(|_| config.take())
519 .map_err(move |err| ConfigIncludeError {
520 main: err,
521 includes: include_errors,
522 });
523
524 ConfigParseResult { config, includes }
525 }
526
527 pub fn parse_mem(text: &str) -> Result<Self, ConfigIncludeError> {
528 Self::parse(Path::new("config.kdl"), text).config
529 }
530}
531
532impl ConfigPath {
533 /// Loads the config, returns an error if it doesn't exist.
534 pub fn load(&self) -> ConfigParseResult<Config, miette::Report> {
535 let _span = tracy_client::span!("ConfigPath::load");
536
537 self.load_inner(|user_path, system_path| {
538 Err(miette!(
539 "no config file found; create one at {user_path:?} or {system_path:?}",
540 ))
541 })
542 .map_config_res(|res| res.context("error loading config"))
543 }
544
545 /// Loads the config, or creates it if it doesn't exist.
546 ///
547 /// Returns a tuple containing the path that was created, if any, and the loaded config.
548 ///
549 /// If the config was created, but for some reason could not be read afterwards,
550 /// this may return `(Some(_), Err(_))`.
551 pub fn load_or_create(&self) -> (Option<&Path>, ConfigParseResult<Config, miette::Report>) {
552 let _span = tracy_client::span!("ConfigPath::load_or_create");
553
554 let mut created_at = None;
555
556 let result = self
557 .load_inner(|user_path, _| {
558 Self::create(user_path, &mut created_at)
559 .map(|()| user_path)
560 .with_context(|| format!("error creating config at {user_path:?}"))
561 })
562 .map_config_res(|res| res.context("error loading config"));
563
564 (created_at, result)
565 }
566
567 fn load_inner<'a>(
568 &'a self,
569 maybe_create: impl FnOnce(&'a Path, &'a Path) -> miette::Result<&'a Path>,
570 ) -> ConfigParseResult<Config, miette::Report> {
571 let path = match self {
572 ConfigPath::Explicit(path) => path.as_path(),
573 ConfigPath::Regular {
574 user_path,
575 system_path,
576 } => {
577 if user_path.exists() {
578 user_path.as_path()
579 } else if system_path.exists() {
580 system_path.as_path()
581 } else {
582 match maybe_create(user_path.as_path(), system_path.as_path()) {
583 Ok(x) => x,
584 Err(err) => return ConfigParseResult::from_err(miette!(err)),
585 }
586 }
587 }
588 };
589 Config::load(path)
590 }
591
592 fn create<'a>(path: &'a Path, created_at: &mut Option<&'a Path>) -> miette::Result<()> {
593 if let Some(default_parent) = path.parent() {
594 fs::create_dir_all(default_parent)
595 .into_diagnostic()
596 .with_context(|| format!("error creating config directory {default_parent:?}"))?;
597 }
598
599 // Create the config and fill it with the default config if it doesn't exist.
600 let mut new_file = match File::options()
601 .read(true)
602 .write(true)
603 .create_new(true)
604 .open(path)
605 {
606 Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => return Ok(()),
607 res => res,
608 }
609 .into_diagnostic()
610 .with_context(|| format!("error opening config file at {path:?}"))?;
611
612 *created_at = Some(path);
613
614 let default = include_bytes!("../../resources/default-config.kdl");
615
616 new_file
617 .write_all(default)
618 .into_diagnostic()
619 .with_context(|| format!("error writing default config to {path:?}"))?;
620
621 Ok(())
622 }
623}
624
625#[cfg(test)]
626mod tests {
627 use insta::{assert_debug_snapshot, assert_snapshot};
628 use pretty_assertions::assert_eq;
629 use smithay::input::keyboard::Keysym;
630
631 use super::*;
632
633 #[test]
634 fn can_create_default_config() {
635 let _ = Config::load_default();
636 }
637
638 #[test]
639 fn default_repeat_params() {
640 let config = Config::parse_mem("").unwrap();
641 assert_eq!(config.input.keyboard.repeat_delay, 600);
642 assert_eq!(config.input.keyboard.repeat_rate, 25);
643 }
644
645 #[track_caller]
646 fn do_parse(text: &str) -> Config {
647 Config::parse_mem(text)
648 .map_err(miette::Report::new)
649 .unwrap()
650 }
651
652 #[test]
653 fn parse_release_binds_for_supported_triggers() {
654 // Keys and mouse buttons have release events, so release sections are supported.
655 do_parse(
656 r#"
657 binds {
658 Mod+MouseLeft {
659 release { close-window; }
660 }
661 Mod+Q {
662 press { close-window; }
663 release { close-window; }
664 }
665 }
666 "#,
667 );
668 }
669
670 #[test]
671 fn parse_release_binds_for_unsupported_triggers() {
672 // Scroll ticks are dispatched as press events only, so scroll binds can't have a release
673 // action.
674 assert_parse_error(
675 r#"
676 binds {
677 Mod+WheelScrollDown {
678 release { toggle-overview; }
679 }
680 }
681 "#,
682 "release sections are not supported for scroll binds",
683 );
684 assert_parse_error(
685 r#"
686 binds {
687 Mod+TouchpadScrollDown {
688 release { toggle-overview; }
689 }
690 }
691 "#,
692 "release sections are not supported for scroll binds",
693 );
694 }
695
696 #[test]
697 fn parse_bind_repeat_on_release_only() {
698 // A release-only bind has no press action to repeat, so repeat=true is rejected.
699 assert_parse_error(
700 r#"
701 binds {
702 Mod+Q repeat=true {
703 release { close-window; }
704 }
705 }
706 "#,
707 "release-only binds cannot repeat",
708 );
709
710 do_parse(
711 r#"
712 binds {
713 Mod+T repeat=true { spawn "alacritty"; }
714 Mod+Q repeat=true {
715 press { close-window; }
716 release { close-window; }
717 }
718 Mod+W {
719 release { close-window; }
720 }
721 Mod+E repeat=false {
722 release { close-window; }
723 }
724 }
725 "#,
726 );
727 }
728
729 /// Asserts that parsing fails with a diagnostic containing `message`.
730 #[track_caller]
731 fn assert_parse_error(text: &str, message: &str) {
732 let err = match Config::parse_mem(text) {
733 Ok(_) => panic!("expected a parse error for:\n{text}"),
734 Err(err) => err,
735 };
736
737 // knuffel keeps the individual diagnostics in a private field, so check the Debug
738 // representation, which includes their messages.
739 let err = format!("{err:?}");
740 assert!(
741 err.contains(message),
742 "expected {message:?} in parse error:\n{err}"
743 );
744 }
745
746 #[test]
747 fn parse_bind_section_errors() {
748 // A direct action node and a `press` section both specify the press action, so mixing them
749 // is reported as mixing the two syntaxes rather than as a duplicate `press` section.
750 assert_parse_error(
751 r#"
752 binds {
753 Mod+Q {
754 close-window;
755 press { center-column; }
756 }
757 }
758 "#,
759 "cannot mix direct actions with press/release sections",
760 );
761
762 // A second direct action is a duplicate action, not a mix of the two syntaxes.
763 assert_parse_error(
764 r#"
765 binds {
766 Mod+Q {
767 close-window;
768 center-column;
769 }
770 }
771 "#,
772 "only one action is allowed per keybind",
773 );
774
775 // A direct action following a `press` section is mixing the two syntaxes.
776 assert_parse_error(
777 r#"
778 binds {
779 Mod+Q {
780 press { close-window; }
781 center-column;
782 }
783 }
784 "#,
785 "cannot mix direct actions with press/release sections",
786 );
787
788 // Two `press` sections are still duplicates.
789 assert_parse_error(
790 r#"
791 binds {
792 Mod+Q {
793 press { close-window; }
794 press { center-column; }
795 }
796 }
797 "#,
798 "duplicate `press` section",
799 );
800
801 assert_parse_error(
802 r#"
803 binds {
804 Mod+Q {
805 center-column;
806 release { close-window; }
807 }
808 }
809 "#,
810 "cannot mix direct actions with press/release sections",
811 );
812
813 assert_parse_error(
814 r#"
815 binds {
816 Mod+Q {
817 release { close-window; }
818 center-column;
819 }
820 }
821 "#,
822 "cannot mix direct actions with press/release sections",
823 );
824 }
825
826 #[test]
827 fn parse_bind_bound_action() {
828 let config = do_parse(
829 r#"
830 binds {
831 Mod+A { close-window; }
832 Mod+B {
833 press { close-window; }
834 }
835 Mod+C {
836 release { toggle-overview; }
837 }
838 Mod+D {
839 press { close-window; }
840 release { toggle-overview; }
841 }
842 }
843 "#,
844 );
845
846 let action = |index: usize| &config.binds.0[index].action;
847
848 // A direct action and a press section both bind only the press phase.
849 assert!(matches!(action(0), BoundAction::Press(Action::CloseWindow)));
850 assert!(matches!(action(1), BoundAction::Press(Action::CloseWindow)));
851
852 // A release section binds only the release phase.
853 assert!(matches!(
854 action(2),
855 BoundAction::Release(Action::ToggleOverview)
856 ));
857
858 // Both sections bind both phases.
859 assert!(matches!(
860 action(3),
861 BoundAction::Both {
862 press: Action::CloseWindow,
863 release: Action::ToggleOverview,
864 }
865 ));
866 }
867
868 #[test]
869 fn parse_bare_modifier_keys() {
870 let config = do_parse(
871 r#"
872 binds {
873 Mod {
874 release { toggle-overview; }
875 }
876 Ctrl {
877 release { close-window; }
878 }
879 Shift {
880 release { close-window; }
881 }
882 Alt {
883 release { close-window; }
884 }
885 Super {
886 release { close-window; }
887 }
888 Mod5 {
889 release { close-window; }
890 }
891 Mod3 {
892 release { close-window; }
893 }
894
895 Ctrl+Alt_L {
896 release { close-window; }
897 }
898 }
899 "#,
900 );
901
902 let triggers = config
903 .binds
904 .0
905 .iter()
906 .map(|bind| bind.key.trigger)
907 .collect::<Vec<_>>();
908
909 assert_eq!(
910 triggers,
911 vec![
912 Trigger::CompositorMod,
913 Trigger::Modifier(ModKey::Ctrl),
914 Trigger::Modifier(ModKey::Shift),
915 Trigger::Modifier(ModKey::Alt),
916 Trigger::Modifier(ModKey::Super),
917 Trigger::Modifier(ModKey::IsoLevel3Shift),
918 Trigger::Modifier(ModKey::IsoLevel5Shift),
919 Trigger::Keysym(Keysym::Alt_L),
920 ]
921 );
922
923 // Ctrl+Alt_L has modifiers of Ctrl (manually specified) and Alt (implied by the keysym).
924 assert_eq!(
925 config.binds.0[7].key.modifiers,
926 Modifiers::CTRL | Modifiers::ALT
927 );
928 }
929
930 #[test]
931 fn parse_bind_conflicting_modifier_keys() {
932 // A modifier key can be spelled as the modifier itself (`Alt`) or as its keysym (`Alt_L`),
933 // and a modifier key is triggered by either of its keysyms, so one of these two binds
934 // would always shadow the other.
935 assert_parse_error(
936 r#"
937 binds {
938 Alt {
939 release { toggle-overview; }
940 }
941 Alt_L {
942 release { close-window; }
943 }
944 }
945 "#,
946 "conflicting keybind later defined here",
947 );
948 assert_parse_error(
949 r#"
950 recent-windows {
951 binds {
952 Alt+Control_L { next-window; }
953 Alt+Ctrl { next-window; }
954 }
955 }
956 "#,
957 "conflicting keybind later defined here",
958 );
959
960 // The left and right keysyms are different keys, so those can be bound separately.
961 do_parse(
962 r#"
963 binds {
964 Alt_L {
965 release { close-window; }
966 }
967 Alt_R {
968 release { center-column; }
969 }
970 }
971 "#,
972 );
973
974 // A modifier keysym on its own is an ordinary modifier-only bind.
975 let config = do_parse(
976 r#"
977 binds {
978 Alt_L {
979 release { close-window; }
980 }
981 }
982 "#,
983 );
984 assert!(config.binds.0[0].key.trigger.is_modifier());
985 }
986
987 #[test]
988 fn parse_recent_windows_bind_modifier() {
989 // Modifier-only binds are allowed.
990 do_parse(
991 r#"
992 recent-windows {
993 binds {
994 Ctrl+Alt_L { next-window; }
995 Ctrl+Shift { next-window; }
996 }
997 }
998 "#,
999 );
1000
1001 // Binds must have an extra modifier.
1002 assert_parse_error(
1003 r#"
1004 recent-windows {
1005 binds {
1006 Alt_L { next-window; }
1007 }
1008 }
1009 "#,
1010 "keybind must have a modifier key",
1011 );
1012 assert_parse_error(
1013 r#"
1014 recent-windows {
1015 binds {
1016 Alt+Alt_L { next-window; }
1017 }
1018 }
1019 "#,
1020 "keybind must have a modifier key",
1021 );
1022
1023 // A trigger with no modifier at all is rejected.
1024 assert_parse_error(
1025 r#"
1026 recent-windows {
1027 binds {
1028 Tab { next-window; }
1029 }
1030 }
1031 "#,
1032 "keybind must have a modifier key",
1033 );
1034
1035 // Only keyboard keys are supported here for now.
1036 assert_parse_error(
1037 r#"
1038 recent-windows {
1039 binds {
1040 Alt+MouseLeft { next-window; }
1041 }
1042 }
1043 "#,
1044 "key must be a keyboard key",
1045 );
1046 }
1047
1048 #[test]
1049 fn parse_bind_redundant_modifiers_are_the_same_bind() {
1050 // Redundant modifiers are normalized, so these should error as duplicates.
1051 assert_parse_error(
1052 r#"
1053 binds {
1054 Alt_L { close-window; }
1055 Alt+Alt_L { center-column; }
1056 }
1057 "#,
1058 "duplicate keybind later defined here",
1059 );
1060 assert_parse_error(
1061 r#"
1062 binds {
1063 Alt { close-window; }
1064 Alt+Alt { center-column; }
1065 }
1066 "#,
1067 "duplicate keybind later defined here",
1068 );
1069 assert_parse_error(
1070 r#"
1071 binds {
1072 Mod { close-window; }
1073 Mod+Mod { center-column; }
1074 }
1075 "#,
1076 "duplicate keybind later defined here",
1077 );
1078 assert_parse_error(
1079 r#"
1080 recent-windows {
1081 binds {
1082 Alt+Control_L { next-window; }
1083 Alt+Ctrl+Control_L { next-window; }
1084 }
1085 }
1086 "#,
1087 "duplicate keybind later defined here",
1088 );
1089 }
1090
1091 #[test]
1092 fn parse_on_xdg_activate() {
1093 let parsed = do_parse(
1094 r#"
1095 window-rule { on-xdg-activate "ignore"; }
1096 window-rule { on-xdg-activate "set-urgent"; }
1097 window-rule { on-xdg-activate "focus"; }
1098 "#,
1099 );
1100
1101 assert_eq!(
1102 parsed
1103 .window_rules
1104 .iter()
1105 .map(|rule| rule.on_xdg_activate)
1106 .collect::<Vec<_>>(),
1107 vec![
1108 Some(OnXdgActivate::Ignore),
1109 Some(OnXdgActivate::SetUrgent),
1110 Some(OnXdgActivate::Focus),
1111 ]
1112 );
1113 }
1114
1115 #[test]
1116 fn parse() {
1117 let parsed = do_parse(
1118 r##"
1119 input {
1120 keyboard {
1121 repeat-delay 600
1122 repeat-rate 25
1123 track-layout "window"
1124 xkb {
1125 layout "us,ru"
1126 options "grp:win_space_toggle"
1127 }
1128 }
1129
1130 touchpad {
1131 tap
1132 dwt
1133 dwtp
1134 drag true
1135 click-method "clickfinger"
1136 accel-speed 0.2
1137 accel-profile "flat"
1138 scroll-method "two-finger"
1139 scroll-button 272
1140 scroll-button-lock
1141 tap-button-map "left-middle-right"
1142 disabled-on-external-mouse
1143 scroll-factor 0.9
1144 pinch-sensitivity 1.8
1145 }
1146
1147 mouse {
1148 natural-scroll
1149 accel-speed 0.4
1150 accel-profile "flat"
1151 scroll-method "no-scroll"
1152 scroll-button 273
1153 middle-emulation
1154 scroll-factor 0.2
1155 }
1156
1157 trackpoint {
1158 off
1159 natural-scroll
1160 accel-speed 0.0
1161 accel-profile "flat"
1162 scroll-method "on-button-down"
1163 scroll-button 274
1164 }
1165
1166 trackball {
1167 off
1168 natural-scroll
1169 accel-speed 0.0
1170 accel-profile "flat"
1171 scroll-method "edge"
1172 scroll-button 275
1173 scroll-button-lock
1174 left-handed
1175 middle-emulation
1176 }
1177
1178 tablet {
1179 map-to-output "eDP-1"
1180 map-to-focused-output
1181 map-to-focused-window
1182 calibration-matrix 1.0 2.0 3.0 \
1183 4.0 5.0 6.0
1184 }
1185
1186 touch {
1187 map-to-output "eDP-1"
1188 }
1189
1190 disable-power-key-handling
1191
1192 warp-mouse-to-focus
1193 focus-follows-mouse
1194 workspace-auto-back-and-forth
1195
1196 mod-key "Mod5"
1197 mod-key-nested "Super"
1198 }
1199
1200 output "eDP-1" {
1201 focus-at-startup
1202 scale 2
1203 transform "flipped-90"
1204 position x=10 y=20
1205 mode "1920x1080@144"
1206 max-bpc 10
1207 variable-refresh-rate on-demand=true
1208 background-color "rgba(25, 25, 102, 1.0)"
1209 hot-corners {
1210 off
1211 top-left
1212 top-right
1213 bottom-left
1214 bottom-right
1215 }
1216 }
1217
1218 output "eDP-2" {
1219 mode custom=true "1920x1080@144"
1220 }
1221
1222 output "eDP-3" {
1223 modeline 173.00 1920 2048 2248 2576 1080 1083 1088 1120 "-hsync" "+vsync"
1224 }
1225
1226 layout {
1227 focus-ring {
1228 width 5
1229 active-color 0 100 200 255
1230 inactive-color 255 200 100 0
1231 active-gradient from="rgba(10, 20, 30, 1.0)" to="#0080ffff" relative-to="workspace-view"
1232 }
1233
1234 border {
1235 width 3
1236 inactive-color "rgba(255, 200, 100, 0.0)"
1237 }
1238
1239 shadow {
1240 offset x=10 y=-20
1241 }
1242
1243 tab-indicator {
1244 width 10
1245 position "top"
1246 }
1247
1248 preset-column-widths {
1249 proportion 0.25
1250 proportion 0.5
1251 fixed 960
1252 fixed 1280
1253 }
1254
1255 preset-window-heights {
1256 proportion 0.25
1257 proportion 0.5
1258 fixed 960
1259 fixed 1280
1260 }
1261
1262 default-column-width { proportion 0.25; }
1263
1264 gaps 8
1265
1266 struts {
1267 left 1
1268 right 2
1269 top 3
1270 }
1271
1272 center-focused-column "on-overflow"
1273
1274 default-column-display "tabbed"
1275
1276 insert-hint {
1277 color "rgb(255, 200, 127)"
1278 gradient from="rgba(10, 20, 30, 1.0)" to="#0080ffff" relative-to="workspace-view"
1279 }
1280 }
1281
1282 spawn-at-startup "alacritty" "-e" "fish"
1283 spawn-sh-at-startup "qs -c ~/source/qs/MyAwesomeShell"
1284
1285 prefer-no-csd
1286
1287 cursor {
1288 xcursor-theme "breeze_cursors"
1289 xcursor-size 16
1290 hide-when-typing
1291 hide-after-inactive-ms 3000
1292 }
1293
1294 screenshot-path "~/Screenshots/screenshot.png"
1295
1296 clipboard {
1297 disable-primary
1298 }
1299
1300 hotkey-overlay {
1301 skip-at-startup
1302 }
1303
1304 animations {
1305 slowdown 2.0
1306
1307 workspace-switch {
1308 spring damping-ratio=1.0 stiffness=1000 epsilon=0.0001
1309 }
1310
1311 horizontal-view-movement {
1312 duration-ms 100
1313 curve "ease-out-expo"
1314 }
1315
1316 window-open { off; }
1317
1318 window-close {
1319 curve "cubic-bezier" 0.05 0.7 0.1 1
1320 }
1321
1322 recent-windows-close {
1323 off
1324 }
1325 }
1326
1327 gestures {
1328 dnd-edge-view-scroll {
1329 trigger-width 10
1330 max-speed 50
1331 }
1332 }
1333
1334 environment {
1335 QT_QPA_PLATFORM "wayland"
1336 DISPLAY null
1337 }
1338
1339 window-rule {
1340 match app-id=".*alacritty"
1341 exclude title="~"
1342 exclude is-active=true is-focused=false
1343
1344 open-on-output "eDP-1"
1345 open-maximized true
1346 open-fullscreen false
1347 open-floating false
1348 open-focused true
1349 default-window-height { fixed 500; }
1350 default-column-display "tabbed"
1351 default-floating-position x=100 y=-200 relative-to="bottom-left"
1352 on-xdg-activate "ignore"
1353 variable-refresh-rate "fullscreen-only"
1354
1355 focus-ring {
1356 off
1357 width 3
1358 }
1359
1360 border {
1361 on
1362 width 8.5
1363 }
1364
1365 tab-indicator {
1366 active-color "#f00"
1367 }
1368
1369 pinch-sensitivity 1.2
1370 }
1371
1372 layer-rule {
1373 match namespace="^notifications$"
1374 block-out-from "screencast"
1375 }
1376
1377 binds {
1378 Mod+Escape hotkey-overlay-title="Inhibit" { toggle-keyboard-shortcuts-inhibit; }
1379 Mod+Shift+Escape allow-inhibiting=true { toggle-keyboard-shortcuts-inhibit; }
1380 Mod+T allow-when-locked=true { spawn "alacritty"; }
1381 Mod+Q hotkey-overlay-title=null { close-window; }
1382 Mod+Shift+H { focus-monitor-left; }
1383 Mod+Shift+O { focus-monitor "eDP-1"; }
1384 Mod+Ctrl+Shift+L { move-window-to-monitor-right; }
1385 Mod+Ctrl+Alt+O { move-window-to-monitor "eDP-1"; }
1386 Mod+Ctrl+Alt+P { move-column-to-monitor "DP-1"; }
1387 Mod+Comma { consume-window-into-column; }
1388 Mod+1 { focus-workspace 1; }
1389 Mod+Shift+1 { focus-workspace "workspace-1"; }
1390 Mod+Shift+E allow-inhibiting=false { quit skip-confirmation=true; }
1391 Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
1392 Super+Alt+S allow-when-locked=true { spawn-sh "pkill orca || exec orca"; }
1393 Mod {
1394 release { toggle-overview; }
1395 }
1396 Shift+Mod {
1397 release { toggle-window-floating; }
1398 }
1399 }
1400
1401 switch-events {
1402 tablet-mode-on { spawn "bash" "-c" "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled true"; }
1403 tablet-mode-off { spawn "bash" "-c" "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false"; }
1404 }
1405
1406 debug {
1407 render-drm-device "/dev/dri/renderD129"
1408 ignore-drm-device "/dev/dri/renderD128"
1409 ignore-drm-device "/dev/dri/renderD130"
1410 }
1411
1412 workspace "workspace-1" {
1413 open-on-output "eDP-1"
1414 open-on-output "DP-1"
1415 }
1416 workspace "workspace-2"
1417 workspace "workspace-3"
1418
1419 recent-windows {
1420 off
1421
1422 highlight {
1423 padding 15
1424 active-color "#00ff00"
1425 }
1426
1427 previews {
1428 max-height 960
1429 }
1430
1431 binds {
1432 Alt+Tab { next-window; }
1433 Alt+grave { next-window filter="app-id"; }
1434 Super+Tab { next-window scope="output"; }
1435 }
1436 }
1437 "##,
1438 );
1439
1440 assert_debug_snapshot!(parsed, @r#"
1441 Config {
1442 input: Input {
1443 keyboard: Keyboard {
1444 xkb: Xkb {
1445 rules: "",
1446 model: "",
1447 layout: "us,ru",
1448 variant: "",
1449 options: Some(
1450 "grp:win_space_toggle",
1451 ),
1452 file: None,
1453 },
1454 repeat_delay: 600,
1455 repeat_rate: 25,
1456 track_layout: Window,
1457 numlock: false,
1458 },
1459 touchpad: Touchpad {
1460 off: false,
1461 tap: true,
1462 dwt: true,
1463 dwtp: true,
1464 drag: Some(
1465 true,
1466 ),
1467 drag_lock: false,
1468 natural_scroll: false,
1469 click_method: Some(
1470 Clickfinger,
1471 ),
1472 accel_speed: FloatOrInt(
1473 0.2,
1474 ),
1475 accel_profile: Some(
1476 Flat,
1477 ),
1478 scroll_method: Some(
1479 TwoFinger,
1480 ),
1481 scroll_button: Some(
1482 272,
1483 ),
1484 scroll_button_lock: true,
1485 tap_button_map: Some(
1486 LeftMiddleRight,
1487 ),
1488 left_handed: false,
1489 disabled_on_external_mouse: true,
1490 middle_emulation: false,
1491 scroll_factor: Some(
1492 ScrollFactor {
1493 base: Some(
1494 FloatOrInt(
1495 0.9,
1496 ),
1497 ),
1498 horizontal: None,
1499 vertical: None,
1500 },
1501 ),
1502 pinch_sensitivity: Some(
1503 FloatOrInt(
1504 1.8,
1505 ),
1506 ),
1507 },
1508 mouse: Mouse {
1509 off: false,
1510 natural_scroll: true,
1511 accel_speed: FloatOrInt(
1512 0.4,
1513 ),
1514 accel_profile: Some(
1515 Flat,
1516 ),
1517 scroll_method: Some(
1518 NoScroll,
1519 ),
1520 scroll_button: Some(
1521 273,
1522 ),
1523 scroll_button_lock: false,
1524 left_handed: false,
1525 middle_emulation: true,
1526 scroll_factor: Some(
1527 ScrollFactor {
1528 base: Some(
1529 FloatOrInt(
1530 0.2,
1531 ),
1532 ),
1533 horizontal: None,
1534 vertical: None,
1535 },
1536 ),
1537 },
1538 trackpoint: Trackpoint {
1539 off: true,
1540 natural_scroll: true,
1541 accel_speed: FloatOrInt(
1542 0.0,
1543 ),
1544 accel_profile: Some(
1545 Flat,
1546 ),
1547 scroll_method: Some(
1548 OnButtonDown,
1549 ),
1550 scroll_button: Some(
1551 274,
1552 ),
1553 scroll_button_lock: false,
1554 left_handed: false,
1555 middle_emulation: false,
1556 },
1557 trackball: Trackball {
1558 off: true,
1559 natural_scroll: true,
1560 accel_speed: FloatOrInt(
1561 0.0,
1562 ),
1563 accel_profile: Some(
1564 Flat,
1565 ),
1566 scroll_method: Some(
1567 Edge,
1568 ),
1569 scroll_button: Some(
1570 275,
1571 ),
1572 scroll_button_lock: true,
1573 left_handed: true,
1574 middle_emulation: true,
1575 },
1576 tablet: Tablet {
1577 off: false,
1578 calibration_matrix: Some(
1579 [
1580 1.0,
1581 2.0,
1582 3.0,
1583 4.0,
1584 5.0,
1585 6.0,
1586 ],
1587 ),
1588 map_to_output: Some(
1589 "eDP-1",
1590 ),
1591 map_to_focused_output: true,
1592 map_to_focused_window: true,
1593 left_handed: false,
1594 },
1595 touch: Touch {
1596 off: false,
1597 calibration_matrix: None,
1598 map_to_output: Some(
1599 "eDP-1",
1600 ),
1601 },
1602 disable_power_key_handling: true,
1603 warp_mouse_to_focus: Some(
1604 WarpMouseToFocus {
1605 mode: None,
1606 },
1607 ),
1608 focus_follows_mouse: Some(
1609 FocusFollowsMouse {
1610 max_scroll_amount: None,
1611 },
1612 ),
1613 workspace_auto_back_and_forth: true,
1614 mod_key: Some(
1615 IsoLevel3Shift,
1616 ),
1617 mod_key_nested: Some(
1618 Super,
1619 ),
1620 },
1621 outputs: Outputs(
1622 [
1623 Output {
1624 off: false,
1625 name: "eDP-1",
1626 scale: Some(
1627 FloatOrInt(
1628 2.0,
1629 ),
1630 ),
1631 transform: Flipped90,
1632 position: Some(
1633 Position {
1634 x: 10,
1635 y: 20,
1636 },
1637 ),
1638 max_bpc: Some(
1639 MaxBpc(
1640 _10,
1641 ),
1642 ),
1643 mode: Some(
1644 Mode {
1645 custom: false,
1646 mode: ConfiguredMode {
1647 width: 1920,
1648 height: 1080,
1649 refresh: Some(
1650 144.0,
1651 ),
1652 },
1653 },
1654 ),
1655 modeline: None,
1656 variable_refresh_rate: Some(
1657 Vrr {
1658 on_demand: true,
1659 },
1660 ),
1661 focus_at_startup: true,
1662 background_color: Some(
1663 Color {
1664 r: 0.09803922,
1665 g: 0.09803922,
1666 b: 0.4,
1667 a: 1.0,
1668 },
1669 ),
1670 backdrop_color: None,
1671 hot_corners: Some(
1672 HotCorners {
1673 off: true,
1674 top_left: true,
1675 top_right: true,
1676 bottom_left: true,
1677 bottom_right: true,
1678 },
1679 ),
1680 layout: None,
1681 },
1682 Output {
1683 off: false,
1684 name: "eDP-2",
1685 scale: None,
1686 transform: Normal,
1687 position: None,
1688 max_bpc: None,
1689 mode: Some(
1690 Mode {
1691 custom: true,
1692 mode: ConfiguredMode {
1693 width: 1920,
1694 height: 1080,
1695 refresh: Some(
1696 144.0,
1697 ),
1698 },
1699 },
1700 ),
1701 modeline: None,
1702 variable_refresh_rate: None,
1703 focus_at_startup: false,
1704 background_color: None,
1705 backdrop_color: None,
1706 hot_corners: None,
1707 layout: None,
1708 },
1709 Output {
1710 off: false,
1711 name: "eDP-3",
1712 scale: None,
1713 transform: Normal,
1714 position: None,
1715 max_bpc: None,
1716 mode: None,
1717 modeline: Some(
1718 Modeline {
1719 clock: 173.0,
1720 hdisplay: 1920,
1721 hsync_start: 2048,
1722 hsync_end: 2248,
1723 htotal: 2576,
1724 vdisplay: 1080,
1725 vsync_start: 1083,
1726 vsync_end: 1088,
1727 vtotal: 1120,
1728 hsync_polarity: NHSync,
1729 vsync_polarity: PVSync,
1730 },
1731 ),
1732 variable_refresh_rate: None,
1733 focus_at_startup: false,
1734 background_color: None,
1735 backdrop_color: None,
1736 hot_corners: None,
1737 layout: None,
1738 },
1739 ],
1740 ),
1741 spawn_at_startup: [
1742 SpawnAtStartup {
1743 command: [
1744 "alacritty",
1745 "-e",
1746 "fish",
1747 ],
1748 },
1749 ],
1750 spawn_sh_at_startup: [
1751 SpawnShAtStartup {
1752 command: "qs -c ~/source/qs/MyAwesomeShell",
1753 },
1754 ],
1755 layout: Layout {
1756 focus_ring: FocusRing {
1757 off: false,
1758 width: 5.0,
1759 active_color: Color {
1760 r: 0.0,
1761 g: 0.39215687,
1762 b: 0.78431374,
1763 a: 1.0,
1764 },
1765 inactive_color: Color {
1766 r: 1.0,
1767 g: 0.78431374,
1768 b: 0.39215687,
1769 a: 0.0,
1770 },
1771 urgent_color: Color {
1772 r: 0.60784316,
1773 g: 0.0,
1774 b: 0.0,
1775 a: 1.0,
1776 },
1777 active_gradient: Some(
1778 Gradient {
1779 from: Color {
1780 r: 0.039215688,
1781 g: 0.078431375,
1782 b: 0.11764706,
1783 a: 1.0,
1784 },
1785 to: Color {
1786 r: 0.0,
1787 g: 0.5019608,
1788 b: 1.0,
1789 a: 1.0,
1790 },
1791 angle: 180,
1792 relative_to: WorkspaceView,
1793 in_: GradientInterpolation {
1794 color_space: Srgb,
1795 hue_interpolation: Shorter,
1796 },
1797 },
1798 ),
1799 inactive_gradient: None,
1800 urgent_gradient: None,
1801 },
1802 border: Border {
1803 off: false,
1804 width: 3.0,
1805 active_color: Color {
1806 r: 1.0,
1807 g: 0.78431374,
1808 b: 0.49803922,
1809 a: 1.0,
1810 },
1811 inactive_color: Color {
1812 r: 1.0,
1813 g: 0.78431374,
1814 b: 0.39215687,
1815 a: 0.0,
1816 },
1817 urgent_color: Color {
1818 r: 0.60784316,
1819 g: 0.0,
1820 b: 0.0,
1821 a: 1.0,
1822 },
1823 active_gradient: None,
1824 inactive_gradient: None,
1825 urgent_gradient: None,
1826 },
1827 shadow: Shadow {
1828 on: false,
1829 offset: ShadowOffset {
1830 x: FloatOrInt(
1831 10.0,
1832 ),
1833 y: FloatOrInt(
1834 -20.0,
1835 ),
1836 },
1837 softness: 30.0,
1838 spread: 5.0,
1839 draw_behind_window: false,
1840 color: Color {
1841 r: 0.0,
1842 g: 0.0,
1843 b: 0.0,
1844 a: 0.46666667,
1845 },
1846 inactive_color: None,
1847 },
1848 tab_indicator: TabIndicator {
1849 off: false,
1850 hide_when_single_tab: false,
1851 place_within_column: false,
1852 gap: 5.0,
1853 width: 10.0,
1854 length: TabIndicatorLength {
1855 total_proportion: Some(
1856 0.5,
1857 ),
1858 },
1859 position: Top,
1860 gaps_between_tabs: 0.0,
1861 corner_radius: 0.0,
1862 active_color: None,
1863 inactive_color: None,
1864 urgent_color: None,
1865 active_gradient: None,
1866 inactive_gradient: None,
1867 urgent_gradient: None,
1868 },
1869 insert_hint: InsertHint {
1870 off: false,
1871 color: Color {
1872 r: 1.0,
1873 g: 0.78431374,
1874 b: 0.49803922,
1875 a: 1.0,
1876 },
1877 gradient: Some(
1878 Gradient {
1879 from: Color {
1880 r: 0.039215688,
1881 g: 0.078431375,
1882 b: 0.11764706,
1883 a: 1.0,
1884 },
1885 to: Color {
1886 r: 0.0,
1887 g: 0.5019608,
1888 b: 1.0,
1889 a: 1.0,
1890 },
1891 angle: 180,
1892 relative_to: WorkspaceView,
1893 in_: GradientInterpolation {
1894 color_space: Srgb,
1895 hue_interpolation: Shorter,
1896 },
1897 },
1898 ),
1899 },
1900 preset_column_widths: [
1901 Proportion(
1902 0.25,
1903 ),
1904 Proportion(
1905 0.5,
1906 ),
1907 Fixed(
1908 960,
1909 ),
1910 Fixed(
1911 1280,
1912 ),
1913 ],
1914 default_column_width: Some(
1915 Proportion(
1916 0.25,
1917 ),
1918 ),
1919 preset_window_heights: [
1920 Proportion(
1921 0.25,
1922 ),
1923 Proportion(
1924 0.5,
1925 ),
1926 Fixed(
1927 960,
1928 ),
1929 Fixed(
1930 1280,
1931 ),
1932 ],
1933 center_focused_column: OnOverflow,
1934 always_center_single_column: false,
1935 empty_workspace_above_first: false,
1936 default_column_display: Tabbed,
1937 gaps: 8.0,
1938 struts: Struts {
1939 left: FloatOrInt(
1940 1.0,
1941 ),
1942 right: FloatOrInt(
1943 2.0,
1944 ),
1945 top: FloatOrInt(
1946 3.0,
1947 ),
1948 bottom: FloatOrInt(
1949 0.0,
1950 ),
1951 },
1952 background_color: Color {
1953 r: 0.25,
1954 g: 0.25,
1955 b: 0.25,
1956 a: 1.0,
1957 },
1958 fullscreen_backdrop_color: Color {
1959 r: 0.0,
1960 g: 0.0,
1961 b: 0.0,
1962 a: 1.0,
1963 },
1964 },
1965 prefer_no_csd: true,
1966 cursor: Cursor {
1967 xcursor_theme: "breeze_cursors",
1968 xcursor_size: 16,
1969 hide_when_typing: true,
1970 hide_after_inactive_ms: Some(
1971 3000,
1972 ),
1973 },
1974 screenshot_path: ScreenshotPath(
1975 Some(
1976 "~/Screenshots/screenshot.png",
1977 ),
1978 ),
1979 clipboard: Clipboard {
1980 disable_primary: true,
1981 },
1982 hotkey_overlay: HotkeyOverlay {
1983 skip_at_startup: true,
1984 hide_not_bound: false,
1985 },
1986 config_notification: ConfigNotification {
1987 disable_failed: false,
1988 },
1989 animations: Animations {
1990 off: false,
1991 slowdown: 2.0,
1992 workspace_switch: WorkspaceSwitchAnim(
1993 Animation {
1994 off: false,
1995 kind: Spring(
1996 SpringParams {
1997 damping_ratio: 1.0,
1998 stiffness: 1000,
1999 epsilon: 0.0001,
2000 },
2001 ),
2002 },
2003 ),
2004 window_open: WindowOpenAnim {
2005 anim: Animation {
2006 off: true,
2007 kind: Easing(
2008 EasingParams {
2009 duration_ms: 150,
2010 curve: EaseOutExpo,
2011 },
2012 ),
2013 },
2014 custom_shader: None,
2015 },
2016 window_close: WindowCloseAnim {
2017 anim: Animation {
2018 off: false,
2019 kind: Easing(
2020 EasingParams {
2021 duration_ms: 150,
2022 curve: CubicBezier(
2023 0.05,
2024 0.7,
2025 0.1,
2026 1.0,
2027 ),
2028 },
2029 ),
2030 },
2031 custom_shader: None,
2032 },
2033 horizontal_view_movement: HorizontalViewMovementAnim(
2034 Animation {
2035 off: false,
2036 kind: Easing(
2037 EasingParams {
2038 duration_ms: 100,
2039 curve: EaseOutExpo,
2040 },
2041 ),
2042 },
2043 ),
2044 window_movement: WindowMovementAnim(
2045 Animation {
2046 off: false,
2047 kind: Spring(
2048 SpringParams {
2049 damping_ratio: 1.0,
2050 stiffness: 800,
2051 epsilon: 0.0001,
2052 },
2053 ),
2054 },
2055 ),
2056 window_resize: WindowResizeAnim {
2057 anim: Animation {
2058 off: false,
2059 kind: Spring(
2060 SpringParams {
2061 damping_ratio: 1.0,
2062 stiffness: 800,
2063 epsilon: 0.0001,
2064 },
2065 ),
2066 },
2067 custom_shader: None,
2068 },
2069 config_notification_open_close: ConfigNotificationOpenCloseAnim(
2070 Animation {
2071 off: false,
2072 kind: Spring(
2073 SpringParams {
2074 damping_ratio: 0.6,
2075 stiffness: 1000,
2076 epsilon: 0.001,
2077 },
2078 ),
2079 },
2080 ),
2081 exit_confirmation_open_close: ExitConfirmationOpenCloseAnim(
2082 Animation {
2083 off: false,
2084 kind: Spring(
2085 SpringParams {
2086 damping_ratio: 0.6,
2087 stiffness: 500,
2088 epsilon: 0.01,
2089 },
2090 ),
2091 },
2092 ),
2093 screenshot_ui_open: ScreenshotUiOpenAnim(
2094 Animation {
2095 off: false,
2096 kind: Easing(
2097 EasingParams {
2098 duration_ms: 200,
2099 curve: EaseOutQuad,
2100 },
2101 ),
2102 },
2103 ),
2104 overview_open_close: OverviewOpenCloseAnim(
2105 Animation {
2106 off: false,
2107 kind: Spring(
2108 SpringParams {
2109 damping_ratio: 1.0,
2110 stiffness: 800,
2111 epsilon: 0.0001,
2112 },
2113 ),
2114 },
2115 ),
2116 recent_windows_close: RecentWindowsCloseAnim(
2117 Animation {
2118 off: true,
2119 kind: Spring(
2120 SpringParams {
2121 damping_ratio: 1.0,
2122 stiffness: 800,
2123 epsilon: 0.001,
2124 },
2125 ),
2126 },
2127 ),
2128 },
2129 blur: Blur {
2130 off: false,
2131 passes: 3,
2132 offset: 3.0,
2133 noise: 0.02,
2134 saturation: 1.5,
2135 },
2136 gestures: Gestures {
2137 dnd_edge_view_scroll: DndEdgeViewScroll {
2138 trigger_width: 10.0,
2139 delay_ms: 100,
2140 max_speed: 50.0,
2141 },
2142 dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch {
2143 trigger_height: 50.0,
2144 delay_ms: 100,
2145 max_speed: 1500.0,
2146 },
2147 hot_corners: HotCorners {
2148 off: false,
2149 top_left: false,
2150 top_right: false,
2151 bottom_left: false,
2152 bottom_right: false,
2153 },
2154 },
2155 overview: Overview {
2156 zoom: 0.5,
2157 backdrop_color: Color {
2158 r: 0.15,
2159 g: 0.15,
2160 b: 0.15,
2161 a: 1.0,
2162 },
2163 workspace_shadow: WorkspaceShadow {
2164 off: false,
2165 offset: ShadowOffset {
2166 x: FloatOrInt(
2167 0.0,
2168 ),
2169 y: FloatOrInt(
2170 10.0,
2171 ),
2172 },
2173 softness: 40.0,
2174 spread: 10.0,
2175 color: Color {
2176 r: 0.0,
2177 g: 0.0,
2178 b: 0.0,
2179 a: 0.3137255,
2180 },
2181 },
2182 },
2183 environment: Environment(
2184 [
2185 EnvironmentVariable {
2186 name: "QT_QPA_PLATFORM",
2187 value: Some(
2188 "wayland",
2189 ),
2190 },
2191 EnvironmentVariable {
2192 name: "DISPLAY",
2193 value: None,
2194 },
2195 ],
2196 ),
2197 xwayland_satellite: XwaylandSatellite {
2198 off: false,
2199 path: "xwayland-satellite",
2200 },
2201 window_rules: [
2202 WindowRule {
2203 matches: [
2204 Match {
2205 app_id: Some(
2206 RegexEq(
2207 Regex(
2208 ".*alacritty",
2209 ),
2210 ),
2211 ),
2212 title: None,
2213 is_active: None,
2214 is_focused: None,
2215 is_active_in_column: None,
2216 is_floating: None,
2217 is_window_cast_target: None,
2218 is_urgent: None,
2219 at_startup: None,
2220 },
2221 ],
2222 excludes: [
2223 Match {
2224 app_id: None,
2225 title: Some(
2226 RegexEq(
2227 Regex(
2228 "~",
2229 ),
2230 ),
2231 ),
2232 is_active: None,
2233 is_focused: None,
2234 is_active_in_column: None,
2235 is_floating: None,
2236 is_window_cast_target: None,
2237 is_urgent: None,
2238 at_startup: None,
2239 },
2240 Match {
2241 app_id: None,
2242 title: None,
2243 is_active: Some(
2244 true,
2245 ),
2246 is_focused: Some(
2247 false,
2248 ),
2249 is_active_in_column: None,
2250 is_floating: None,
2251 is_window_cast_target: None,
2252 is_urgent: None,
2253 at_startup: None,
2254 },
2255 ],
2256 default_column_width: None,
2257 default_window_height: Some(
2258 DefaultPresetSize(
2259 Some(
2260 Fixed(
2261 500,
2262 ),
2263 ),
2264 ),
2265 ),
2266 open_on_output: Some(
2267 "eDP-1",
2268 ),
2269 open_on_workspace: None,
2270 open_maximized: Some(
2271 true,
2272 ),
2273 open_maximized_to_edges: None,
2274 open_fullscreen: Some(
2275 false,
2276 ),
2277 open_floating: Some(
2278 false,
2279 ),
2280 open_focused: Some(
2281 true,
2282 ),
2283 on_xdg_activate: Some(
2284 Ignore,
2285 ),
2286 min_width: None,
2287 min_height: None,
2288 max_width: None,
2289 max_height: None,
2290 focus_ring: BorderRule {
2291 off: true,
2292 on: false,
2293 width: Some(
2294 FloatOrInt(
2295 3.0,
2296 ),
2297 ),
2298 active_color: None,
2299 inactive_color: None,
2300 urgent_color: None,
2301 active_gradient: None,
2302 inactive_gradient: None,
2303 urgent_gradient: None,
2304 },
2305 border: BorderRule {
2306 off: false,
2307 on: true,
2308 width: Some(
2309 FloatOrInt(
2310 8.5,
2311 ),
2312 ),
2313 active_color: None,
2314 inactive_color: None,
2315 urgent_color: None,
2316 active_gradient: None,
2317 inactive_gradient: None,
2318 urgent_gradient: None,
2319 },
2320 shadow: ShadowRule {
2321 off: false,
2322 on: false,
2323 offset: None,
2324 softness: None,
2325 spread: None,
2326 draw_behind_window: None,
2327 color: None,
2328 inactive_color: None,
2329 },
2330 tab_indicator: TabIndicatorRule {
2331 active_color: Some(
2332 Color {
2333 r: 1.0,
2334 g: 0.0,
2335 b: 0.0,
2336 a: 1.0,
2337 },
2338 ),
2339 inactive_color: None,
2340 urgent_color: None,
2341 active_gradient: None,
2342 inactive_gradient: None,
2343 urgent_gradient: None,
2344 },
2345 draw_border_with_background: None,
2346 opacity: None,
2347 geometry_corner_radius: None,
2348 clip_to_geometry: None,
2349 baba_is_float: None,
2350 block_out_from: None,
2351 variable_refresh_rate: Some(
2352 FullscreenOnly,
2353 ),
2354 default_column_display: Some(
2355 Tabbed,
2356 ),
2357 default_floating_position: Some(
2358 FloatingPosition {
2359 x: FloatOrInt(
2360 100.0,
2361 ),
2362 y: FloatOrInt(
2363 -200.0,
2364 ),
2365 relative_to: BottomLeft,
2366 },
2367 ),
2368 scroll_factor: None,
2369 pinch_sensitivity: Some(
2370 FloatOrInt(
2371 1.2,
2372 ),
2373 ),
2374 tiled_state: None,
2375 background_effect: BackgroundEffectRule {
2376 xray: None,
2377 blur: None,
2378 noise: None,
2379 saturation: None,
2380 },
2381 popups: PopupsRule {
2382 opacity: None,
2383 geometry_corner_radius: None,
2384 background_effect: BackgroundEffectRule {
2385 xray: None,
2386 blur: None,
2387 noise: None,
2388 saturation: None,
2389 },
2390 },
2391 },
2392 ],
2393 layer_rules: [
2394 LayerRule {
2395 matches: [
2396 Match {
2397 namespace: Some(
2398 RegexEq(
2399 Regex(
2400 "^notifications$",
2401 ),
2402 ),
2403 ),
2404 at_startup: None,
2405 layer: None,
2406 },
2407 ],
2408 excludes: [],
2409 opacity: None,
2410 block_out_from: Some(
2411 Screencast,
2412 ),
2413 shadow: ShadowRule {
2414 off: false,
2415 on: false,
2416 offset: None,
2417 softness: None,
2418 spread: None,
2419 draw_behind_window: None,
2420 color: None,
2421 inactive_color: None,
2422 },
2423 geometry_corner_radius: None,
2424 place_within_backdrop: None,
2425 baba_is_float: None,
2426 background_effect: BackgroundEffectRule {
2427 xray: None,
2428 blur: None,
2429 noise: None,
2430 saturation: None,
2431 },
2432 popups: PopupsRule {
2433 opacity: None,
2434 geometry_corner_radius: None,
2435 background_effect: BackgroundEffectRule {
2436 xray: None,
2437 blur: None,
2438 noise: None,
2439 saturation: None,
2440 },
2441 },
2442 },
2443 ],
2444 binds: Binds(
2445 [
2446 Bind {
2447 key: Key {
2448 trigger: Keysym(
2449 XK_Escape,
2450 ),
2451 modifiers: Modifiers(
2452 COMPOSITOR,
2453 ),
2454 },
2455 action: Press(
2456 ToggleKeyboardShortcutsInhibit,
2457 ),
2458 repeat: true,
2459 cooldown: None,
2460 allow_when_locked: false,
2461 allow_inhibiting: false,
2462 hotkey_overlay_title: Some(
2463 Some(
2464 "Inhibit",
2465 ),
2466 ),
2467 },
2468 Bind {
2469 key: Key {
2470 trigger: Keysym(
2471 XK_Escape,
2472 ),
2473 modifiers: Modifiers(
2474 SHIFT | COMPOSITOR,
2475 ),
2476 },
2477 action: Press(
2478 ToggleKeyboardShortcutsInhibit,
2479 ),
2480 repeat: true,
2481 cooldown: None,
2482 allow_when_locked: false,
2483 allow_inhibiting: false,
2484 hotkey_overlay_title: None,
2485 },
2486 Bind {
2487 key: Key {
2488 trigger: Keysym(
2489 XK_t,
2490 ),
2491 modifiers: Modifiers(
2492 COMPOSITOR,
2493 ),
2494 },
2495 action: Press(
2496 Spawn(
2497 [
2498 "alacritty",
2499 ],
2500 ),
2501 ),
2502 repeat: true,
2503 cooldown: None,
2504 allow_when_locked: true,
2505 allow_inhibiting: true,
2506 hotkey_overlay_title: None,
2507 },
2508 Bind {
2509 key: Key {
2510 trigger: Keysym(
2511 XK_q,
2512 ),
2513 modifiers: Modifiers(
2514 COMPOSITOR,
2515 ),
2516 },
2517 action: Press(
2518 CloseWindow,
2519 ),
2520 repeat: true,
2521 cooldown: None,
2522 allow_when_locked: false,
2523 allow_inhibiting: true,
2524 hotkey_overlay_title: Some(
2525 None,
2526 ),
2527 },
2528 Bind {
2529 key: Key {
2530 trigger: Keysym(
2531 XK_h,
2532 ),
2533 modifiers: Modifiers(
2534 SHIFT | COMPOSITOR,
2535 ),
2536 },
2537 action: Press(
2538 FocusMonitorLeft,
2539 ),
2540 repeat: true,
2541 cooldown: None,
2542 allow_when_locked: false,
2543 allow_inhibiting: true,
2544 hotkey_overlay_title: None,
2545 },
2546 Bind {
2547 key: Key {
2548 trigger: Keysym(
2549 XK_o,
2550 ),
2551 modifiers: Modifiers(
2552 SHIFT | COMPOSITOR,
2553 ),
2554 },
2555 action: Press(
2556 FocusMonitor(
2557 "eDP-1",
2558 ),
2559 ),
2560 repeat: true,
2561 cooldown: None,
2562 allow_when_locked: false,
2563 allow_inhibiting: true,
2564 hotkey_overlay_title: None,
2565 },
2566 Bind {
2567 key: Key {
2568 trigger: Keysym(
2569 XK_l,
2570 ),
2571 modifiers: Modifiers(
2572 CTRL | SHIFT | COMPOSITOR,
2573 ),
2574 },
2575 action: Press(
2576 MoveWindowToMonitorRight,
2577 ),
2578 repeat: true,
2579 cooldown: None,
2580 allow_when_locked: false,
2581 allow_inhibiting: true,
2582 hotkey_overlay_title: None,
2583 },
2584 Bind {
2585 key: Key {
2586 trigger: Keysym(
2587 XK_o,
2588 ),
2589 modifiers: Modifiers(
2590 CTRL | ALT | COMPOSITOR,
2591 ),
2592 },
2593 action: Press(
2594 MoveWindowToMonitor(
2595 "eDP-1",
2596 ),
2597 ),
2598 repeat: true,
2599 cooldown: None,
2600 allow_when_locked: false,
2601 allow_inhibiting: true,
2602 hotkey_overlay_title: None,
2603 },
2604 Bind {
2605 key: Key {
2606 trigger: Keysym(
2607 XK_p,
2608 ),
2609 modifiers: Modifiers(
2610 CTRL | ALT | COMPOSITOR,
2611 ),
2612 },
2613 action: Press(
2614 MoveColumnToMonitor(
2615 "DP-1",
2616 ),
2617 ),
2618 repeat: true,
2619 cooldown: None,
2620 allow_when_locked: false,
2621 allow_inhibiting: true,
2622 hotkey_overlay_title: None,
2623 },
2624 Bind {
2625 key: Key {
2626 trigger: Keysym(
2627 XK_comma,
2628 ),
2629 modifiers: Modifiers(
2630 COMPOSITOR,
2631 ),
2632 },
2633 action: Press(
2634 ConsumeWindowIntoColumn,
2635 ),
2636 repeat: true,
2637 cooldown: None,
2638 allow_when_locked: false,
2639 allow_inhibiting: true,
2640 hotkey_overlay_title: None,
2641 },
2642 Bind {
2643 key: Key {
2644 trigger: Keysym(
2645 XK_1,
2646 ),
2647 modifiers: Modifiers(
2648 COMPOSITOR,
2649 ),
2650 },
2651 action: Press(
2652 FocusWorkspace(
2653 Index(
2654 1,
2655 ),
2656 ),
2657 ),
2658 repeat: true,
2659 cooldown: None,
2660 allow_when_locked: false,
2661 allow_inhibiting: true,
2662 hotkey_overlay_title: None,
2663 },
2664 Bind {
2665 key: Key {
2666 trigger: Keysym(
2667 XK_1,
2668 ),
2669 modifiers: Modifiers(
2670 SHIFT | COMPOSITOR,
2671 ),
2672 },
2673 action: Press(
2674 FocusWorkspace(
2675 Name(
2676 "workspace-1",
2677 ),
2678 ),
2679 ),
2680 repeat: true,
2681 cooldown: None,
2682 allow_when_locked: false,
2683 allow_inhibiting: true,
2684 hotkey_overlay_title: None,
2685 },
2686 Bind {
2687 key: Key {
2688 trigger: Keysym(
2689 XK_e,
2690 ),
2691 modifiers: Modifiers(
2692 SHIFT | COMPOSITOR,
2693 ),
2694 },
2695 action: Press(
2696 Quit(
2697 true,
2698 ),
2699 ),
2700 repeat: true,
2701 cooldown: None,
2702 allow_when_locked: false,
2703 allow_inhibiting: false,
2704 hotkey_overlay_title: None,
2705 },
2706 Bind {
2707 key: Key {
2708 trigger: WheelScrollDown,
2709 modifiers: Modifiers(
2710 COMPOSITOR,
2711 ),
2712 },
2713 action: Press(
2714 FocusWorkspaceDown,
2715 ),
2716 repeat: true,
2717 cooldown: Some(
2718 150ms,
2719 ),
2720 allow_when_locked: false,
2721 allow_inhibiting: true,
2722 hotkey_overlay_title: None,
2723 },
2724 Bind {
2725 key: Key {
2726 trigger: Keysym(
2727 XK_s,
2728 ),
2729 modifiers: Modifiers(
2730 ALT | SUPER,
2731 ),
2732 },
2733 action: Press(
2734 SpawnSh(
2735 "pkill orca || exec orca",
2736 ),
2737 ),
2738 repeat: true,
2739 cooldown: None,
2740 allow_when_locked: true,
2741 allow_inhibiting: true,
2742 hotkey_overlay_title: None,
2743 },
2744 Bind {
2745 key: Key {
2746 trigger: CompositorMod,
2747 modifiers: Modifiers(
2748 COMPOSITOR,
2749 ),
2750 },
2751 action: Release(
2752 ToggleOverview,
2753 ),
2754 repeat: false,
2755 cooldown: None,
2756 allow_when_locked: false,
2757 allow_inhibiting: true,
2758 hotkey_overlay_title: None,
2759 },
2760 Bind {
2761 key: Key {
2762 trigger: CompositorMod,
2763 modifiers: Modifiers(
2764 SHIFT | COMPOSITOR,
2765 ),
2766 },
2767 action: Release(
2768 ToggleWindowFloating,
2769 ),
2770 repeat: false,
2771 cooldown: None,
2772 allow_when_locked: false,
2773 allow_inhibiting: true,
2774 hotkey_overlay_title: None,
2775 },
2776 ],
2777 ),
2778 switch_events: SwitchBinds {
2779 lid_open: None,
2780 lid_close: None,
2781 tablet_mode_on: Some(
2782 SwitchAction {
2783 spawn: [
2784 "bash",
2785 "-c",
2786 "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled true",
2787 ],
2788 },
2789 ),
2790 tablet_mode_off: Some(
2791 SwitchAction {
2792 spawn: [
2793 "bash",
2794 "-c",
2795 "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false",
2796 ],
2797 },
2798 ),
2799 },
2800 debug: Debug {
2801 preview_render: None,
2802 dbus_interfaces_in_non_session_instances: false,
2803 wait_for_frame_completion_before_queueing: false,
2804 enable_overlay_planes: false,
2805 disable_cursor_plane: false,
2806 disable_direct_scanout: false,
2807 restrict_primary_scanout_to_matching_format: false,
2808 force_disable_connectors_on_resume: false,
2809 render_drm_device: Some(
2810 "/dev/dri/renderD129",
2811 ),
2812 ignored_drm_devices: [
2813 "/dev/dri/renderD128",
2814 "/dev/dri/renderD130",
2815 ],
2816 force_pipewire_invalid_modifier: false,
2817 disable_pipewire_dmabuf: false,
2818 emulate_zero_presentation_time: false,
2819 disable_resize_throttling: false,
2820 disable_transactions: false,
2821 keep_laptop_panel_on_when_lid_is_closed: false,
2822 disable_monitor_names: false,
2823 strict_new_window_focus_policy: false,
2824 honor_xdg_activation_with_invalid_serial: false,
2825 deactivate_unfocused_windows: false,
2826 skip_cursor_only_updates_during_vrr: false,
2827 disable_10bit_output: false,
2828 },
2829 workspaces: [
2830 Workspace {
2831 name: WorkspaceName(
2832 "workspace-1",
2833 ),
2834 open_on_output: [
2835 "eDP-1",
2836 "DP-1",
2837 ],
2838 layout: None,
2839 },
2840 Workspace {
2841 name: WorkspaceName(
2842 "workspace-2",
2843 ),
2844 open_on_output: [],
2845 layout: None,
2846 },
2847 Workspace {
2848 name: WorkspaceName(
2849 "workspace-3",
2850 ),
2851 open_on_output: [],
2852 layout: None,
2853 },
2854 ],
2855 recent_windows: RecentWindows {
2856 on: false,
2857 debounce_ms: 750,
2858 open_delay_ms: 150,
2859 highlight: MruHighlight {
2860 active_color: Color {
2861 r: 0.0,
2862 g: 1.0,
2863 b: 0.0,
2864 a: 1.0,
2865 },
2866 urgent_color: Color {
2867 r: 1.0,
2868 g: 0.6,
2869 b: 0.6,
2870 a: 1.0,
2871 },
2872 padding: 15.0,
2873 corner_radius: 0.0,
2874 },
2875 previews: MruPreviews {
2876 max_height: 960.0,
2877 max_scale: 0.5,
2878 },
2879 binds: [
2880 Bind {
2881 key: Key {
2882 trigger: Keysym(
2883 XK_Tab,
2884 ),
2885 modifiers: Modifiers(
2886 ALT,
2887 ),
2888 },
2889 action: Press(
2890 MruAdvance {
2891 direction: Forward,
2892 scope: None,
2893 filter: Some(
2894 All,
2895 ),
2896 },
2897 ),
2898 repeat: true,
2899 cooldown: None,
2900 allow_when_locked: false,
2901 allow_inhibiting: true,
2902 hotkey_overlay_title: None,
2903 },
2904 Bind {
2905 key: Key {
2906 trigger: Keysym(
2907 XK_grave,
2908 ),
2909 modifiers: Modifiers(
2910 ALT,
2911 ),
2912 },
2913 action: Press(
2914 MruAdvance {
2915 direction: Forward,
2916 scope: None,
2917 filter: Some(
2918 AppId,
2919 ),
2920 },
2921 ),
2922 repeat: true,
2923 cooldown: None,
2924 allow_when_locked: false,
2925 allow_inhibiting: true,
2926 hotkey_overlay_title: None,
2927 },
2928 Bind {
2929 key: Key {
2930 trigger: Keysym(
2931 XK_Tab,
2932 ),
2933 modifiers: Modifiers(
2934 SUPER,
2935 ),
2936 },
2937 action: Press(
2938 MruAdvance {
2939 direction: Forward,
2940 scope: Some(
2941 Output,
2942 ),
2943 filter: Some(
2944 All,
2945 ),
2946 },
2947 ),
2948 repeat: true,
2949 cooldown: None,
2950 allow_when_locked: false,
2951 allow_inhibiting: true,
2952 hotkey_overlay_title: None,
2953 },
2954 ],
2955 },
2956 }
2957 "#);
2958 }
2959
2960 fn diff_lines(expected: &str, actual: &str) -> String {
2961 let mut output = String::new();
2962 let mut in_change = false;
2963
2964 for change in diff::lines(expected, actual) {
2965 match change {
2966 diff::Result::Both(_, _) => {
2967 in_change = false;
2968 }
2969 diff::Result::Left(line) => {
2970 if !output.is_empty() && !in_change {
2971 output.push('\n');
2972 }
2973 output.push('-');
2974 output.push_str(line);
2975 output.push('\n');
2976 in_change = true;
2977 }
2978 diff::Result::Right(line) => {
2979 if !output.is_empty() && !in_change {
2980 output.push('\n');
2981 }
2982 output.push('+');
2983 output.push_str(line);
2984 output.push('\n');
2985 in_change = true;
2986 }
2987 }
2988 }
2989
2990 output
2991 }
2992
2993 #[test]
2994 fn diff_empty_to_default() {
2995 // We try to write the config defaults in such a way that empty sections (and an empty
2996 // config) give the same outcome as the default config bundled with niri. This test
2997 // verifies the actual differences between the two.
2998 let mut default_config = Config::load_default();
2999 let empty_config = Config::parse_mem("").unwrap();
3000
3001 // Some notable omissions: the default config has some window rules, and an empty config
3002 // will not have any binds. Clear them out so they don't spam the diff.
3003 default_config.window_rules.clear();
3004 default_config.binds.0.clear();
3005
3006 assert_snapshot!(
3007 diff_lines(
3008 &format!("{empty_config:#?}"),
3009 &format!("{default_config:#?}")
3010 ),
3011 @r#"
3012 - numlock: false,
3013 + numlock: true,
3014
3015 - tap: false,
3016 + tap: true,
3017
3018 - natural_scroll: false,
3019 + natural_scroll: true,
3020
3021 - spawn_at_startup: [],
3022 + spawn_at_startup: [
3023 + SpawnAtStartup {
3024 + command: [
3025 + "waybar",
3026 + ],
3027 + },
3028 + ],
3029
3030 - 0.3333333333333333,
3031 + 0.33333,
3032
3033 - 0.6666666666666666,
3034 + 0.66667,
3035 "#,
3036 );
3037 }
3038}