diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-09-27 11:20:43 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-02 09:38:17 +0300 |
| commit | b3ae3adbb77c4111366cb59b80d757f361c70237 (patch) | |
| tree | af60f8397ae9971b3ab2889c0925c705abe02a25 /src | |
| parent | 264289cd41069bd2c85c523a1b0c687eab0a89d7 (diff) | |
| download | niri-b3ae3adbb77c4111366cb59b80d757f361c70237.tar.gz niri-b3ae3adbb77c4111366cb59b80d757f361c70237.tar.bz2 niri-b3ae3adbb77c4111366cb59b80d757f361c70237.zip | |
Partially implement config includes
Subsequent commits will add merging for all leftover sections.
Diffstat (limited to 'src')
| -rw-r--r-- | src/layer/mapped.rs | 4 | ||||
| -rw-r--r-- | src/layout/mod.rs | 2 | ||||
| -rw-r--r-- | src/layout/tests.rs | 10 | ||||
| -rw-r--r-- | src/main.rs | 13 | ||||
| -rw-r--r-- | src/tests/animations.rs | 4 | ||||
| -rw-r--r-- | src/tests/floating.rs | 2 | ||||
| -rw-r--r-- | src/tests/window_opening.rs | 4 | ||||
| -rw-r--r-- | src/ui/hotkey_overlay.rs | 2 | ||||
| -rw-r--r-- | src/utils/mod.rs | 2 | ||||
| -rw-r--r-- | src/utils/watcher.rs | 2 |
10 files changed, 23 insertions, 22 deletions
diff --git a/src/layer/mapped.rs b/src/layer/mapped.rs index 2e9f6ca8..658a0c15 100644 --- a/src/layer/mapped.rs +++ b/src/layer/mapped.rs @@ -59,7 +59,7 @@ impl MappedLayer { clock: Clock, config: &Config, ) -> Self { - let mut shadow_config = config.resolve_layout().shadow; + let mut shadow_config = config.layout.shadow; // Shadows for layer surfaces need to be explicitly enabled. shadow_config.on = false; shadow_config.merge_with(&rules.shadow); @@ -76,7 +76,7 @@ impl MappedLayer { } pub fn update_config(&mut self, config: &Config) { - let mut shadow_config = config.resolve_layout().shadow; + let mut shadow_config = config.layout.shadow; // Shadows for layer surfaces need to be explicitly enabled. shadow_config.on = false; shadow_config.merge_with(&self.rules.shadow); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index c04a72ba..e60828d9 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -576,7 +576,7 @@ impl HitType { impl Options { fn from_config(config: &Config) -> Self { Self { - layout: config.resolve_layout(), + layout: config.layout.clone(), animations: config.animations.clone(), gestures: config.gestures, overview: config.overview, diff --git a/src/layout/tests.rs b/src/layout/tests.rs index 389408c2..2dc989fd 100644 --- a/src/layout/tests.rs +++ b/src/layout/tests.rs @@ -2357,9 +2357,9 @@ fn removing_all_outputs_preserves_empty_named_workspaces() { #[test] fn config_change_updates_cached_sizes() { let mut config = Config::default(); - let border = config.layout.border.get_or_insert_with(Default::default); + let border = &mut config.layout.border; border.off = false; - border.width = Some(FloatOrInt(2.)); + border.width = 2.; let mut layout = Layout::new(Clock::default(), &config); @@ -2371,7 +2371,7 @@ fn config_change_updates_cached_sizes() { } .apply(&mut layout); - config.layout.border.as_mut().unwrap().width = Some(FloatOrInt(4.)); + config.layout.border.width = 4.; layout.update_config(&config); layout.verify_invariants(); @@ -2380,7 +2380,7 @@ fn config_change_updates_cached_sizes() { #[test] fn preset_height_change_removes_preset() { let mut config = Config::default(); - config.layout.preset_window_heights = Some(vec![PresetSize::Fixed(1), PresetSize::Fixed(2)]); + config.layout.preset_window_heights = vec![PresetSize::Fixed(1), PresetSize::Fixed(2)]; let mut layout = Layout::new(Clock::default(), &config); @@ -2401,7 +2401,7 @@ fn preset_height_change_removes_preset() { } // Leave only one. - config.layout.preset_window_heights = Some(vec![PresetSize::Fixed(1)]); + config.layout.preset_window_heights = vec![PresetSize::Fixed(1)]; layout.update_config(&config); diff --git a/src/main.rs b/src/main.rs index 118fe27a..8e5ce1d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use niri::utils::spawning::{ REMOVE_ENV_RUST_BACKTRACE, REMOVE_ENV_RUST_LIB_BACKTRACE, }; use niri::utils::{cause_panic, version, watcher, xwayland, IS_SYSTEMD_SERVICE}; -use niri_config::ConfigPath; +use niri_config::{Config, ConfigPath}; use niri_ipc::socket::SOCKET_PATH_ENV; use portable_atomic::Ordering; use sd_notify::NotifyState; @@ -101,7 +101,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Sub::Validate { config } => { tracy_client::Client::start(); - config_path(config).load()?; + config_path(config).load().config?; info!("config is valid"); return Ok(()); } @@ -148,10 +148,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let config_path = config_path(cli.config); env::remove_var("NIRI_CONFIG"); let (config_created_at, config_load_result) = config_path.load_or_create(); - let config_errored = config_load_result.is_err(); - let mut config = config_load_result - .map_err(|err| warn!("{err:?}")) - .unwrap_or_default(); + let config_errored = config_load_result.config.is_err(); + let mut config = config_load_result.config.unwrap_or_else(|err| { + warn!("{err:?}"); + Config::load_default() + }); let spawn_at_startup = mem::take(&mut config.spawn_at_startup); let spawn_sh_at_startup = mem::take(&mut config.spawn_sh_at_startup); diff --git a/src/tests/animations.rs b/src/tests/animations.rs index 4871f2c0..51c57f73 100644 --- a/src/tests/animations.rs +++ b/src/tests/animations.rs @@ -3,7 +3,7 @@ use std::time::Duration; use insta::assert_snapshot; use niri_config::animations::{Curve, EasingParams, Kind}; -use niri_config::{Config, FloatOrInt}; +use niri_config::Config; use niri_ipc::SizeChange; use smithay::utils::{Point, Size}; use wayland_client::protocol::wl_surface::WlSurface; @@ -74,7 +74,7 @@ fn set_up() -> Fixture { }); let mut config = Config::default(); - config.layout.gaps = Some(FloatOrInt(0.0)); + config.layout.gaps = 0.0; config.animations.window_resize.anim.kind = LINEAR; config.animations.window_movement.0.kind = LINEAR; diff --git a/src/tests/floating.rs b/src/tests/floating.rs index 4d0b9383..e1cb4330 100644 --- a/src/tests/floating.rs +++ b/src/tests/floating.rs @@ -795,7 +795,7 @@ window-rule { max-width 300 } "##; - let config = Config::parse("test.kdl", config).unwrap(); + let config = Config::parse_mem(config).unwrap(); let mut f = Fixture::with_config(config); f.add_output(1, (1920, 1080)); f.add_output(2, (1280, 720)); diff --git a/src/tests/window_opening.rs b/src/tests/window_opening.rs index e6210fde..9a2ff6da 100644 --- a/src/tests/window_opening.rs +++ b/src/tests/window_opening.rs @@ -281,7 +281,7 @@ window-rule {{ snapshot_desc.push(format!("config:{config}")); - let config = Config::parse("config.kdl", &config).unwrap(); + let config = Config::parse_mem(&config).unwrap(); let mut f = Fixture::with_config(config); f.add_output(1, (1280, 720)); @@ -574,7 +574,7 @@ layout { snapshot_desc.push(format!("config:{config}")); - let config = Config::parse("config.kdl", &config).unwrap(); + let config = Config::parse_mem(&config).unwrap(); let mut f = Fixture::with_config(config); f.add_output(1, (1280, 720)); diff --git a/src/ui/hotkey_overlay.rs b/src/ui/hotkey_overlay.rs index 783b71ef..67997fc8 100644 --- a/src/ui/hotkey_overlay.rs +++ b/src/ui/hotkey_overlay.rs @@ -607,7 +607,7 @@ mod tests { #[track_caller] fn check(config: &str, action: Action) -> String { - let config = Config::parse("test.kdl", config).unwrap(); + let config = Config::parse_mem(config).unwrap(); if let Some((key, title)) = format_bind(&config.binds.0, &action) { let key = key.map(|key| key_name(false, ModKey::Super, &key)); let key = key.as_deref().unwrap_or("(not bound)"); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a96c1bfc..8efa8654 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -213,7 +213,7 @@ pub fn expand_home(path: &Path) -> anyhow::Result<Option<PathBuf>> { } pub fn make_screenshot_path(config: &Config) -> anyhow::Result<Option<PathBuf>> { - let Some(path) = &config.screenshot_path else { + let Some(path) = &config.screenshot_path.0 else { return Ok(None); }; diff --git a/src/utils/watcher.rs b/src/utils/watcher.rs index 034e963a..ecb9007b 100644 --- a/src/utils/watcher.rs +++ b/src/utils/watcher.rs @@ -128,7 +128,7 @@ pub fn setup(state: &mut State, config_path: &ConfigPath) { // Parsing the config actually takes > 20 ms on my beefy machine, so let's do it on the // watcher thread. let process = |path: &ConfigPath| { - path.load().map_err(|err| { + path.load().config.map_err(|err| { warn!("{err:?}"); }) }; |
