refactor(macos): move the animation settings to settings

Plan step 10, S5 for macOS. The seven ANIMATION_* statics are gone. The
Animation, AnimationDuration, AnimationFps and AnimationStyle commands each
write settings().shared.animation with one update (global value clears the
per-prefix map, a prefix inserts one entry); the animation block of a load is
one update through SharedDelta::apply (global clears the map, a map replaces
it, a block without fps has the default, no block keeps everything).
animation::motion_for reads enabled, duration and style from one snapshot
(Animation::motion_for) where it read three separate statics, and
frame_period reads fps from settings. The suspend() counter
(ANIMATIONS_SUSPENDED) is runtime state and stays as it is: it is the model
for the KDE and Windows guards. The test-only AnimationsOn helper in
window_manager.rs writes through settings().

BEHAVIOUR: the animator, lane and border threads no longer see a half-applied
animation reload or command (they can no longer mix the enabled flag of one
configuration with the duration or style of another), and a load publishes the
block once. Gate: macOS hand check (animation section of the hand-check list).

Verified: macOS fake-CC cargo clippy --locked --target aarch64-apple-darwin
-p komorebi-macos --all-targets -- -D warnings: clean. Nothing run on a Mac;
value semantics rest on the settings crate tests (merge, reset of fps, global
clears the map) and the KDE tests that exercise the same delta.
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent 3c1339a5a4
commit b6c00ef795
5 files changed
+86 -141

No files matched your search

