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)