refactor(kde): move paddings, aspect ratio, layout defaults and display preferences to settings

Plan step 10, S3. The two default paddings, the aspect ratio of a window
toggled to floating (centre with resize), layout_defaults and
display_index_preferences are no longer statics: their writers
(apply_globals through SharedDelta::apply, the DisplayIndexPreference
command) and all readers use settings() together. The semantics are the
statics': a missing padding or display_index_preferences key keeps the
value, a missing layout_defaults clears it, a missing aspect ratio is
Standard (not the initial Widescreen), and the command inserts one entry.
Readers get an owned copy from one snapshot (accessors in settings.rs).

BEHAVIOUR only in this: apply_globals used to store these keys one at a
time and now publishes the group in one update, so a thread can no longer see
a half-applied reload of them. Value semantics are pinned by
crates/komorebi-settings tests/reload.rs and shared.rs (reload merges, a
few keys reset, a load never touches groups it does not name).

KDE: window.rs, desktop.rs, monitor.rs, monitor_reconciliator.rs, state.rs,
static_config.rs, process_command.rs, lib.rs and tests/config.rs (the test
harness resets the paddings through settings()).

Verified: KDE cargo test --locked -p komorebi-linux --lib --tests (lite env,
own target dir): 63 test binaries, 631 passed, 0 failed, including
tests/config.rs that loads configurations over a fake desktop. KDE VM suites
not run (gate: config reload and workspace padding suites).
This commit is contained in:
LGUG2Z committed 2026-11-05 10:30:05 -08:00
1 parent 6f8bc2b0ba
commit 04c10a00a5
10 files changed
+123 -140

No files matched your search

+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);