+9 -49
View File
@@ -1,13 +1,7 @@
use crate::core::animation::AnimationStyle;
use parking_lot::Mutex;
pub use prefix::AnimationPrefix;
pub use komorebi_config::animation::PerAnimationPrefixConfig;
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::LazyLock;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::time::Duration;
@@ -35,27 +29,6 @@ pub const DEFAULT_ANIMATION_FPS: u64 = 60;
/// How many operations have asked for animations to be skipped for as long as they run
static ANIMATIONS_SUSPENDED: AtomicUsize = AtomicUsize::new(0);
pub static ANIMATION_STYLE_GLOBAL: LazyLock<Arc<Mutex<AnimationStyle>>> =
LazyLock::new(|| Arc::new(Mutex::new(DEFAULT_ANIMATION_STYLE)));
pub static ANIMATION_ENABLED_GLOBAL: LazyLock<Arc<AtomicBool>> =
LazyLock::new(|| Arc::new(AtomicBool::new(DEFAULT_ANIMATION_ENABLED)));
pub static ANIMATION_DURATION_GLOBAL: LazyLock<Arc<AtomicU64>> =
LazyLock::new(|| Arc::new(AtomicU64::new(DEFAULT_ANIMATION_DURATION)));
pub static ANIMATION_STYLE_PER_ANIMATION: LazyLock<
Arc<Mutex<HashMap<AnimationPrefix, AnimationStyle>>>,
> = LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
pub static ANIMATION_ENABLED_PER_ANIMATION: LazyLock<Arc<Mutex<HashMap<AnimationPrefix, bool>>>> =
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
pub static ANIMATION_DURATION_PER_ANIMATION: LazyLock<Arc<Mutex<HashMap<AnimationPrefix, u64>>>> =
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
pub static ANIMATION_FPS: AtomicU64 = AtomicU64::new(DEFAULT_ANIMATION_FPS);
/// Skips animations for as long as the guard is held
///
/// Some operations, such as stacking windows, rearrange a workspace in a way that animating would
@@ -81,29 +54,16 @@ pub fn motion_for(prefix: AnimationPrefix) -> Option<MotionSpec> {
return None;
}
let enabled = ANIMATION_ENABLED_PER_ANIMATION
.lock()
.get(&prefix)
.copied()
.unwrap_or_else(|| ANIMATION_ENABLED_GLOBAL.load(Ordering::SeqCst));
if !enabled {
return None;
}
// one snapshot: enabled, duration and style are read from the same configuration
let motion = crate::settings::settings()
.snapshot()
.shared
.animation
.motion_for(prefix)?;
Some(MotionSpec {
duration: Duration::from_millis(
ANIMATION_DURATION_PER_ANIMATION
.lock()
.get(&prefix)
.copied()
.unwrap_or_else(|| ANIMATION_DURATION_GLOBAL.load(Ordering::SeqCst)),
),
style: ANIMATION_STYLE_PER_ANIMATION
.lock()
.get(&prefix)
.copied()
.unwrap_or_else(|| *ANIMATION_STYLE_GLOBAL.lock()),
duration: Duration::from_millis(motion.duration_ms),
style: motion.style,
})
}
@@ -114,7 +74,7 @@ pub fn workspace_transitions_enabled() -> bool {
/// How long one frame takes, given the configured frames per second
pub fn frame_period() -> Duration {
let fps = ANIMATION_FPS.load(Ordering::Relaxed).clamp(1, 240);
let fps = crate::settings::animation_fps().clamp(1, 240);
Duration::from_secs_f64(1.0 / fps as f64)
}
@@ -9,13 +9,6 @@ use crate::SUBSCRIPTION_SOCKET_OPTIONS;
use crate::SUBSCRIPTION_SOCKETS;
use crate::WORKSPACE_MATCHING_RULES;
use crate::animation;
use crate::animation::ANIMATION_DURATION_GLOBAL;
use crate::animation::ANIMATION_DURATION_PER_ANIMATION;
use crate::animation::ANIMATION_ENABLED_GLOBAL;
use crate::animation::ANIMATION_ENABLED_PER_ANIMATION;
use crate::animation::ANIMATION_FPS;
use crate::animation::ANIMATION_STYLE_GLOBAL;
use crate::animation::ANIMATION_STYLE_PER_ANIMATION;
use crate::application::Application;
use crate::border_manager;
use crate::cf_array_as;
@@ -1808,41 +1801,51 @@ impl WindowManager {
SocketMessage::Theme(ref theme) => {
theme_manager::send_notification(*theme.clone());
}
SocketMessage::Animation(enable, prefix) => match prefix {
Some(prefix) => {
ANIMATION_ENABLED_PER_ANIMATION
.lock()
.insert(prefix, enable);
}
None => {
ANIMATION_ENABLED_GLOBAL.store(enable, Ordering::SeqCst);
ANIMATION_ENABLED_PER_ANIMATION.lock().clear();
}
},
SocketMessage::AnimationDuration(duration, prefix) => match prefix {
Some(prefix) => {
ANIMATION_DURATION_PER_ANIMATION
.lock()
.insert(prefix, duration);
}
None => {
ANIMATION_DURATION_GLOBAL.store(duration, Ordering::SeqCst);
ANIMATION_DURATION_PER_ANIMATION.lock().clear();
}
},
SocketMessage::AnimationFps(fps) => {
ANIMATION_FPS.store(fps, Ordering::SeqCst);
SocketMessage::Animation(enable, prefix) => {
crate::settings::settings().update(|settings| {
let animation = &mut settings.shared.animation;
match prefix {
Some(prefix) => {
animation.enabled_per_animation.insert(prefix, enable);
}
None => {
animation.enabled = enable;
animation.enabled_per_animation.clear();
}
}
});
}
SocketMessage::AnimationDuration(duration, prefix) => {
crate::settings::settings().update(|settings| {
let animation = &mut settings.shared.animation;
match prefix {
Some(prefix) => {
animation.duration_per_animation.insert(prefix, duration);
}
None => {
animation.duration = duration;
animation.duration_per_animation.clear();
}
}
});
}
SocketMessage::AnimationFps(fps) => {
crate::settings::settings().update(|settings| settings.shared.animation.fps = fps);
}
SocketMessage::AnimationStyle(style, prefix) => {
crate::settings::settings().update(|settings| {
let animation = &mut settings.shared.animation;
match prefix {
Some(prefix) => {
animation.style_per_animation.insert(prefix, style);
}
None => {
animation.style = style;
animation.style_per_animation.clear();
}
}
});
}
SocketMessage::AnimationStyle(style, prefix) => match prefix {
Some(prefix) => {
ANIMATION_STYLE_PER_ANIMATION.lock().insert(prefix, style);
}
None => {
let mut animation_style = ANIMATION_STYLE_GLOBAL.lock();
*animation_style = style;
ANIMATION_STYLE_PER_ANIMATION.lock().clear();
}
},
// Messages of other platforms: answered, and nothing else happens
SocketMessage::AddSubscriberPipe(..)
| SocketMessage::AltFocusHack(..)
@@ -67,6 +67,11 @@ pub fn display_index_preferences() -> HashMap<usize, String> {
.clone()
}
/// `animation.fps`.
pub fn animation_fps() -> u64 {
settings().snapshot().shared.animation.fps
}
#[cfg(test)]
mod tests {
use std::sync::atomic::Ordering;
+14 -45
View File
@@ -1,3 +1,4 @@
use komorebi_settings::shared::AnimationDelta;
use komorebi_settings::shared::SharedDelta;
use crate::CoreFoundationRunLoop;
use crate::DATA_DIR;
@@ -10,15 +11,6 @@ use crate::REGEX_IDENTIFIERS;
use crate::TABBED_APPLICATIONS;
use crate::TITLELESS_APPLICATIONS;
use crate::WORKSPACE_MATCHING_RULES;
use crate::animation::ANIMATION_DURATION_GLOBAL;
use crate::animation::ANIMATION_DURATION_PER_ANIMATION;
use crate::animation::ANIMATION_ENABLED_GLOBAL;
use crate::animation::ANIMATION_ENABLED_PER_ANIMATION;
use crate::animation::ANIMATION_FPS;
use crate::animation::ANIMATION_STYLE_GLOBAL;
use crate::animation::ANIMATION_STYLE_PER_ANIMATION;
use crate::animation::DEFAULT_ANIMATION_FPS;
use crate::animation::PerAnimationPrefixConfig;
use crate::border_manager;
use crate::core::ApplicationIdentifier;
use crate::core::CrossBoundaryBehaviour;
@@ -421,44 +413,21 @@ impl ApplyGlobals for StaticConfig {
// window::MINIMUM_WIDTH.store(width, Ordering::SeqCst);
// }
// the animation block, as one update: a global value clears its per-animation map, a map
// replaces the map, and a block without `fps` has the default (`SharedDelta::apply`)
if let Some(animations) = &self.animation {
match &animations.enabled {
PerAnimationPrefixConfig::Prefix(enabled) => {
ANIMATION_ENABLED_PER_ANIMATION.lock().clone_from(enabled);
crate::settings::settings().update(|settings| {
SharedDelta {
animation: Some(AnimationDelta {
enabled: animations.enabled.clone(),
style: animations.style.clone(),
duration: animations.duration.clone(),
fps: animations.fps,
}),
..SharedDelta::default()
}
PerAnimationPrefixConfig::Global(enabled) => {
ANIMATION_ENABLED_GLOBAL.store(*enabled, Ordering::SeqCst);
ANIMATION_ENABLED_PER_ANIMATION.lock().clear();
}
}
match &animations.style {
Some(PerAnimationPrefixConfig::Prefix(style)) => {
ANIMATION_STYLE_PER_ANIMATION.lock().clone_from(style);
}
Some(PerAnimationPrefixConfig::Global(style)) => {
let mut animation_style = ANIMATION_STYLE_GLOBAL.lock();
*animation_style = *style;
ANIMATION_STYLE_PER_ANIMATION.lock().clear();
}
None => {}
}
match &animations.duration {
Some(PerAnimationPrefixConfig::Prefix(duration)) => {
ANIMATION_DURATION_PER_ANIMATION.lock().clone_from(duration);
}
Some(PerAnimationPrefixConfig::Global(duration)) => {
ANIMATION_DURATION_GLOBAL.store(*duration, Ordering::SeqCst);
ANIMATION_DURATION_PER_ANIMATION.lock().clear();
}
None => {}
}
ANIMATION_FPS.store(
animations.fps.unwrap_or(DEFAULT_ANIMATION_FPS),
Ordering::SeqCst,
);
.apply(&mut settings.shared);
});
}
if let Some(border_width) = self.border_width {
@@ -4033,18 +4033,26 @@ mod tests {
impl AnimationsOn {
fn new() -> Self {
animation::ANIMATION_ENABLED_PER_ANIMATION
.lock()
.insert(AnimationPrefix::Movement, true);
crate::settings::settings().update(|settings| {
settings
.shared
.animation
.enabled_per_animation
.insert(AnimationPrefix::Movement, true);
});
Self
}
}
impl Drop for AnimationsOn {
fn drop(&mut self) {
animation::ANIMATION_ENABLED_PER_ANIMATION
.lock()
.remove(&AnimationPrefix::Movement);
crate::settings::settings().update(|settings| {
settings
.shared
.animation
.enabled_per_animation
.remove(&AnimationPrefix::Movement);
});
}
}