merge: wip-u-kfm2 + wip-u-settings2 (candidate 3)

Merge of kfm's macOS core migration (wip-u-kfm2 9cb4f2fa) and the settings
stack through S3 (wip-u-settings2 696d2929), both on wip-u-integ2. Two files
conflicted, both macOS; every hunk is resolved the same way: take kfm's
version of the file (its new shapes: komorebi_core Monitor/Workspace,
workspace_config and monitor_config as free functions) and re-apply the S3
change to it, because the settings side only touched lines kfm moved.

- komorebi-for-mac/komorebi/src/monitor.rs: conflict 1 (imports): kfm's
  header doc kept, the DEFAULT_CONTAINER_PADDING / DEFAULT_WORKSPACE_PADDING
  imports dropped (S3). Conflict 2 (std imports): kfm's side (no VecDeque).
  The four padding reads (the two default fallbacks in the monitor's
  workspace globals) call crate::settings::container_padding() /
  workspace_padding(); the now unused Ordering import is removed.
- komorebi-for-mac/komorebi/src/static_config.rs: both conflicts are the
  padding defaults in kfm's free functions (workspace_config, monitor_config):
  kfm's text kept, the two defaults read from settings. Re-applied S3 in this
  file: apply_globals applies paddings, aspect ratio, layout_defaults and
  display_index_preferences as one Handle::update of a SharedDelta; the
  readers (layout_defaults, aspect ratio, display preferences, paddings) use
  the accessors; the statics' imports and the now unused AspectRatio imports
  are removed.

komorebi-core and the shared crates read none of the removed statics
(grep: only the unrelated DEFAULT_*_PADDING consts in komorebi-config), so no
hook is needed. S3 semantics are unchanged from wip-u-settings2 (statics
removed, one update per load, reload merges, a few keys reset); the pins
are the settings crate's reload.rs and shared tests plus the KDE
tests/config.rs.

Verified: see the run in the progress log (macOS fake-CC clippy -D warnings
-p komorebi-macos --all-targets clean at this revision).
This commit is contained in:
LGUG2Z committed 2026-11-05 10:30:05 -08:00
commit e663e346ba
35 files changed
+556 -337

No files matched your search

