From 2429e3d5faa222e3b7060661f777f71d0e3a6108 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:34:16 -0700 Subject: [PATCH 1/7] refactor(windows): take the default constants from komorebi-settings DEFAULT_RESIZE_DELTA, DEFAULT_MOUSE_FOLLOWS_FOCUS and the initial values of DEFAULT_WORKSPACE_PADDING and DEFAULT_CONTAINER_PADDING now come from komorebi_settings::shared (PlatformDefaults::WINDOWS: 10, 10; 50; true); the statics keep their names and types, so no reader changes. Adds the komorebi-settings dependency edge to komorebi-windows (Cargo.lock edge only; the crate is already a workspace member). Plan step 10, S1. Pure refactor. Verified: Windows clippy -D warnings --all-targets on komorebi-windows (dev shell, cross, target-fast-win): clean. e2e not run; tools/e2e-needed will report the crate as an input of komorebi.exe, behaviour is unchanged. --- Cargo.lock | 1 + komorebi/Cargo.toml | 1 + komorebi/src/lib.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf996037..ba65ac8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3815,6 +3815,7 @@ dependencies = [ "komorebi-layouts", "komorebi-protocol", "komorebi-scrolling", + "komorebi-settings", "komorebi-themes", "komorebi-transport", "lazy_static", diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index af0163d1..d2bde6ff 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -12,6 +12,7 @@ komorebi-backend = { path = "../crates/komorebi-backend" } komorebi-collections = { path = "../crates/komorebi-collections" } komorebi-core = { path = "../crates/komorebi-core" } komorebi-config = { path = "../crates/komorebi-config", default-features = false } +komorebi-settings = { path = "../crates/komorebi-settings" } komorebi-layouts = { path = "../komorebi-layouts", features = ["win32"] } komorebi-scrolling = { path = "../komorebi-scrolling" } komorebi-themes = { path = "../komorebi-themes" } diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index ba20ddfe..4c8ea986 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -268,11 +268,13 @@ lazy_static! { Arc::new(Mutex::new(HashMap::new())); } -pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(10); -pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(10); -pub static DEFAULT_RESIZE_DELTA: i32 = 50; +pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = + AtomicI32::new(komorebi_settings::shared::PlatformDefaults::WINDOWS.workspace_padding); +pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = + AtomicI32::new(komorebi_settings::shared::PlatformDefaults::WINDOWS.container_padding); +pub static DEFAULT_RESIZE_DELTA: i32 = komorebi_settings::shared::DEFAULT_RESIZE_DELTA; -pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = true; +pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; pub static INITIAL_CONFIGURATION_LOADED: AtomicBool = AtomicBool::new(false); pub static CUSTOM_FFM: AtomicBool = AtomicBool::new(false); pub static SESSION_ID: AtomicU32 = AtomicU32::new(0); From 1cb147b2f92924b10e7ff3f21e058d29beb8dbb1 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:35:08 -0700 Subject: [PATCH 2/7] feat(windows): install the settings handle New module settings.rs: WindowsSettings (empty platform part) and settings(), a LazyLock> starting from Shared::defaults_for(PlatformDefaults::WINDOWS). Nothing reads it yet, so nothing changes at runtime. A test pins that the starting settings equal the starting values of the statics (paddings, resize delta, mouse follows focus, border enabled/width/offset, six colours; Windows has no border radius static). Plan step 10, S2. Pure refactor. Verified: Windows clippy -D warnings --locked --all-targets on komorebi-windows (cross, compiles the pin test; it cannot run on this host). The pin test was not run. e2e not run. --- komorebi/src/lib.rs | 1 + komorebi/src/settings.rs | 93 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 komorebi/src/settings.rs diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 4c8ea986..14ce1273 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -25,6 +25,7 @@ pub mod scrolling; pub mod set_window_position; pub mod splash; pub mod stackbar_manager; +pub mod settings; pub mod state; pub mod static_config; pub mod styles; diff --git a/komorebi/src/settings.rs b/komorebi/src/settings.rs new file mode 100644 index 00000000..f73fd659 --- /dev/null +++ b/komorebi/src/settings.rs @@ -0,0 +1,93 @@ +//! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`). +//! +//! Nothing reads this yet: the process-wide statics are still the source of truth, and each +//! migration step moves one group of them (writers and readers together) into +//! [`settings()`]. Until then the value is the starting values of those statics. + +use std::sync::LazyLock; + +use komorebi_settings::Handle; +use komorebi_settings::Shared; +use komorebi_settings::shared::PlatformDefaults; + +/// The part of the settings that only Windows has. Empty for now; the stackbar, hiding and handling behaviour and border style join it later. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct WindowsSettings {} + +pub type Settings = komorebi_settings::Settings; + +static SETTINGS: LazyLock> = LazyLock::new(|| { + Handle::new(Settings::new( + Shared::defaults_for(PlatformDefaults::WINDOWS), + WindowsSettings::default(), + )) +}); + +/// The settings of the running daemon: take a [`Handle::snapshot`] once per unit of work. +pub fn settings() -> &'static Handle { + &SETTINGS +} + +#[cfg(test)] +mod tests { + use std::sync::atomic::Ordering; + + use super::*; + use crate::border_manager; + + // The statics are still the source of truth. These pin that the starting values of the + // settings are the starting values of the statics, so that moving a group over changes nothing. + // (They read the statics without any test writing them first: no test here sets them.) + #[test] + fn the_starting_settings_are_the_starting_values_of_the_statics() { + let shared = &settings().snapshot().shared; + + assert_eq!( + shared.defaults.container_padding, + crate::DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst) + ); + assert_eq!( + shared.defaults.workspace_padding, + crate::DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst) + ); + assert_eq!(shared.defaults.resize_delta, crate::DEFAULT_RESIZE_DELTA); + assert_eq!( + shared.defaults.mouse_follows_focus, + crate::DEFAULT_MOUSE_FOLLOWS_FOCUS + ); + assert_eq!( + shared.border.enabled, + border_manager::BORDER_ENABLED.load(Ordering::SeqCst) + ); + assert_eq!( + shared.border.width, + border_manager::BORDER_WIDTH.load(Ordering::SeqCst) + ); + assert_eq!( + shared.border.offset, + border_manager::BORDER_OFFSET.load(Ordering::SeqCst) + ); + let colours = shared.border.colours; + assert_eq!( + colours.single, + border_manager::FOCUSED.load(Ordering::SeqCst) + ); + assert_eq!(colours.stack, border_manager::STACK.load(Ordering::SeqCst)); + assert_eq!( + colours.monocle, + border_manager::MONOCLE.load(Ordering::SeqCst) + ); + assert_eq!( + colours.floating, + border_manager::FLOATING.load(Ordering::SeqCst) + ); + assert_eq!( + colours.unfocused, + border_manager::UNFOCUSED.load(Ordering::SeqCst) + ); + assert_eq!( + colours.unfocused_locked, + border_manager::UNFOCUSED_LOCKED.load(Ordering::SeqCst) + ); + } +} From 6f8bc2b0badccfaa542b1fbf1cbee17bd60f2a4d Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:35:29 -0700 Subject: [PATCH 3/7] refactor(settings): pin a configuration load through the handle Adds crates/komorebi-settings/tests/reload.rs: a load applied through a Handle merges what the file gives, resets layout_defaults and the aspect ratio when absent (the first load without the key turns the initial Widescreen into Standard, as the statics do), keeps paddings and display index preferences, never touches groups it does not name, and a reader that holds the earlier snapshot still sees the earlier load whole. Test only. Verified: native cargo test -p komorebi-settings: 18 unit + 3 integration passed. --- crates/komorebi-settings/tests/reload.rs | 127 +++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 crates/komorebi-settings/tests/reload.rs diff --git a/crates/komorebi-settings/tests/reload.rs b/crates/komorebi-settings/tests/reload.rs new file mode 100644 index 00000000..890f4019 --- /dev/null +++ b/crates/komorebi-settings/tests/reload.rs @@ -0,0 +1,127 @@ +//! A configuration load through a `Handle`, the way the daemons apply `apply_globals` for the groups +//! that have moved (paddings, aspect ratio, layout defaults, display index preferences): a reload +//! merges, a few keys reset. Section 4 of `docs/dev/settings.md`. + +use std::collections::HashMap; + +use komorebi_config::aspect_ratio::AspectRatio; +use komorebi_config::aspect_ratio::PredefinedAspectRatio; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::LayoutDefaultEntry; +use komorebi_settings::Handle; +use komorebi_settings::Settings; +use komorebi_settings::Shared; +use komorebi_settings::shared::PlatformDefaults; +use komorebi_settings::shared::SharedDelta; + +fn handle() -> Handle<()> { + Handle::new(Settings::new( + Shared::defaults_for(PlatformDefaults::WINDOWS), + (), + )) +} + +fn load(handle: &Handle<()>, delta: SharedDelta) { + handle.update(|settings| delta.apply(&mut settings.shared)); +} + +fn entry() -> LayoutDefaultEntry { + LayoutDefaultEntry { + layout_options: None, + layout_options_rules: None, + } +} + +#[test] +fn the_first_load_without_the_keys_changes_widescreen_to_standard() { + let handle = handle(); + assert_eq!( + handle.snapshot().shared.floating_window_aspect_ratio, + AspectRatio::Predefined(PredefinedAspectRatio::Widescreen) + ); + + load(&handle, SharedDelta::default()); + + assert_eq!( + handle.snapshot().shared.floating_window_aspect_ratio, + AspectRatio::Predefined(PredefinedAspectRatio::Standard) + ); +} + +#[test] +fn a_reload_merges_what_the_file_gives_and_resets_what_it_resets() { + let handle = handle(); + + // load 1 gives everything + load( + &handle, + SharedDelta { + default_container_padding: Some(7), + default_workspace_padding: Some(8), + floating_window_aspect_ratio: Some(AspectRatio::Custom(3, 2)), + layout_defaults: Some(HashMap::from([(DefaultLayout::BSP, entry())])), + display_index_preferences: Some(HashMap::from([(0, String::from("a"))])), + ..SharedDelta::default() + }, + ); + let first = handle.snapshot(); + assert_eq!(first.shared.defaults.container_padding, 7); + assert_eq!(first.shared.defaults.workspace_padding, 8); + assert_eq!( + first.shared.floating_window_aspect_ratio, + AspectRatio::Custom(3, 2) + ); + assert_eq!(first.shared.layout_defaults.len(), 1); + + // load 2 gives only a workspace padding + load( + &handle, + SharedDelta { + default_workspace_padding: Some(1), + ..SharedDelta::default() + }, + ); + let second = handle.snapshot(); + // kept: container padding, display index preferences + assert_eq!(second.shared.defaults.container_padding, 7); + assert_eq!( + second.shared.display_index_preferences, + HashMap::from([(0, String::from("a"))]) + ); + // replaced + assert_eq!(second.shared.defaults.workspace_padding, 1); + // reset: layout defaults cleared, aspect ratio Standard + assert!(second.shared.layout_defaults.is_empty()); + assert_eq!( + second.shared.floating_window_aspect_ratio, + AspectRatio::Predefined(PredefinedAspectRatio::Standard) + ); + + // a reader that held the first snapshot still sees the first load, whole + assert_eq!(first.shared.defaults.workspace_padding, 8); + assert_eq!(first.shared.layout_defaults.len(), 1); +} + +#[test] +fn a_load_never_touches_the_groups_it_does_not_name() { + let handle = handle(); + handle.update(|settings| { + settings.shared.border.width = 42; + settings.shared.animation.fps = 144; + settings.shared.transparency.alpha = 9; + }); + let before = handle.snapshot(); + + load( + &handle, + SharedDelta { + default_container_padding: Some(3), + ..SharedDelta::default() + }, + ); + + let after = handle.snapshot(); + assert_eq!(after.shared.border, before.shared.border); + assert_eq!(after.shared.animation, before.shared.animation); + assert_eq!(after.shared.transparency, before.shared.transparency); +} From 04c10a00a53449659f6850d0ec44d5a53a6961c7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:35:29 -0700 Subject: [PATCH 4/7] refactor(kde): move paddings, aspect ratio, layout defaults and display preferences to settings Plan step 10, S3. The two default paddings, the aspect ratio of a window toggled to floating (centre with resize), layout_defaults and display_index_preferences are no longer statics: their writers (apply_globals through SharedDelta::apply, the DisplayIndexPreference command) and all readers use settings() together. The semantics are the statics': a missing padding or display_index_preferences key keeps the value, a missing layout_defaults clears it, a missing aspect ratio is Standard (not the initial Widescreen), and the command inserts one entry. Readers get an owned copy from one snapshot (accessors in settings.rs). BEHAVIOUR only in this: apply_globals used to store these keys one at a time and now publishes the group in one update, so a thread can no longer see a half-applied reload of them. Value semantics are pinned by crates/komorebi-settings tests/reload.rs and shared.rs (reload merges, a few keys reset, a load never touches groups it does not name). KDE: window.rs, desktop.rs, monitor.rs, monitor_reconciliator.rs, state.rs, static_config.rs, process_command.rs, lib.rs and tests/config.rs (the test harness resets the paddings through settings()). Verified: KDE cargo test --locked -p komorebi-linux --lib --tests (lite env, own target dir): 63 test binaries, 631 passed, 0 failed, including tests/config.rs that loads configurations over a fake desktop. KDE VM suites not run (gate: config reload and workspace padding suites). --- komorebi-for-kde/komorebi/src/desktop.rs | 11 +-- komorebi-for-kde/komorebi/src/lib.rs | 30 +----- komorebi-for-kde/komorebi/src/monitor.rs | 30 ++---- .../komorebi/src/monitor_reconciliator.rs | 9 +- .../komorebi/src/process_command.rs | 15 +-- komorebi-for-kde/komorebi/src/settings.rs | 53 +++++++--- komorebi-for-kde/komorebi/src/state.rs | 5 +- .../komorebi/src/static_config.rs | 96 +++++++++---------- komorebi-for-kde/komorebi/src/window.rs | 6 +- komorebi-for-kde/komorebi/tests/config.rs | 8 +- 10 files changed, 123 insertions(+), 140 deletions(-) diff --git a/komorebi-for-kde/komorebi/src/desktop.rs b/komorebi-for-kde/komorebi/src/desktop.rs index b224b6a4..261efe5f 100644 --- a/komorebi-for-kde/komorebi/src/desktop.rs +++ b/komorebi-for-kde/komorebi/src/desktop.rs @@ -36,16 +36,15 @@ #![deny(missing_docs)] -use crate::monitor::MonitorExt; -use crate::workspace::WorkspaceExt; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::backend::backend; use crate::container::Container; use crate::core::Rect; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::window::RuleDebug; use crate::window::Window; use crate::window_manager::WindowManager; +use crate::workspace::WorkspaceExt; use color_eyre::eyre; use komorebi_backend::MonitorId; use komorebi_backend::WindowId; @@ -149,8 +148,8 @@ pub fn load_monitor_information(wm: &mut WindowManager) -> eyre::Result<()> { let m = device.clone(); let mut index_preference = None; - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); - for (index, id) in &*display_index_preferences { + let display_index_preferences = crate::settings::display_index_preferences(); + for (index, id) in &display_index_preferences { if m.serial_number_id.eq(id) { index_preference = Option::from(index); } @@ -183,7 +182,7 @@ pub fn load_monitor_information(wm: &mut WindowManager) -> eyre::Result<()> { // Rebuild monitor index map *monitor_usr_idx_map = HashMap::new(); let mut added_monitor_idxs = Vec::new(); - for (index, id) in &*DISPLAY_INDEX_PREFERENCES.read() { + for (index, id) in &crate::settings::display_index_preferences() { if let Some(m_idx) = monitors .elements() .iter() diff --git a/komorebi-for-kde/komorebi/src/lib.rs b/komorebi-for-kde/komorebi/src/lib.rs index 570a2c7d..20064658 100644 --- a/komorebi-for-kde/komorebi/src/lib.rs +++ b/komorebi-for-kde/komorebi/src/lib.rs @@ -37,8 +37,6 @@ //! [`check`]. use crate::core::ApplicationIdentifier; -use crate::core::DefaultLayout; -use crate::core::LayoutDefaultEntry; use crate::core::SocketMessage; use crate::core::SubscribeOptions; use crate::core::config_generation::IdWithIdentifier; @@ -47,14 +45,11 @@ use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; use crate::monitor_reconciliator::MonitorNotification; use crate::state::State; -use crate::window::AspectRatio; -use crate::window::PredefinedAspectRatio; use crate::window_manager_event::WindowManagerEvent; use color_eyre::eyre; use core::pathext::PathExt; use lazy_static::lazy_static; use parking_lot::Mutex; -use parking_lot::RwLock; use regex::Regex; use serde::Deserialize; use serde::Serialize; @@ -63,7 +58,6 @@ use std::collections::HashSet; use std::os::unix::net::UnixStream; use std::path::PathBuf; use std::sync::Arc; -use std::sync::atomic::AtomicI32; #[macro_use] extern crate komorebi_collections; @@ -154,15 +148,6 @@ lazy_static! { /// same name, without options, keeps the options it had. pub static ref SUBSCRIPTION_SOCKET_OPTIONS: Arc>> = Arc::new(Mutex::new(HashMap::new())); - /// The aspect ratio a window that is floated by `ToggleFloat` is given when the placement of - /// floated windows centers and resizes them - static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc> = Arc::new(Mutex::new( - AspectRatio::Predefined(PredefinedAspectRatio::Widescreen) - )); - /// The index the user gives each monitor, by its serial number id - /// ([`SocketMessage::DisplayIndexPreference`]): the window manager orders its monitors by it - static ref DISPLAY_INDEX_PREFERENCES: Arc>> = - Arc::new(RwLock::new(HashMap::new())); /// The rules that send the windows of an application to a workspace: when they open /// (`initial_only`) or whenever the window manager looks at them static ref WORKSPACE_MATCHING_RULES: Arc>> = @@ -201,26 +186,15 @@ lazy_static! { /// The windows komorebi took out of sight (the back of a stack, on the parking desktop), so /// that what the compositor reports about them is not mistaken for something the user did pub static ref HIDDEN_WINDOWS: Arc>> = Arc::new(Mutex::new(HashSet::new())); - /// The layout options and the layout options rules that `layout_defaults` in `komorebi.json` - /// gives each layout, for a workspace that sets neither of its own - pub static ref LAYOUT_DEFAULTS: Arc>> = - Arc::new(Mutex::new(HashMap::new())); } -/// The padding, in pixels, between the edge of a monitor's work area and the tiles of its -/// workspaces, for a monitor that sets none of its own. The default for this is 5. -pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::KDE.workspace_padding); -/// The padding, in pixels, around each tile, for a monitor that sets none of its own. The default -/// for this is 5. -pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::KDE.container_padding); /// How many pixels `ResizeWindowEdge` and `ResizeWindowAxis` resize by, when `komorebi.json` does /// not say pub static DEFAULT_RESIZE_DELTA: i32 = komorebi_settings::shared::DEFAULT_RESIZE_DELTA; /// Whether the pointer goes to the window that is given the focus, when `komorebi.json` does not /// say -pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; +pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = + komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; /// The event, the message or the change of the monitors a [`Notification`] is about /// diff --git a/komorebi-for-kde/komorebi/src/monitor.rs b/komorebi-for-kde/komorebi/src/monitor.rs index 4466c09e..8cd778c2 100644 --- a/komorebi-for-kde/komorebi/src/monitor.rs +++ b/komorebi-for-kde/komorebi/src/monitor.rs @@ -3,7 +3,7 @@ //! A monitor has the bounds and the work area the backend reports for it //! ([`MonitorInfo`](crate::backend::MonitorInfo)), and shows one of its workspaces, the focused //! one. Before the focused workspace is tiled it is given the monitor's work area, the monitor's -//! padding (or [`DEFAULT_CONTAINER_PADDING`] and [`DEFAULT_WORKSPACE_PADDING`]), the work area +//! padding (or [`crate::settings::container_padding`] and [`crate::settings::workspace_padding`]), the work area //! offset and, while the compositor draws borders, the room they take ([`WorkspaceGlobals`]). //! //! Workspace `i` of a monitor is the compositor's virtual desktop `i` on that monitor. Showing @@ -11,9 +11,6 @@ //! workspace it is in, asks the compositor to show the focused workspace's desktop, which shows its //! windows and hides the others, and gives the focus to the workspace's focused window. -use crate::workspace::WorkspaceExt; -use crate::DEFAULT_CONTAINER_PADDING; -use crate::DEFAULT_WORKSPACE_PADDING; use crate::backend::backend; use crate::border_manager::BORDER_DRAWN; use crate::border_manager::BORDER_OFFSET; @@ -24,8 +21,9 @@ use crate::core::Layout; use crate::core::OperationDirection; use crate::core::Rect; use crate::ring::Ring; -use crate::workspace::Workspace; use crate::workspace::KdePlatform; +use crate::workspace::Workspace; +use crate::workspace::WorkspaceExt; use crate::workspace::WorkspaceGlobals; use crate::workspace::WorkspaceLayer; use color_eyre::eyre; @@ -90,7 +88,7 @@ pub fn new( workspaces.elements_mut().push_back(Workspace::default()); Monitor { - extra: Default::default(), + extra: Default::default(), id, device, serial_number_id, @@ -108,15 +106,9 @@ pub fn new( } } - pub trait MonitorExt { - fn new( - id: u32, - size: Rect, - work_area_size: Rect, - device: &str, - serial_number_id: &str, - ) -> Self; + fn new(id: u32, size: Rect, work_area_size: Rect, device: &str, serial_number_id: &str) + -> Self; /// A stand-in for a monitor the user gave an index to (`DisplayIndexPreference`) that is not /// connected, so that the monitors after it keep their indices while it is not there @@ -169,7 +161,6 @@ pub trait MonitorExt { ) -> eyre::Result<()>; fn update_workspaces_globals(&mut self, offset: Option); - } impl MonitorExt for Monitor { @@ -244,10 +235,10 @@ impl MonitorExt for Monitor { fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::Relaxed))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::Relaxed))); + .or(Some(crate::settings::workspace_padding())); // a border the compositor draws outside the window takes room that the window leaves let (border_width, border_offset) = if BORDER_DRAWN.load(Ordering::SeqCst) { ( @@ -490,10 +481,10 @@ impl MonitorExt for Monitor { fn update_workspaces_globals(&mut self, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::workspace_padding())); let (border_width, border_offset) = (0, 0); let work_area = self.work_area_size; let work_area_offset = self.work_area_offset.or(offset); @@ -515,7 +506,6 @@ impl MonitorExt for Monitor { } } } - } #[cfg(test)] diff --git a/komorebi-for-kde/komorebi/src/monitor_reconciliator.rs b/komorebi-for-kde/komorebi/src/monitor_reconciliator.rs index 7f4cb054..a35e82e7 100644 --- a/komorebi-for-kde/komorebi/src/monitor_reconciliator.rs +++ b/komorebi-for-kde/komorebi/src/monitor_reconciliator.rs @@ -26,8 +26,6 @@ //! Covered by `tests/monitor_resize.rs`, `tests/hotplug.rs`, `tests/follow_output.rs` and //! `tests/wake.rs` against the fake backend, and by the `vm-hotplug` and `vm-lock-sleep` VM suites. -use crate::monitor::MonitorExt; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::Notification; use crate::NotificationEvent; use crate::WORKSPACE_MATCHING_RULES; @@ -35,6 +33,7 @@ use crate::border_manager; use crate::core::config_generation::WorkspaceMatchingRule; use crate::desktop; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::notify_subscribers; use crate::state::State; use crate::window_manager::WindowManager; @@ -93,7 +92,7 @@ fn event_rx() -> Receiver { /// It is kept under `serial_number_id`, except when a display index preference has that id as its /// value: then it is kept under the monitor's own serial number id. pub fn insert_in_monitor_cache(serial_number_id: &str, monitor: Monitor) { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); let mut dip_ids = display_index_preferences.values(); let preferred_id = if dip_ids.any(|id| id == serial_number_id) { monitor.serial_number_id.clone() @@ -257,7 +256,7 @@ pub fn reconcile_display_change(wm: &mut WindowManager) -> color_eyre::Result<() // Let's add their state to the cache for later, make sure to use what // the user set as preference as the id. - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); let mut dip_ids = display_index_preferences.values(); let preferred_id = if dip_ids.any(|id| m.serial_number_id.eq(id)) { @@ -357,7 +356,7 @@ pub fn reconcile_display_change(wm: &mut WindowManager) -> color_eyre::Result<() // load the cached monitor removing any window that has since been // closed or moved to another workspace *m = Monitor { - extra: Default::default(), + extra: Default::default(), // Data that should be the one just read from the compositor id: m.id, device: m.device.clone(), diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index cb9f55d4..9d2595b8 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -219,11 +219,7 @@ //! Once a message has been handled, every subscriber is sent a notification of it //! ([`notify_subscribers`]). -use crate::monitor::MonitorExt; -use crate::scrolling::WorkspaceScrolling; -use crate::workspace::WorkspaceExt; use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; @@ -260,8 +256,10 @@ use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; +use crate::monitor::MonitorExt; use crate::monitor::MonitorInformation; use crate::notify_subscribers; +use crate::scrolling::WorkspaceScrolling; use crate::state::GlobalState; use crate::state::State; use crate::static_config::StaticConfig; @@ -272,6 +270,7 @@ use crate::window::RuleDebug; use crate::window::Window; use crate::window_manager::WindowManager; use crate::window_manager_event_listener; +use crate::workspace::WorkspaceExt; use crate::workspace::WorkspaceLayer; use crate::workspace::WorkspaceWindowLocation; use color_eyre::eyre; @@ -1443,8 +1442,12 @@ impl WindowManager { self.cross_monitor_move_behaviour = behaviour; } SocketMessage::DisplayIndexPreference(index_preference, ref display) => { - let mut display_index_preferences = DISPLAY_INDEX_PREFERENCES.write(); - display_index_preferences.insert(index_preference, display.clone()); + crate::settings::settings().update(|settings| { + settings + .shared + .display_index_preferences + .insert(index_preference, display.clone()); + }); } SocketMessage::ReplaceConfiguration(ref config) => { self.replace_configuration(config)? diff --git a/komorebi-for-kde/komorebi/src/settings.rs b/komorebi-for-kde/komorebi/src/settings.rs index b7056427..11ce4186 100644 --- a/komorebi-for-kde/komorebi/src/settings.rs +++ b/komorebi-for-kde/komorebi/src/settings.rs @@ -1,11 +1,17 @@ //! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`). //! -//! Nothing reads this yet: the process-wide statics are still the source of truth, and each -//! migration step moves one group of them (writers and readers together) into -//! [`settings()`]. Until then the value is the starting values of those statics. +//! Each migration step moves one group of the process-wide statics (writers and readers together) +//! into [`settings()`]. Moved so far: the two default paddings, the aspect ratio of a window toggled +//! to floating, `layout_defaults` and `display_index_preferences`. The groups that have not moved +//! are still statics and the pin test compares them with the starting settings. +use std::collections::HashMap; use std::sync::LazyLock; +use komorebi_config::aspect_ratio::AspectRatio; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::LayoutDefaultEntry; + use komorebi_settings::Handle; use komorebi_settings::Shared; use komorebi_settings::shared::PlatformDefaults; @@ -28,6 +34,39 @@ pub fn settings() -> &'static Handle { &SETTINGS } +// Accessors for the groups that have moved over (S3). Each takes one snapshot, so a caller sees one +// configuration, and returns an owned value: the callers are configuration and monitor-change +// paths, not hot paths. + +/// `default_container_padding`: the padding around each tile for a monitor that sets none. +pub fn container_padding() -> i32 { + settings().snapshot().shared.defaults.container_padding +} + +/// `default_workspace_padding`: the padding inside a work area for a monitor that sets none. +pub fn workspace_padding() -> i32 { + settings().snapshot().shared.defaults.workspace_padding +} + +/// `floating_window_aspect_ratio`: the shape of a window that is toggled to floating and centred. +pub fn floating_window_aspect_ratio() -> AspectRatio { + settings().snapshot().shared.floating_window_aspect_ratio +} + +/// `layout_defaults`: what each layout starts with when a workspace sets nothing. +pub fn layout_defaults() -> HashMap { + settings().snapshot().shared.layout_defaults.clone() +} + +/// `display_index_preferences`: which monitor each configured index belongs to. +pub fn display_index_preferences() -> HashMap { + settings() + .snapshot() + .shared + .display_index_preferences + .clone() +} + #[cfg(test)] mod tests { use std::sync::atomic::Ordering; @@ -42,14 +81,6 @@ mod tests { fn the_starting_settings_are_the_starting_values_of_the_statics() { let shared = &settings().snapshot().shared; - assert_eq!( - shared.defaults.container_padding, - crate::DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst) - ); - assert_eq!( - shared.defaults.workspace_padding, - crate::DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst) - ); assert_eq!(shared.defaults.resize_delta, crate::DEFAULT_RESIZE_DELTA); assert_eq!( shared.defaults.mouse_follows_focus, diff --git a/komorebi-for-kde/komorebi/src/state.rs b/komorebi-for-kde/komorebi/src/state.rs index a1b8f880..2d37869d 100644 --- a/komorebi-for-kde/komorebi/src/state.rs +++ b/komorebi-for-kde/komorebi/src/state.rs @@ -12,7 +12,6 @@ //! [`Notification`]: crate::Notification use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::HOME_DIR; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; @@ -109,7 +108,7 @@ impl Default for GlobalState { transparency_blacklist: TRANSPARENCY_BLACKLIST.lock().clone(), ignore_identifiers: IGNORE_IDENTIFIERS.lock().clone(), manage_identifiers: MANAGE_IDENTIFIERS.lock().clone(), - display_index_preferences: DISPLAY_INDEX_PREFERENCES.read().clone(), + display_index_preferences: crate::settings::display_index_preferences(), workspace_rules: WORKSPACE_MATCHING_RULES.lock().clone(), configuration_dir: HOME_DIR.clone(), data_dir: DATA_DIR.clone(), @@ -175,7 +174,7 @@ impl From<&WindowManager> for State { .monitors() .iter() .map(|monitor| Monitor { - extra: Default::default(), + extra: Default::default(), id: monitor.id, device: monitor.device.clone(), serial_number_id: monitor.serial_number_id.clone(), diff --git a/komorebi-for-kde/komorebi/src/static_config.rs b/komorebi-for-kde/komorebi/src/static_config.rs index fa995c17..42cdbe65 100644 --- a/komorebi-for-kde/komorebi/src/static_config.rs +++ b/komorebi-for-kde/komorebi/src/static_config.rs @@ -21,21 +21,14 @@ //! rules are added to the ones the configuration itself has. //! //! Settings that have no key are left to their defaults ([`DEFAULT_RESIZE_DELTA`], -//! [`DEFAULT_WORKSPACE_PADDING`] and the others in [`crate`]), and an optional key set to `null` +//! [`crate::settings`] holds the others), and an optional key set to `null` //! is the same as one that is left out. -use crate::monitor::MonitorExt; -use crate::workspace::WorkspaceExt; use crate::DATA_DIR; -use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_MOUSE_FOLLOWS_FOCUS; use crate::DEFAULT_RESIZE_DELTA; -use crate::DEFAULT_WORKSPACE_PADDING; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::IGNORE_IDENTIFIERS; -use crate::LAYOUT_DEFAULTS; use crate::MANAGE_IDENTIFIERS; use crate::REGEX_IDENTIFIERS; use crate::TRANSPARENCY_BLACKLIST; @@ -67,19 +60,20 @@ use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; use crate::monitor; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::monitor_reconciliator; use crate::ring::Ring; use crate::theme_manager; use crate::transparency_manager; -use crate::window::AspectRatio; -use crate::window::PredefinedAspectRatio; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crate::workspace::Workspace; +use crate::workspace::WorkspaceExt; use color_eyre::eyre; use crossbeam_channel::Receiver; use hotwatch::EventKind; use hotwatch::Hotwatch; +use komorebi_settings::shared::SharedDelta; use komorebi_themes::colour::Colour; use parking_lot::Mutex; use regex::Regex; @@ -129,8 +123,8 @@ pub fn workspace_config(value: &Workspace) -> WorkspaceConfig { window_container_behaviour_rules.insert(*threshold, *behaviour); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -218,8 +212,8 @@ pub fn monitor_config(value: &Monitor) -> MonitorConfig { workspaces.push(workspace_config(w)); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -366,14 +360,10 @@ impl From<&WindowManager> for StaticConfig { // border_style: Option::from(STYLE.load()), // border_z_order: None, // border_implementation: Option::from(IMPLEMENTATION.load()), - default_workspace_padding: Option::from( - DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst), - ), - default_container_padding: Option::from( - DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst), - ), + default_workspace_padding: Option::from(crate::settings::workspace_padding()), + default_container_padding: Option::from(crate::settings::container_padding()), layout_defaults: { - let guard = LAYOUT_DEFAULTS.lock(); + let guard = crate::settings::layout_defaults(); if guard.is_empty() { None } else { @@ -393,7 +383,7 @@ impl From<&WindowManager> for StaticConfig { // object_name_change_applications: None, // object_name_change_title_ignore_list: None, // monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()), - display_index_preferences: Option::from(DISPLAY_INDEX_PREFERENCES.read().clone()), + display_index_preferences: Option::from(crate::settings::display_index_preferences()), // stackbar: None, animation: None, theme: None, @@ -403,7 +393,9 @@ impl From<&WindowManager> for StaticConfig { // slow_application_identifiers: Option::from(SLOW_APPLICATION_IDENTIFIERS.lock().clone()), // bar_configurations: None, // remove_titlebar_applications: Option::from(NO_TITLEBAR.lock().clone()), - floating_window_aspect_ratio: Option::from(*FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock()), + floating_window_aspect_ratio: Option::from( + crate::settings::floating_window_aspect_ratio(), + ), // window_handling_behaviour: Option::from(WINDOW_HANDLING_BEHAVIOUR.load()), tabbed_applications: None, ..Default::default() @@ -419,9 +411,22 @@ trait ApplyGlobals { impl ApplyGlobals for StaticConfig { #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] fn apply_globals(&mut self) -> eyre::Result<()> { - *FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock() = self - .floating_window_aspect_ratio - .unwrap_or(AspectRatio::Predefined(PredefinedAspectRatio::Standard)); + // The groups that have moved to `Settings` (the two default paddings, the aspect ratio of a + // window toggled to floating, `layout_defaults` and `display_index_preferences`) are applied + // as one update, with the rules the statics had: a missing padding or display index + // preferences key keeps the value, a missing `layout_defaults` clears it and a missing + // aspect ratio is Standard (`SharedDelta::apply`). + crate::settings::settings().update(|settings| { + SharedDelta { + default_container_padding: self.default_container_padding, + default_workspace_padding: self.default_workspace_padding, + floating_window_aspect_ratio: self.floating_window_aspect_ratio, + layout_defaults: self.layout_defaults.clone(), + display_index_preferences: self.display_index_preferences.clone(), + ..SharedDelta::default() + } + .apply(&mut settings.shared); + }); // if let Some(monitor_index_preferences) = &self.monitor_index_preferences { // let mut preferences = MONITOR_INDEX_PREFERENCES.lock(); @@ -429,11 +434,6 @@ impl ApplyGlobals for StaticConfig { // } // - if let Some(display_index_preferences) = &self.display_index_preferences { - let mut preferences = DISPLAY_INDEX_PREFERENCES.write(); - preferences.clone_from(display_index_preferences); - } - // if let Some(behaviour) = self.window_hiding_behaviour { // let mut window_hiding_behaviour = HIDING_BEHAVIOUR.lock(); // *window_hiding_behaviour = behaviour; @@ -487,20 +487,6 @@ impl ApplyGlobals for StaticConfig { ); } - if let Some(container) = self.default_container_padding { - DEFAULT_CONTAINER_PADDING.store(container, Ordering::SeqCst); - } - - if let Some(workspace) = self.default_workspace_padding { - DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst); - } - - if let Some(defaults) = &self.layout_defaults { - *LAYOUT_DEFAULTS.lock() = defaults.clone(); - } else { - LAYOUT_DEFAULTS.lock().clear(); - } - if let Some(border_width) = self.border_width { border_manager::BORDER_WIDTH.store(border_width, Ordering::SeqCst); } @@ -871,8 +857,10 @@ impl StaticConfigExt for StaticConfig { let mut value = Self::read(path)?; let mut wm = wm.lock(); - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -882,7 +870,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { if monitor.serial_number_id.eq(id) { @@ -978,7 +966,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = @@ -1048,8 +1036,10 @@ impl StaticConfigExt for StaticConfig { value.apply_globals()?; - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -1059,7 +1049,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { if monitor.serial_number_id.eq(id) { @@ -1157,7 +1147,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = diff --git a/komorebi-for-kde/komorebi/src/window.rs b/komorebi-for-kde/komorebi/src/window.rs index c38aa2d8..6d400e4d 100644 --- a/komorebi-for-kde/komorebi/src/window.rs +++ b/komorebi-for-kde/komorebi/src/window.rs @@ -18,7 +18,6 @@ //! ([`live_resize_begins`]): [`Window::set_position`] does not move those until the user lets go. use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::HIDDEN_WINDOWS; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; @@ -351,9 +350,8 @@ impl Window { /// The backend does not know the window, or refuses to move it. pub fn center(&mut self, work_area: &Rect, resize: bool) -> eyre::Result<()> { let (target_width, target_height) = if resize { - let (aspect_ratio_width, aspect_ratio_height) = FLOATING_WINDOW_TOGGLE_ASPECT_RATIO - .lock() - .width_and_height(); + let (aspect_ratio_width, aspect_ratio_height) = + crate::settings::floating_window_aspect_ratio().width_and_height(); let target_height = work_area.bottom / 2; let target_width = (target_height * aspect_ratio_width) / aspect_ratio_height; (target_width, target_height) diff --git a/komorebi-for-kde/komorebi/tests/config.rs b/komorebi-for-kde/komorebi/tests/config.rs index a031f876..d8bde11d 100644 --- a/komorebi-for-kde/komorebi/tests/config.rs +++ b/komorebi-for-kde/komorebi/tests/config.rs @@ -13,8 +13,6 @@ //! of a test are still there in the next one. use color_eyre::eyre; -use komorebi::DEFAULT_CONTAINER_PADDING; -use komorebi::DEFAULT_WORKSPACE_PADDING; use komorebi::backend::fake::FakeBackend; use komorebi::backend::with_backend; use komorebi::core::CrossBoundaryBehaviour; @@ -81,8 +79,10 @@ fn added(id: u32) -> WindowManagerEvent { /// Loads `json` over a fake desktop with one monitor, as `main` does fn load(json: &str) -> Loaded { let turn = TURN.lock().unwrap_or_else(|poisoned| poisoned.into_inner()); - DEFAULT_WORKSPACE_PADDING.store(5, Ordering::SeqCst); - DEFAULT_CONTAINER_PADDING.store(5, Ordering::SeqCst); + komorebi::settings::settings().update(|settings| { + settings.shared.defaults.workspace_padding = 5; + settings.shared.defaults.container_padding = 5; + }); let fake = Arc::new(FakeBackend::with_one_monitor()); let path = write_config(json); From faf7bbd79efc413114c9e6c62289c7cb725ec373 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:35:29 -0700 Subject: [PATCH 5/7] refactor(macos): move paddings, aspect ratio, layout defaults and display preferences to settings Plan step 10, S3. The two default paddings, the aspect ratio of a window toggled to floating (centre with resize), layout_defaults and display_index_preferences are no longer statics: their writers (apply_globals through SharedDelta::apply, the DisplayIndexPreference command) and all readers use settings() together. The semantics are the statics': a missing padding or display_index_preferences key keeps the value, a missing layout_defaults clears it, a missing aspect ratio is Standard (not the initial Widescreen), and the command inserts one entry. Readers get an owned copy from one snapshot (accessors in settings.rs). BEHAVIOUR only in this: apply_globals used to store these keys one at a time and now publishes the group in one update, so a thread can no longer see a half-applied reload of them. Value semantics are pinned by crates/komorebi-settings tests/reload.rs and shared.rs (reload merges, a few keys reset, a load never touches groups it does not name). macOS: window.rs, monitor.rs, monitor_reconciliator.rs, macos_api.rs, state.rs, static_config.rs, process_command.rs, lib.rs. rustfmt also reflowed a few unrelated lines in window.rs and process_command.rs. Verified: macOS fake-CC cargo check --locked --target aarch64-apple-darwin -p komorebi-macos --all-targets: 0 errors, 0 warnings from these files. Nothing run on a Mac. --- komorebi-for-mac/komorebi/src/lib.rs | 20 +--- komorebi-for-mac/komorebi/src/macos_api.rs | 7 +- komorebi-for-mac/komorebi/src/monitor.rs | 17 ++-- .../komorebi/src/monitor_reconciliator.rs | 6 +- .../komorebi/src/process_command.rs | 24 ++--- komorebi-for-mac/komorebi/src/settings.rs | 53 ++++++++--- komorebi-for-mac/komorebi/src/state.rs | 3 +- .../komorebi/src/static_config.rs | 93 +++++++++---------- komorebi-for-mac/komorebi/src/window.rs | 15 +-- 9 files changed, 116 insertions(+), 122 deletions(-) diff --git a/komorebi-for-mac/komorebi/src/lib.rs b/komorebi-for-mac/komorebi/src/lib.rs index 8ebc30db..d69b65ea 100644 --- a/komorebi-for-mac/komorebi/src/lib.rs +++ b/komorebi-for-mac/komorebi/src/lib.rs @@ -2,8 +2,6 @@ use crate::accessibility::error::AccessibilityError; use crate::core::ApplicationIdentifier; -use crate::core::DefaultLayout; -use crate::core::LayoutDefaultEntry; use crate::core::SocketMessage; use crate::core::SubscribeOptions; use crate::core::WindowHidingPosition; @@ -14,8 +12,6 @@ use crate::core::config_generation::WorkspaceMatchingRule; use crate::core_graphics::error::CoreGraphicsError; use crate::monitor_reconciliator::MonitorNotification; use crate::state::State; -use crate::window::AspectRatio; -use crate::window::PredefinedAspectRatio; use crate::window_manager_event::WindowManagerEvent; use color_eyre::eyre; use core::pathext::PathExt; @@ -31,7 +27,6 @@ use objc2_core_foundation::CGPoint; use objc2_core_foundation::CGRect; use objc2_core_foundation::CGSize; use parking_lot::Mutex; -use parking_lot::RwLock; use regex::Regex; use serde::Deserialize; use serde::Serialize; @@ -42,7 +37,6 @@ use std::panic; use std::path::PathBuf; use std::ptr::NonNull; use std::sync::Arc; -use std::sync::atomic::AtomicI32; #[macro_use] extern crate komorebi_collections; @@ -115,11 +109,6 @@ lazy_static! { Arc::new(Mutex::new(HashMap::new())); pub static ref SUBSCRIPTION_SOCKET_OPTIONS: Arc>> = Arc::new(Mutex::new(HashMap::new())); - static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc> = Arc::new(Mutex::new( - AspectRatio::Predefined(PredefinedAspectRatio::Widescreen) - )); - static ref DISPLAY_INDEX_PREFERENCES: Arc>> = - Arc::new(RwLock::new(HashMap::new())); static ref WINDOW_RESTORE_POSITIONS: Arc>> = Arc::new(Mutex::new(HashMap::new())); static ref WORKSPACE_MATCHING_RULES: Arc>> = @@ -161,16 +150,11 @@ lazy_static! { ])); static ref TITLELESS_APPLICATIONS: Arc>> = Arc::new(Mutex::new(Vec::new())); static ref UNMANAGED_WINDOW_IDS: Arc>> = Arc::new(Mutex::new(vec![])); - pub static ref LAYOUT_DEFAULTS: Arc>> = - Arc::new(Mutex::new(HashMap::new())); } -pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::MACOS.workspace_padding); -pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::MACOS.container_padding); pub static DEFAULT_RESIZE_DELTA: i32 = komorebi_settings::shared::DEFAULT_RESIZE_DELTA; -pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; +pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = + komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; pub const PUBLIC_KEY: [u8; 32] = [ 0x5a, 0x69, 0x4a, 0xe1, 0x3c, 0x4b, 0xc8, 0x4e, 0xc3, 0x79, 0x0f, 0xab, 0x27, 0x6b, 0x7e, 0xdd, diff --git a/komorebi-for-mac/komorebi/src/macos_api.rs b/komorebi-for-mac/komorebi/src/macos_api.rs index 400bff6b..98a405ef 100644 --- a/komorebi-for-mac/komorebi/src/macos_api.rs +++ b/komorebi-for-mac/komorebi/src/macos_api.rs @@ -1,4 +1,3 @@ -use crate::DISPLAY_INDEX_PREFERENCES; use crate::LibraryError; use crate::accessibility::AccessibilityApi; use crate::accessibility::attribute_constants::kAXFocusedApplicationAttribute; @@ -109,8 +108,8 @@ impl MacosApi { let m = device.clone(); let mut index_preference = None; - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); - for (index, id) in &*display_index_preferences { + let display_index_preferences = crate::settings::display_index_preferences(); + for (index, id) in &display_index_preferences { if m.serial_number_id.eq(id) { index_preference = Option::from(index); } @@ -143,7 +142,7 @@ impl MacosApi { // Rebuild monitor index map *monitor_usr_idx_map = HashMap::new(); let mut added_monitor_idxs = Vec::new(); - for (index, id) in &*DISPLAY_INDEX_PREFERENCES.read() { + for (index, id) in &crate::settings::display_index_preferences() { if let Some(m_idx) = monitors .elements() .iter() diff --git a/komorebi-for-mac/komorebi/src/monitor.rs b/komorebi-for-mac/komorebi/src/monitor.rs index 967abe51..0cf504fb 100644 --- a/komorebi-for-mac/komorebi/src/monitor.rs +++ b/komorebi-for-mac/komorebi/src/monitor.rs @@ -1,5 +1,3 @@ -use crate::DEFAULT_CONTAINER_PADDING; -use crate::DEFAULT_WORKSPACE_PADDING; use crate::container::Container; use crate::core::DefaultLayout; use crate::core::FloatingLayerBehaviour; @@ -19,7 +17,6 @@ use color_eyre::eyre::OptionExt; use serde::Deserialize; use serde::Serialize; use std::collections::VecDeque; -use std::sync::atomic::Ordering; #[derive(Debug, Serialize, Deserialize)] pub struct MonitorInfo { @@ -188,10 +185,10 @@ impl Monitor { pub fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::Relaxed))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::Relaxed))); + .or(Some(crate::settings::workspace_padding())); let (border_width, border_offset) = (0, 0); let work_area = self.work_area_size; let work_area_offset = self.work_area_offset.or(offset); @@ -467,7 +464,8 @@ impl Monitor { workspace.add_container_to_front(container); } DefaultLayout::UltrawideVerticalStack => { - #[allow(clippy::collapsible_match)] // the outer match has one arm per layout; collapsing would restructure it + #[allow(clippy::collapsible_match)] + // the outer match has one arm per layout; collapsing would restructure it if workspace.containers().len() == 1 { workspace.insert_container_at_idx(0, container); } else { @@ -490,7 +488,8 @@ impl Monitor { match layout { DefaultLayout::RightMainVerticalStack | DefaultLayout::UltrawideVerticalStack => { - #[allow(clippy::collapsible_match)] // the outer match has one arm per layout; collapsing would restructure it + #[allow(clippy::collapsible_match)] + // the outer match has one arm per layout; collapsing would restructure it if workspace.containers().len() == 1 { workspace.add_container_to_back(container); } else { @@ -517,10 +516,10 @@ impl Monitor { pub fn update_workspaces_globals(&mut self, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::workspace_padding())); let (border_width, border_offset) = (0, 0); let work_area = self.work_area_size; let work_area_offset = self.work_area_offset.or(offset); diff --git a/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs b/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs index 2d943c5e..c85e203f 100644 --- a/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs +++ b/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs @@ -1,4 +1,3 @@ -use crate::DISPLAY_INDEX_PREFERENCES; use crate::Notification; use crate::NotificationEvent; use crate::WORKSPACE_MATCHING_RULES; @@ -46,7 +45,7 @@ fn event_rx() -> Receiver { } pub fn insert_in_monitor_cache(serial_number_id: &str, monitor: Monitor) { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); let mut dip_ids = display_index_preferences.values(); let preferred_id = if dip_ids.any(|id| id == serial_number_id) { monitor.serial_number_id.clone() @@ -317,7 +316,8 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result // Let's add their state to the cache for later, make sure to use what // the user set as preference as the id. - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = + crate::settings::display_index_preferences(); let mut dip_ids = display_index_preferences.values(); let preferred_id = if dip_ids.any(|id| m.serial_number_id.eq(id)) { diff --git a/komorebi-for-mac/komorebi/src/process_command.rs b/komorebi-for-mac/komorebi/src/process_command.rs index f32d3680..0ccaee44 100644 --- a/komorebi-for-mac/komorebi/src/process_command.rs +++ b/komorebi-for-mac/komorebi/src/process_command.rs @@ -1,5 +1,4 @@ use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; @@ -635,8 +634,7 @@ impl WindowManager { // Sort by window area window_idx_pairs.sort_by_key(|(_, w)| { - let rect = - Rect::from(w.window_rect().unwrap_or_default()); + let rect = Rect::from(w.window_rect().unwrap_or_default()); rect.right * rect.bottom }); window_idx_pairs.reverse(); @@ -705,9 +703,7 @@ impl WindowManager { // Sort by window area window_idx_pairs.sort_by_key(|w| { - let rect = Rect::from( - w.window_rect().unwrap_or_default(), - ); + let rect = Rect::from(w.window_rect().unwrap_or_default()); rect.right * rect.bottom }); @@ -1733,8 +1729,12 @@ impl WindowManager { } } SocketMessage::DisplayIndexPreference(index_preference, ref display) => { - let mut display_index_preferences = DISPLAY_INDEX_PREFERENCES.write(); - display_index_preferences.insert(index_preference, display.clone()); + crate::settings::settings().update(|settings| { + settings + .shared + .display_index_preferences + .insert(index_preference, display.clone()); + }); } SocketMessage::ReplaceConfiguration(ref config) => { // Check that this is a valid static config file first @@ -1880,8 +1880,7 @@ impl WindowManager { | SocketMessage::WatchConfiguration(..) | SocketMessage::WindowHidingBehaviour(..) | SocketMessage::WorkspaceLayoutCustom(..) - | SocketMessage::WorkspaceLayoutCustomRule(..) - => { + | SocketMessage::WorkspaceLayoutCustomRule(..) => { reply.write_all(message.not_supported_reply().as_bytes())?; return Ok(()); } @@ -1909,10 +1908,7 @@ impl WindowManager { } } -pub fn read_commands_uds( - wm: &Arc>, - stream: UnixStream, -) -> eyre::Result<()> { +pub fn read_commands_uds(wm: &Arc>, stream: UnixStream) -> eyre::Result<()> { komorebi_transport::read_commands::(wm, stream, &NoPolicy) } diff --git a/komorebi-for-mac/komorebi/src/settings.rs b/komorebi-for-mac/komorebi/src/settings.rs index 8d7db4df..1c1f9213 100644 --- a/komorebi-for-mac/komorebi/src/settings.rs +++ b/komorebi-for-mac/komorebi/src/settings.rs @@ -1,11 +1,17 @@ //! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`). //! -//! Nothing reads this yet: the process-wide statics are still the source of truth, and each -//! migration step moves one group of them (writers and readers together) into -//! [`settings()`]. Until then the value is the starting values of those statics. +//! Each migration step moves one group of the process-wide statics (writers and readers together) +//! into [`settings()`]. Moved so far: the two default paddings, the aspect ratio of a window toggled +//! to floating, `layout_defaults` and `display_index_preferences`. The groups that have not moved +//! are still statics and the pin test compares them with the starting settings. +use std::collections::HashMap; use std::sync::LazyLock; +use komorebi_config::aspect_ratio::AspectRatio; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::LayoutDefaultEntry; + use komorebi_settings::Handle; use komorebi_settings::Shared; use komorebi_settings::shared::PlatformDefaults; @@ -28,6 +34,39 @@ pub fn settings() -> &'static Handle { &SETTINGS } +// Accessors for the groups that have moved over (S3). Each takes one snapshot, so a caller sees one +// configuration, and returns an owned value: the callers are configuration and monitor-change +// paths, not hot paths. + +/// `default_container_padding`: the padding around each tile for a monitor that sets none. +pub fn container_padding() -> i32 { + settings().snapshot().shared.defaults.container_padding +} + +/// `default_workspace_padding`: the padding inside a work area for a monitor that sets none. +pub fn workspace_padding() -> i32 { + settings().snapshot().shared.defaults.workspace_padding +} + +/// `floating_window_aspect_ratio`: the shape of a window that is toggled to floating and centred. +pub fn floating_window_aspect_ratio() -> AspectRatio { + settings().snapshot().shared.floating_window_aspect_ratio +} + +/// `layout_defaults`: what each layout starts with when a workspace sets nothing. +pub fn layout_defaults() -> HashMap { + settings().snapshot().shared.layout_defaults.clone() +} + +/// `display_index_preferences`: which monitor each configured index belongs to. +pub fn display_index_preferences() -> HashMap { + settings() + .snapshot() + .shared + .display_index_preferences + .clone() +} + #[cfg(test)] mod tests { use std::sync::atomic::Ordering; @@ -42,14 +81,6 @@ mod tests { fn the_starting_settings_are_the_starting_values_of_the_statics() { let shared = &settings().snapshot().shared; - assert_eq!( - shared.defaults.container_padding, - crate::DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst) - ); - assert_eq!( - shared.defaults.workspace_padding, - crate::DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst) - ); assert_eq!(shared.defaults.resize_delta, crate::DEFAULT_RESIZE_DELTA); assert_eq!( shared.defaults.mouse_follows_focus, diff --git a/komorebi-for-mac/komorebi/src/state.rs b/komorebi-for-mac/komorebi/src/state.rs index 87947623..91fe4ad1 100644 --- a/komorebi-for-mac/komorebi/src/state.rs +++ b/komorebi-for-mac/komorebi/src/state.rs @@ -1,5 +1,4 @@ use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::HOME_DIR; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; @@ -61,7 +60,7 @@ impl Default for GlobalState { Self { ignore_identifiers: IGNORE_IDENTIFIERS.lock().clone(), manage_identifiers: MANAGE_IDENTIFIERS.lock().clone(), - display_index_preferences: DISPLAY_INDEX_PREFERENCES.read().clone(), + display_index_preferences: crate::settings::display_index_preferences(), workspace_rules: WORKSPACE_MATCHING_RULES.lock().clone(), configuration_dir: HOME_DIR.clone(), data_dir: DATA_DIR.clone(), diff --git a/komorebi-for-mac/komorebi/src/static_config.rs b/komorebi-for-mac/komorebi/src/static_config.rs index 6fbb0341..89a01448 100644 --- a/komorebi-for-mac/komorebi/src/static_config.rs +++ b/komorebi-for-mac/komorebi/src/static_config.rs @@ -1,14 +1,9 @@ use crate::CoreFoundationRunLoop; use crate::DATA_DIR; -use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_MOUSE_FOLLOWS_FOCUS; use crate::DEFAULT_RESIZE_DELTA; -use crate::DEFAULT_WORKSPACE_PADDING; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::IGNORE_IDENTIFIERS; -use crate::LAYOUT_DEFAULTS; use crate::MANAGE_IDENTIFIERS; use crate::REGEX_IDENTIFIERS; use crate::TABBED_APPLICATIONS; @@ -45,8 +40,6 @@ use crate::monitor::Monitor; use crate::monitor_reconciliator; use crate::ring::Ring; use crate::theme_manager; -use crate::window::AspectRatio; -use crate::window::PredefinedAspectRatio; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crate::workspace::Workspace; @@ -54,6 +47,7 @@ use color_eyre::eyre; use crossbeam_channel::Receiver; use hotwatch::EventKind; use hotwatch::Hotwatch; +use komorebi_settings::shared::SharedDelta; use komorebi_themes::colour::Colour; use objc2_core_foundation::CFRetained; use objc2_core_foundation::CFRunLoop; @@ -103,8 +97,8 @@ impl From<&Workspace> for WorkspaceConfig { window_container_behaviour_rules.insert(*threshold, *behaviour); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -190,8 +184,8 @@ impl From<&Monitor> for MonitorConfig { workspaces.push(WorkspaceConfig::from(w)); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -338,14 +332,10 @@ impl From<&WindowManager> for StaticConfig { // border_style: Option::from(STYLE.load()), // border_z_order: None, // border_implementation: Option::from(IMPLEMENTATION.load()), - default_workspace_padding: Option::from( - DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst), - ), - default_container_padding: Option::from( - DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst), - ), + default_workspace_padding: Option::from(crate::settings::workspace_padding()), + default_container_padding: Option::from(crate::settings::container_padding()), layout_defaults: { - let guard = LAYOUT_DEFAULTS.lock(); + let guard = crate::settings::layout_defaults(); if guard.is_empty() { None } else { @@ -365,7 +355,7 @@ impl From<&WindowManager> for StaticConfig { // object_name_change_applications: None, // object_name_change_title_ignore_list: None, // monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()), - display_index_preferences: Option::from(DISPLAY_INDEX_PREFERENCES.read().clone()), + display_index_preferences: Option::from(crate::settings::display_index_preferences()), // stackbar: None, animation: None, theme: None, @@ -375,7 +365,9 @@ impl From<&WindowManager> for StaticConfig { // slow_application_identifiers: Option::from(SLOW_APPLICATION_IDENTIFIERS.lock().clone()), // bar_configurations: None, // remove_titlebar_applications: Option::from(NO_TITLEBAR.lock().clone()), - floating_window_aspect_ratio: Option::from(*FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock()), + floating_window_aspect_ratio: Option::from( + crate::settings::floating_window_aspect_ratio(), + ), // window_handling_behaviour: Option::from(WINDOW_HANDLING_BEHAVIOUR.load()), tabbed_applications: None, ..Default::default() @@ -391,9 +383,22 @@ trait ApplyGlobals { impl ApplyGlobals for StaticConfig { #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] fn apply_globals(&mut self) -> eyre::Result<()> { - *FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock() = self - .floating_window_aspect_ratio - .unwrap_or(AspectRatio::Predefined(PredefinedAspectRatio::Standard)); + // The groups that have moved to `Settings` (the two default paddings, the aspect ratio of a + // window toggled to floating, `layout_defaults` and `display_index_preferences`) are applied + // as one update, with the rules the statics had: a missing padding or display index + // preferences key keeps the value, a missing `layout_defaults` clears it and a missing + // aspect ratio is Standard (`SharedDelta::apply`). + crate::settings::settings().update(|settings| { + SharedDelta { + default_container_padding: self.default_container_padding, + default_workspace_padding: self.default_workspace_padding, + floating_window_aspect_ratio: self.floating_window_aspect_ratio, + layout_defaults: self.layout_defaults.clone(), + display_index_preferences: self.display_index_preferences.clone(), + ..SharedDelta::default() + } + .apply(&mut settings.shared); + }); // if let Some(monitor_index_preferences) = &self.monitor_index_preferences { // let mut preferences = MONITOR_INDEX_PREFERENCES.lock(); @@ -401,11 +406,6 @@ impl ApplyGlobals for StaticConfig { // } // - if let Some(display_index_preferences) = &self.display_index_preferences { - let mut preferences = DISPLAY_INDEX_PREFERENCES.write(); - preferences.clone_from(display_index_preferences); - } - // if let Some(behaviour) = self.window_hiding_behaviour { // let mut window_hiding_behaviour = HIDING_BEHAVIOUR.lock(); // *window_hiding_behaviour = behaviour; @@ -459,20 +459,6 @@ impl ApplyGlobals for StaticConfig { ); } - if let Some(container) = self.default_container_padding { - DEFAULT_CONTAINER_PADDING.store(container, Ordering::SeqCst); - } - - if let Some(workspace) = self.default_workspace_padding { - DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst); - } - - if let Some(defaults) = &self.layout_defaults { - *LAYOUT_DEFAULTS.lock() = defaults.clone(); - } else { - LAYOUT_DEFAULTS.lock().clear(); - } - if let Some(border_width) = self.border_width { border_manager::BORDER_WIDTH.store(border_width, Ordering::SeqCst); } @@ -835,8 +821,10 @@ impl StaticConfigExt for StaticConfig { let mut value = Self::read(path)?; let mut wm = wm.lock(); - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -846,7 +834,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { if monitor.serial_number_id.eq(id) { @@ -944,7 +932,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = @@ -998,8 +986,10 @@ impl StaticConfigExt for StaticConfig { value.apply_globals()?; - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -1009,7 +999,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { if monitor.serial_number_id.eq(id) { @@ -1109,7 +1099,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = @@ -1256,7 +1246,8 @@ fn handle_asc_file( match path.extension() { None => {} Some(ext) => { - #[allow(clippy::collapsible_match)] // collapsing the nested if into a guard would restructure a 40-line block + #[allow(clippy::collapsible_match)] + // collapsing the nested if into a guard would restructure a 40-line block if ext.to_string_lossy().to_string().as_str() == "json" { tracing::info!("loading applications.json from: {}", path.display()); let mut asc = ApplicationSpecificConfiguration::load(path)?; diff --git a/komorebi-for-mac/komorebi/src/window.rs b/komorebi-for-mac/komorebi/src/window.rs index 595e6702..af68a334 100644 --- a/komorebi-for-mac/komorebi/src/window.rs +++ b/komorebi-for-mac/komorebi/src/window.rs @@ -1,7 +1,6 @@ use crate::AccessibilityObserver; use crate::AccessibilityUiElement; use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::IGNORE_IDENTIFIERS; use crate::LibraryError; use crate::MANAGE_IDENTIFIERS; @@ -42,8 +41,6 @@ use crate::arrival; use crate::cf_dictionary_value; use crate::core::ApplicationIdentifier; use crate::core::Rect; -pub use komorebi_config::aspect_ratio::AspectRatio; -pub use komorebi_config::aspect_ratio::PredefinedAspectRatio; use crate::core::WindowHidingPosition; use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; @@ -60,6 +57,8 @@ use crate::window_manager_event::SystemNotification; use crate::window_manager_event::WindowManagerEvent; use crate::window_manager_event_listener; use color_eyre::eyre; +pub use komorebi_config::aspect_ratio::AspectRatio; +pub use komorebi_config::aspect_ratio::PredefinedAspectRatio; use objc2::__framework_prelude::Retained; use objc2_app_kit::NSApplicationActivationOptions; use objc2_app_kit::NSRunningApplication; @@ -521,10 +520,7 @@ impl Serialize for Window { { let mut state = serializer.serialize_struct("Window", 6)?; state.serialize_field("id", &self.id)?; - state.serialize_field( - "rect", - &Rect::from(self.window_rect().unwrap_or_default()), - )?; + state.serialize_field("rect", &Rect::from(self.window_rect().unwrap_or_default()))?; state.serialize_field("details", &WindowDetails::from(self))?; state.end() } @@ -1235,9 +1231,8 @@ impl Window { pub fn center(&mut self, work_area: &Rect, resize: bool) -> Result<(), AccessibilityError> { let (target_width, target_height) = if resize { - let (aspect_ratio_width, aspect_ratio_height) = FLOATING_WINDOW_TOGGLE_ASPECT_RATIO - .lock() - .width_and_height(); + let (aspect_ratio_width, aspect_ratio_height) = + crate::settings::floating_window_aspect_ratio().width_and_height(); let target_height = work_area.bottom / 2; let target_width = (target_height * aspect_ratio_width) / aspect_ratio_height; (target_width, target_height) From cab39bedfb448e83bb7654e6129ec72bbbab5515 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:35:29 -0700 Subject: [PATCH 6/7] refactor(windows): move paddings, aspect ratio, layout defaults and display preferences to settings Plan step 10, S3. The two default paddings, the aspect ratio of a window toggled to floating (centre with resize), layout_defaults and display_index_preferences are no longer statics: their writers (apply_globals through SharedDelta::apply, the DisplayIndexPreference command) and all readers use settings() together. The semantics are the statics': a missing padding or display_index_preferences key keeps the value, a missing layout_defaults clears it, a missing aspect ratio is Standard (not the initial Widescreen), and the command inserts one entry. Readers get an owned copy from one snapshot (accessors in settings.rs). BEHAVIOUR only in this: apply_globals used to store these keys one at a time and now publishes the group in one update, so a thread can no longer see a half-applied reload of them. Value semantics are pinned by crates/komorebi-settings tests/reload.rs and shared.rs (reload merges, a few keys reset, a load never touches groups it does not name). Windows: window.rs, windows_api.rs, workspace.rs, monitor.rs, monitor_reconciliator, stackbar_manager (the gap reads the container padding from settings), state.rs, static_config.rs, process_command.rs, lib.rs. MONITOR_INDEX_PREFERENCES stays a static (Windows only). Verified: Windows clippy -D warnings --locked --all-targets on komorebi-windows (cross): clean. e2e not run: config_reload, layouts, workspaces, stackbars (container padding gap) are needed. --- komorebi/src/lib.rs | 19 ++--- komorebi/src/monitor.rs | 10 +-- komorebi/src/monitor_reconciliator/mod.rs | 5 +- komorebi/src/process_command.rs | 9 ++- komorebi/src/settings.rs | 53 ++++++++++--- komorebi/src/stackbar_manager/mod.rs | 4 +- komorebi/src/stackbar_manager/stackbar.rs | 7 +- komorebi/src/state.rs | 3 +- komorebi/src/static_config.rs | 90 ++++++++++------------- komorebi/src/window.rs | 6 +- komorebi/src/windows_api.rs | 7 +- komorebi/src/workspace.rs | 6 +- 12 files changed, 111 insertions(+), 108 deletions(-) diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 14ce1273..24dc4f33 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -12,8 +12,8 @@ pub mod container; pub mod core; pub mod focus_manager; pub mod live_resize; -pub use komorebi_collections::lockable_sequence; pub use komorebi_collections::Lockable; +pub use komorebi_collections::lockable_sequence; pub mod monitor; pub mod monitor_reconciliator; pub mod pan; @@ -23,19 +23,19 @@ pub mod process_movement; pub mod reaper; pub mod scrolling; pub mod set_window_position; +pub mod settings; pub mod splash; pub mod stackbar_manager; -pub mod settings; pub mod state; pub mod static_config; pub mod styles; pub mod theme_manager; pub mod transparency_manager; pub mod window; -pub mod windows_backend; pub mod window_manager; pub mod window_manager_event; pub mod windows_api; +pub mod windows_backend; pub mod windows_callbacks; pub mod winevent; pub mod winevent_listener; @@ -52,7 +52,6 @@ use std::path::PathBuf; use std::process::Command; use std::sync::Arc; use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicI32; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; @@ -162,8 +161,6 @@ lazy_static! { static ref TRANSPARENCY_BLACKLIST: Arc>> = Arc::new(Mutex::new(Vec::new())); static ref MONITOR_INDEX_PREFERENCES: Arc>> = Arc::new(Mutex::new(HashMap::new())); - static ref DISPLAY_INDEX_PREFERENCES: Arc>> = - Arc::new(RwLock::new(HashMap::new())); static ref WORKSPACE_MATCHING_RULES: Arc>> = Arc::new(Mutex::new(Vec::new())); static ref REGEX_IDENTIFIERS: Arc>> = @@ -261,21 +258,15 @@ lazy_static! { static ref WINDOWS_BY_BAR_HWNDS: Arc>>> = Arc::new(Mutex::new(HashMap::new())); - static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc> = Arc::new(Mutex::new(AspectRatio::Predefined(PredefinedAspectRatio::Widescreen))); static ref CURRENT_VIRTUAL_DESKTOP: Arc>>> = Arc::new(Mutex::new(None)); - pub static ref LAYOUT_DEFAULTS: Arc>> = - Arc::new(Mutex::new(HashMap::new())); } -pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::WINDOWS.workspace_padding); -pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = - AtomicI32::new(komorebi_settings::shared::PlatformDefaults::WINDOWS.container_padding); pub static DEFAULT_RESIZE_DELTA: i32 = komorebi_settings::shared::DEFAULT_RESIZE_DELTA; -pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; +pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = + komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS; pub static INITIAL_CONFIGURATION_LOADED: AtomicBool = AtomicBool::new(false); pub static CUSTOM_FFM: AtomicBool = AtomicBool::new(false); pub static SESSION_ID: AtomicU32 = AtomicU32::new(0); diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 774de709..2b0a669d 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -15,8 +15,6 @@ use crate::core::Rect; use komorebi_backend::MonitorId; use komorebi_core::ContainerWindow; -use crate::DEFAULT_CONTAINER_PADDING; -use crate::DEFAULT_WORKSPACE_PADDING; use crate::DefaultLayout; use crate::Layout; use crate::OperationDirection; @@ -260,10 +258,10 @@ impl MonitorExt for Monitor { fn update_workspaces_globals(&mut self, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::workspace_padding())); let (border_width, border_offset) = { let border_enabled = BORDER_ENABLED.load(Ordering::SeqCst); if border_enabled { @@ -298,10 +296,10 @@ impl MonitorExt for Monitor { fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option) { let container_padding = self .container_padding - .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::container_padding())); let workspace_padding = self .workspace_padding - .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst))); + .or(Some(crate::settings::workspace_padding())); let (border_width, border_offset) = { let border_enabled = BORDER_ENABLED.load(Ordering::SeqCst); if border_enabled { diff --git a/komorebi/src/monitor_reconciliator/mod.rs b/komorebi/src/monitor_reconciliator/mod.rs index 64c5aa85..f0a16e92 100644 --- a/komorebi/src/monitor_reconciliator/mod.rs +++ b/komorebi/src/monitor_reconciliator/mod.rs @@ -1,6 +1,5 @@ #![deny(clippy::unwrap_used, clippy::expect_used)] -use crate::DISPLAY_INDEX_PREFERENCES; use crate::DUPLICATE_MONITOR_SERIAL_IDS; use crate::Notification; use crate::NotificationEvent; @@ -106,7 +105,7 @@ pub fn display_change_in_progress(grace_period: std::time::Duration) -> bool { } pub fn insert_in_monitor_cache(serial_or_device_id: &str, monitor: Monitor) { - let dip = DISPLAY_INDEX_PREFERENCES.read(); + let dip = crate::settings::display_index_preferences(); let mut dip_ids = dip.values(); let preferred_id = if dip_ids.any(|id| id.eq(&monitor.extra.device_id)) { monitor.extra.device_id.clone() @@ -653,7 +652,7 @@ where // Let's add their state to the cache for later, make sure to use what // the user set as preference as the id. - let dip = DISPLAY_INDEX_PREFERENCES.read(); + let dip = crate::settings::display_index_preferences(); let mut dip_ids = dip.values(); let preferred_id = if dip_ids.any(|id| id.eq(&m.extra.device_id)) { m.extra.device_id.clone() diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index d091ad92..0e57644d 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -27,7 +27,6 @@ use uds_windows::UnixStream; use crate::CUSTOM_FFM; use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; use crate::HIDING_BEHAVIOUR; use crate::IGNORE_IDENTIFIERS; @@ -934,8 +933,12 @@ impl WindowManager { ); } SocketMessage::DisplayIndexPreference(index_preference, ref display) => { - let mut display_index_preferences = DISPLAY_INDEX_PREFERENCES.write(); - display_index_preferences.insert(index_preference, display.clone()); + crate::settings::settings().update(|settings| { + settings + .shared + .display_index_preferences + .insert(index_preference, display.clone()); + }); } SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => { self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?; diff --git a/komorebi/src/settings.rs b/komorebi/src/settings.rs index f73fd659..5b1e3242 100644 --- a/komorebi/src/settings.rs +++ b/komorebi/src/settings.rs @@ -1,11 +1,17 @@ //! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`). //! -//! Nothing reads this yet: the process-wide statics are still the source of truth, and each -//! migration step moves one group of them (writers and readers together) into -//! [`settings()`]. Until then the value is the starting values of those statics. +//! Each migration step moves one group of the process-wide statics (writers and readers together) +//! into [`settings()`]. Moved so far: the two default paddings, the aspect ratio of a window toggled +//! to floating, `layout_defaults` and `display_index_preferences`. The groups that have not moved +//! are still statics and the pin test compares them with the starting settings. +use std::collections::HashMap; use std::sync::LazyLock; +use komorebi_config::aspect_ratio::AspectRatio; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::LayoutDefaultEntry; + use komorebi_settings::Handle; use komorebi_settings::Shared; use komorebi_settings::shared::PlatformDefaults; @@ -28,6 +34,39 @@ pub fn settings() -> &'static Handle { &SETTINGS } +// Accessors for the groups that have moved over (S3). Each takes one snapshot, so a caller sees one +// configuration, and returns an owned value: the callers are configuration and monitor-change +// paths, not hot paths. + +/// `default_container_padding`: the padding around each tile for a monitor that sets none. +pub fn container_padding() -> i32 { + settings().snapshot().shared.defaults.container_padding +} + +/// `default_workspace_padding`: the padding inside a work area for a monitor that sets none. +pub fn workspace_padding() -> i32 { + settings().snapshot().shared.defaults.workspace_padding +} + +/// `floating_window_aspect_ratio`: the shape of a window that is toggled to floating and centred. +pub fn floating_window_aspect_ratio() -> AspectRatio { + settings().snapshot().shared.floating_window_aspect_ratio +} + +/// `layout_defaults`: what each layout starts with when a workspace sets nothing. +pub fn layout_defaults() -> HashMap { + settings().snapshot().shared.layout_defaults.clone() +} + +/// `display_index_preferences`: which monitor each configured index belongs to. +pub fn display_index_preferences() -> HashMap { + settings() + .snapshot() + .shared + .display_index_preferences + .clone() +} + #[cfg(test)] mod tests { use std::sync::atomic::Ordering; @@ -42,14 +81,6 @@ mod tests { fn the_starting_settings_are_the_starting_values_of_the_statics() { let shared = &settings().snapshot().shared; - assert_eq!( - shared.defaults.container_padding, - crate::DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst) - ); - assert_eq!( - shared.defaults.workspace_padding, - crate::DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst) - ); assert_eq!(shared.defaults.resize_delta, crate::DEFAULT_RESIZE_DELTA); assert_eq!( shared.defaults.mouse_follows_focus, diff --git a/komorebi/src/stackbar_manager/mod.rs b/komorebi/src/stackbar_manager/mod.rs index 011b9b1f..edc8aa82 100644 --- a/komorebi/src/stackbar_manager/mod.rs +++ b/komorebi/src/stackbar_manager/mod.rs @@ -1,6 +1,5 @@ mod stackbar; -use crate::DEFAULT_CONTAINER_PADDING; use crate::WindowManager; use crate::WindowsApi; use crate::container::Container; @@ -11,7 +10,6 @@ use crate::windows_backend::backend; use crossbeam_channel::Receiver; use crossbeam_channel::Sender; use crossbeam_utils::atomic::AtomicCell; -use crossbeam_utils::atomic::AtomicConsume; use komorebi_backend::WindowId; use lazy_static::lazy_static; use parking_lot::Mutex; @@ -175,7 +173,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let container_padding = ws .container_padding - .unwrap_or_else(|| DEFAULT_CONTAINER_PADDING.load_consume()); + .unwrap_or_else(crate::settings::container_padding); 'containers: for container in ws.containers_mut() { let should_add_stackbar = match STACKBAR_MODE.load() { diff --git a/komorebi/src/stackbar_manager/stackbar.rs b/komorebi/src/stackbar_manager/stackbar.rs index d2b31a54..5dd3d906 100644 --- a/komorebi/src/stackbar_manager/stackbar.rs +++ b/komorebi/src/stackbar_manager/stackbar.rs @@ -1,5 +1,3 @@ -use color_eyre::eyre::OptionExt; -use crate::DEFAULT_CONTAINER_PADDING; use crate::WINDOWS_11; use crate::WindowsApi; use crate::border_manager::BORDER_OFFSET; @@ -20,6 +18,7 @@ use crate::stackbar_manager::STACKBAR_UNFOCUSED_TEXT_COLOUR; use crate::stackbar_manager::STACKBARS_CONTAINERS; use crate::windows_api; use crate::windows_backend::backend; +use color_eyre::eyre::OptionExt; use crossbeam_utils::atomic::AtomicConsume; use komorebi_backend::WindowId; use std::os::windows::ffi::OsStrExt; @@ -172,7 +171,7 @@ impl Stackbar { ) -> color_eyre::Result<()> { let width = STACKBAR_TAB_WIDTH.load_consume(); let height = STACKBAR_TAB_HEIGHT.load_consume(); - let gap = DEFAULT_CONTAINER_PADDING.load_consume(); + let gap = crate::settings::container_padding(); let background = STACKBAR_TAB_BACKGROUND_COLOUR.load_consume(); let focused_text_colour = STACKBAR_FOCUSED_TEXT_COLOUR.load_consume(); let unfocused_text_colour = STACKBAR_UNFOCUSED_TEXT_COLOUR.load_consume(); @@ -341,7 +340,7 @@ impl Stackbar { let width = STACKBAR_TAB_WIDTH.load_consume(); let height = STACKBAR_TAB_HEIGHT.load_consume(); - let gap = DEFAULT_CONTAINER_PADDING.load_consume(); + let gap = crate::settings::container_padding(); let focused_window_idx = container.focused_window_idx(); let focused_window_rect = backend() diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index 78270b0a..82aa53ec 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -3,7 +3,6 @@ use crate::BorderStyle; use crate::CURRENT_VIRTUAL_DESKTOP; use crate::CUSTOM_FFM; use crate::DATA_DIR; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::DUPLICATE_MONITOR_SERIAL_IDS; use crate::FocusFollowsMouseImplementation; use crate::HIDING_BEHAVIOUR; @@ -211,7 +210,7 @@ impl Default for GlobalState { tray_and_multi_window_identifiers: TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock().clone(), name_change_on_launch_identifiers: OBJECT_NAME_CHANGE_ON_LAUNCH.lock().clone(), monitor_index_preferences: MONITOR_INDEX_PREFERENCES.lock().clone(), - display_index_preferences: DISPLAY_INDEX_PREFERENCES.read().clone(), + display_index_preferences: crate::settings::display_index_preferences(), ignored_duplicate_monitor_serial_ids: DUPLICATE_MONITOR_SERIAL_IDS.read().clone(), workspace_rules: WORKSPACE_MATCHING_RULES.lock().clone(), window_hiding_behaviour: *HIDING_BEHAVIOUR.lock(), diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index c508cc41..5f2e1aec 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1,25 +1,18 @@ -use crate::AspectRatio; use crate::CrossBoundaryBehaviour; use crate::DATA_DIR; -use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_MOUSE_FOLLOWS_FOCUS; use crate::DEFAULT_RESIZE_DELTA; -use crate::DEFAULT_WORKSPACE_PADDING; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::FloatingLayerBehaviour; use crate::HIDING_BEHAVIOUR; use crate::IGNORE_IDENTIFIERS; use crate::LAYERED_WHITELIST; -use crate::LAYOUT_DEFAULTS; use crate::MANAGE_IDENTIFIERS; use crate::MONITOR_INDEX_PREFERENCES; use crate::NO_TITLEBAR; use crate::OBJECT_NAME_CHANGE_ON_LAUNCH; use crate::OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST; use crate::Placement; -use crate::PredefinedAspectRatio; use crate::REGEX_IDENTIFIERS; use crate::SLOW_APPLICATION_COMPENSATION_TIME; use crate::SLOW_APPLICATION_IDENTIFIERS; @@ -86,6 +79,7 @@ use color_eyre::eyre; use crossbeam_channel::Receiver; use hotwatch::EventKind; use hotwatch::Hotwatch; +use komorebi_settings::shared::SharedDelta; use komorebi_themes::colour::Colour; use parking_lot::Mutex; use regex::Regex; @@ -138,8 +132,8 @@ pub fn workspace_config(value: &Workspace) -> WorkspaceConfig { window_container_behaviour_rules.insert(*threshold, *behaviour); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -226,8 +220,8 @@ pub fn monitor_config(value: &Monitor) -> MonitorConfig { workspaces.push(workspace_config(w)); } - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + let default_container_padding = crate::settings::container_padding(); + let default_workspace_padding = crate::settings::workspace_padding(); let container_padding = value.container_padding.and_then(|container_padding| { if container_padding == default_container_padding { @@ -338,14 +332,10 @@ impl From<&WindowManager> for StaticConfig { #[allow(deprecated)] border_z_order: None, border_implementation: Option::from(IMPLEMENTATION.load()), - default_workspace_padding: Option::from( - DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst), - ), - default_container_padding: Option::from( - DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst), - ), + default_workspace_padding: Option::from(crate::settings::workspace_padding()), + default_container_padding: Option::from(crate::settings::container_padding()), layout_defaults: { - let guard = LAYOUT_DEFAULTS.lock(); + let guard = crate::settings::layout_defaults(); if guard.is_empty() { None } else { @@ -373,7 +363,7 @@ impl From<&WindowManager> for StaticConfig { .collect::>(), ), monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()), - display_index_preferences: Option::from(DISPLAY_INDEX_PREFERENCES.read().clone()), + display_index_preferences: Option::from(crate::settings::display_index_preferences()), stackbar: None, animation: None, theme: None, @@ -383,7 +373,9 @@ impl From<&WindowManager> for StaticConfig { slow_application_identifiers: Option::from(SLOW_APPLICATION_IDENTIFIERS.lock().clone()), bar_configurations: None, remove_titlebar_applications: Option::from(NO_TITLEBAR.lock().clone()), - floating_window_aspect_ratio: Option::from(*FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock()), + floating_window_aspect_ratio: Option::from( + crate::settings::floating_window_aspect_ratio(), + ), window_handling_behaviour: Option::from(WINDOW_HANDLING_BEHAVIOUR.load()), ..Default::default() } @@ -398,20 +390,28 @@ trait ApplyGlobals { impl ApplyGlobals for StaticConfig { #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] fn apply_globals(&mut self) -> eyre::Result<()> { - *FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock() = self - .floating_window_aspect_ratio - .unwrap_or(AspectRatio::Predefined(PredefinedAspectRatio::Standard)); + // The groups that have moved to `Settings` (the two default paddings, the aspect ratio of a + // window toggled to floating, `layout_defaults` and `display_index_preferences`) are applied + // as one update, with the rules the statics had: a missing padding or display index + // preferences key keeps the value, a missing `layout_defaults` clears it and a missing + // aspect ratio is Standard (`SharedDelta::apply`). + crate::settings::settings().update(|settings| { + SharedDelta { + default_container_padding: self.default_container_padding, + default_workspace_padding: self.default_workspace_padding, + floating_window_aspect_ratio: self.floating_window_aspect_ratio, + layout_defaults: self.layout_defaults.clone(), + display_index_preferences: self.display_index_preferences.clone(), + ..SharedDelta::default() + } + .apply(&mut settings.shared); + }); if let Some(monitor_index_preferences) = &self.monitor_index_preferences { let mut preferences = MONITOR_INDEX_PREFERENCES.lock(); preferences.clone_from(monitor_index_preferences); } - if let Some(display_index_preferences) = &self.display_index_preferences { - let mut preferences = DISPLAY_INDEX_PREFERENCES.write(); - preferences.clone_from(display_index_preferences); - } - if let Some(behaviour) = self.window_hiding_behaviour { let mut window_hiding_behaviour = HIDING_BEHAVIOUR.lock(); *window_hiding_behaviour = behaviour; @@ -476,20 +476,6 @@ impl ApplyGlobals for StaticConfig { } } - if let Some(container) = self.default_container_padding { - DEFAULT_CONTAINER_PADDING.store(container, Ordering::SeqCst); - } - - if let Some(workspace) = self.default_workspace_padding { - DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst); - } - - if let Some(defaults) = &self.layout_defaults { - *LAYOUT_DEFAULTS.lock() = defaults.clone(); - } else { - LAYOUT_DEFAULTS.lock().clear(); - } - if let Some(border_width) = self.border_width { border_manager::BORDER_WIDTH.store(border_width, Ordering::SeqCst); } @@ -844,8 +830,10 @@ impl StaticConfigExt for StaticConfig { let mut value = Self::read(path)?; let mut wm = wm.lock(); - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -855,7 +843,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id) @@ -950,7 +938,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = @@ -1009,8 +997,10 @@ impl StaticConfigExt for StaticConfig { value.apply_globals()?; - let configs_with_preference: Vec<_> = - DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect(); + let configs_with_preference: Vec<_> = crate::settings::display_index_preferences() + .keys() + .copied() + .collect(); let mut configs_used = Vec::new(); let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock(); @@ -1020,7 +1010,7 @@ impl StaticConfigExt for StaticConfig { let offset = wm.work_area_offset; for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { let preferred_config_idx = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.iter().find_map(|(c_idx, id)| { (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id) @@ -1118,7 +1108,7 @@ impl StaticConfigExt for StaticConfig { .filter(|i| !configs_used.contains(i)) { let id = { - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); + let display_index_preferences = crate::settings::display_index_preferences(); display_index_preferences.get(i).cloned() }; if let (Some(id), Some(monitor_config)) = diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index c89ed7dd..9e084ef6 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -1,6 +1,5 @@ use crate::AnimationStyle; use crate::FLOATING_APPLICATIONS; -use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; use crate::HIDDEN_HWNDS; use crate::HIDING_BEHAVIOUR; use crate::IGNORE_IDENTIFIERS; @@ -316,9 +315,8 @@ impl Window { pub fn center(&mut self, work_area: &Rect, resize: bool) -> eyre::Result<()> { let (target_width, target_height) = if resize { - let (aspect_ratio_width, aspect_ratio_height) = FLOATING_WINDOW_TOGGLE_ASPECT_RATIO - .lock() - .width_and_height(); + let (aspect_ratio_width, aspect_ratio_height) = + crate::settings::floating_window_aspect_ratio().width_and_height(); let target_height = work_area.bottom / 2; let target_width = (target_height * aspect_ratio_width) / aspect_ratio_height; (target_width, target_height) diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 625245d9..98d3bed4 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -161,7 +161,6 @@ use windows_core::HSTRING; use crate::core::Rect; -use crate::DISPLAY_INDEX_PREFERENCES; use crate::DUPLICATE_MONITOR_SERIAL_IDS; use crate::MONITOR_INDEX_PREFERENCES; use crate::WINDOW_HANDLING_BEHAVIOUR; @@ -369,8 +368,8 @@ impl WindowsApi { } } - let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); - for (index, id) in &*display_index_preferences { + let display_index_preferences = crate::settings::display_index_preferences(); + for (index, id) in &display_index_preferences { if m.serial_number_id.as_ref().is_some_and(|sn| sn == id) || id.eq(&m.extra.device_id) { @@ -405,7 +404,7 @@ impl WindowsApi { // Rebuild monitor index map *monitor_usr_idx_map = HashMap::new(); let mut added_monitor_idxs = Vec::new(); - for (index, id) in &*DISPLAY_INDEX_PREFERENCES.read() { + for (index, id) in &crate::settings::display_index_preferences() { if let Some(m_idx) = monitors.elements().iter().position(|m| { m.serial_number_id.as_ref().is_some_and(|sn| sn == id) || m.extra.device_id.eq(id) }) { diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index c12ff0f6..53d1a148 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -22,8 +22,8 @@ impl komorebi_core::WorkspacePlatform for WindowsPlatform { fn default_padding() -> (Option, Option) { ( - Option::from(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst)), - Option::from(DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst)), + Option::from(crate::settings::container_padding()), + Option::from(crate::settings::workspace_padding()), ) } @@ -98,8 +98,6 @@ impl komorebi_core::WorkspacePlatform for WindowsPlatform { use std::sync::atomic::Ordering; use crate::DATA_DIR; -use crate::DEFAULT_CONTAINER_PADDING; -use crate::DEFAULT_WORKSPACE_PADDING; use crate::HIDDEN_HWNDS; use crate::INITIAL_CONFIGURATION_LOADED; use crate::KomorebiTheme; From 0499b5c7a37bd34c4ebc0075558de82956297288 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:43:43 -0700 Subject: [PATCH 7/7] docs(settings): record S1, S2 for Windows and S3 for all three daemons Section 9 of docs/dev/settings.md: what S3 moved, how apply_globals and the command write it, how readers get it, and that the only BEHAVIOUR is the single publish. Verified: not applicable (documentation). --- docs/dev/settings.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/dev/settings.md b/docs/dev/settings.md index 6ca75bb5..3aea7225 100644 --- a/docs/dev/settings.md +++ b/docs/dev/settings.md @@ -318,3 +318,15 @@ Windows S1/S2, to apply when told (all in the files kfw is changing, so not done 4. Gate: Windows clippy (`-D warnings`) and `cargo test -p komorebi --lib`; `tools/e2e-needed` will say YES (the crate is in the closure of `komorebi.exe`) so one e2e run is owed, but behaviour is unchanged. + +## 9. S1, S2 (Windows) and S3 (all three) as landed on `wip-u-settings2` + +Windows S1 and S2 were applied as described in section 8 (package `komorebi-windows`). S3 moved the two +default paddings, the floating-window aspect ratio, `layout_defaults` and `display_index_preferences` on +all three daemons: statics removed, `apply_globals` applies them with one `Handle::update` of a +`SharedDelta` that names only these keys (so the other groups are untouched), the +`DisplayIndexPreference` command is one `update`, and readers call the accessors in `settings.rs` +(`container_padding()`, `workspace_padding()`, `floating_window_aspect_ratio()`, `layout_defaults()`, +`display_index_preferences()`), each a clone from one snapshot. The only BEHAVIOUR is the single +publish. Note the KDE integration test harness (`tests/config.rs`) now resets the paddings through +`settings()`; it is the oracle that loads configurations over a fake desktop.