Generated
+1
View File
@@ -3816,6 +3816,7 @@ dependencies = [
"komorebi-layouts",
"komorebi-protocol",
"komorebi-scrolling",
"komorebi-settings",
"komorebi-themes",
"komorebi-transport",
"lazy_static",
+127
View File
@@ -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);
}
+12
View File
@@ -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.
+5 -6
View File
@@ -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()
+2 -28
View File
@@ -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<Mutex<HashMap<String, SubscribeOptions>>> =
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<Mutex<AspectRatio>> = 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<RwLock<HashMap<usize, String>>> =
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<Mutex<Vec<WorkspaceMatchingRule>>> =
@@ -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<Mutex<HashSet<u32>>> = 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<Mutex<HashMap<DefaultLayout, LayoutDefaultEntry>>> =
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
///
+10 -20
View File
@@ -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<Rect>);
}
impl MonitorExt for Monitor {
@@ -244,10 +235,10 @@ impl MonitorExt for Monitor {
fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option<Rect>) {
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<Rect>) {
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)]
@@ -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<MonitorNotification> {
/// 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(),
@@ -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)?
+42 -11
View File
@@ -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<KdeSettings> {
&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<DefaultLayout, LayoutDefaultEntry> {
settings().snapshot().shared.layout_defaults.clone()
}
/// `display_index_preferences`: which monitor each configured index belongs to.
pub fn display_index_preferences() -> HashMap<usize, String> {
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,
+2 -3
View File
@@ -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(),
+43 -53
View File
@@ -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)) =
+2 -4
View File
@@ -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)
+4 -4
View File
@@ -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);
+2 -18
View File
@@ -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<Mutex<HashMap<String, SubscribeOptions>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc<Mutex<AspectRatio>> = Arc::new(Mutex::new(
AspectRatio::Predefined(PredefinedAspectRatio::Widescreen)
));
static ref DISPLAY_INDEX_PREFERENCES: Arc<RwLock<HashMap<usize, String>>> =
Arc::new(RwLock::new(HashMap::new()));
static ref WINDOW_RESTORE_POSITIONS: Arc<Mutex<HashMap<u32, CGRect>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref WORKSPACE_MATCHING_RULES: Arc<Mutex<Vec<WorkspaceMatchingRule>>> =
@@ -161,16 +150,11 @@ lazy_static! {
]));
static ref TITLELESS_APPLICATIONS: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
static ref UNMANAGED_WINDOW_IDS: Arc<Mutex<Vec<u32>>> = Arc::new(Mutex::new(vec![]));
pub static ref LAYOUT_DEFAULTS: Arc<Mutex<HashMap<DefaultLayout, LayoutDefaultEntry>>> =
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,
+3 -4
View File
@@ -1,4 +1,3 @@
use crate::DISPLAY_INDEX_PREFERENCES;
use crate::LibraryError;
use crate::accessibility::AccessibilityApi;
use crate::accessibility::attribute_constants::kAXFocusedApplicationAttribute;
@@ -110,8 +109,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);
}
@@ -144,7 +143,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()
+4 -7
View File
@@ -5,8 +5,6 @@
//! hide their windows in ([`MacosMonitorExtra`], written into the monitor's JSON as it always
//! was), and what it does differently from the shared monitor is [`MonitorExt`].
use crate::DEFAULT_CONTAINER_PADDING;
use crate::DEFAULT_WORKSPACE_PADDING;
use crate::container::Container;
use crate::container::ContainerExt;
use crate::core::DefaultLayout;
@@ -26,7 +24,6 @@ use color_eyre::eyre;
use color_eyre::eyre::OptionExt;
use serde::Deserialize;
use serde::Serialize;
use std::sync::atomic::Ordering;
/// The monitor over the macOS [`Window`](crate::window::Window), which is
/// `komorebi_core::Monitor` with this platform's methods added by [`MonitorExt`]
@@ -251,10 +248,10 @@ impl MonitorExt for Monitor {
fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option<Rect>) {
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);
@@ -553,10 +550,10 @@ impl MonitorExt for Monitor {
fn update_workspaces_globals(&mut self, offset: Option<Rect>) {
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);
@@ -1,4 +1,3 @@
use crate::DISPLAY_INDEX_PREFERENCES;
use crate::Notification;
use crate::NotificationEvent;
use crate::WORKSPACE_MATCHING_RULES;
@@ -47,7 +46,7 @@ fn event_rx() -> Receiver<MonitorNotification> {
}
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()
@@ -318,7 +317,8 @@ pub fn handle_notifications(wm: Arc<Mutex<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)) {
@@ -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;
@@ -1734,8 +1733,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
+42 -11
View File
@@ -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<MacosSettings> {
&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<DefaultLayout, LayoutDefaultEntry> {
settings().snapshot().shared.layout_defaults.clone()
}
/// `display_index_preferences`: which monitor each configured index belongs to.
pub fn display_index_preferences() -> HashMap<usize, String> {
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,
+1 -2
View File
@@ -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(),
+32 -44
View File
@@ -1,14 +1,10 @@
use komorebi_settings::shared::SharedDelta;
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;
@@ -46,8 +42,6 @@ use crate::monitor::MonitorExt;
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;
@@ -105,8 +99,8 @@ 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 {
@@ -191,8 +185,8 @@ 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 {
@@ -339,13 +333,13 @@ impl From<&WindowManager> for StaticConfig {
// border_z_order: None,
// border_implementation: Option::from(IMPLEMENTATION.load()),
default_workspace_padding: Option::from(
DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst),
crate::settings::workspace_padding(),
),
default_container_padding: Option::from(
DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst),
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 +359,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 +369,7 @@ 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 +385,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 +408,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 +461,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);
}
@@ -836,7 +824,7 @@ impl StaticConfigExt for StaticConfig {
let mut wm = wm.lock();
let configs_with_preference: Vec<_> =
DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
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)) =
@@ -999,7 +987,7 @@ impl StaticConfigExt for StaticConfig {
value.apply_globals()?;
let configs_with_preference: Vec<_> =
DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
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 +997,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 +1097,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)) =
+5 -10
View File
@@ -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)
+1
View File
@@ -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" }
+6 -12
View File
@@ -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,6 +23,7 @@ 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 state;
@@ -31,10 +32,10 @@ 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;
@@ -51,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;
@@ -161,8 +161,6 @@ lazy_static! {
static ref TRANSPARENCY_BLACKLIST: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(Vec::new()));
static ref MONITOR_INDEX_PREFERENCES: Arc<Mutex<HashMap<usize, Rect>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref DISPLAY_INDEX_PREFERENCES: Arc<RwLock<HashMap<usize, String>>> =
Arc::new(RwLock::new(HashMap::new()));
static ref WORKSPACE_MATCHING_RULES: Arc<Mutex<Vec<WorkspaceMatchingRule>>> =
Arc::new(Mutex::new(Vec::new()));
static ref REGEX_IDENTIFIERS: Arc<Mutex<HashMap<String, Regex>>> =
@@ -260,19 +258,15 @@ lazy_static! {
static ref WINDOWS_BY_BAR_HWNDS: Arc<Mutex<HashMap<isize, VecDeque<isize>>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc<Mutex<AspectRatio>> = Arc::new(Mutex::new(AspectRatio::Predefined(PredefinedAspectRatio::Widescreen)));
static ref CURRENT_VIRTUAL_DESKTOP: Arc<Mutex<Option<Vec<u8>>>> = Arc::new(Mutex::new(None));
pub static ref LAYOUT_DEFAULTS: Arc<Mutex<HashMap<DefaultLayout, LayoutDefaultEntry>>> =
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_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);
+4 -6
View File
@@ -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<Rect>) {
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<Rect>) {
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 {
+2 -3
View File
@@ -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()
+6 -3
View File
@@ -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)?;
+124
View File
@@ -0,0 +1,124 @@
//! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`).
//!
//! 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;
/// 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<WindowsSettings>;
static SETTINGS: LazyLock<Handle<WindowsSettings>> = 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<WindowsSettings> {
&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<DefaultLayout, LayoutDefaultEntry> {
settings().snapshot().shared.layout_defaults.clone()
}
/// `display_index_preferences`: which monitor each configured index belongs to.
pub fn display_index_preferences() -> HashMap<usize, String> {
settings()
.snapshot()
.shared
.display_index_preferences
.clone()
}
#[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.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)
);
}
}
+1 -3
View File
@@ -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<Mutex<WindowManager>>) -> 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() {
+3 -4
View File
@@ -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()
+1 -2
View File
@@ -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(),
+40 -50
View File
@@ -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::<Vec<_>>(),
),
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)) =
+2 -4
View File
@@ -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)
+3 -4
View File
@@ -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)
}) {
+2 -4
View File
@@ -22,8 +22,8 @@ impl komorebi_core::WorkspacePlatform for WindowsPlatform {
fn default_padding() -> (Option<i32>, Option<i32>) {
(
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;