diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index 9d2595b8..4d5af6af 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -2048,14 +2048,15 @@ impl WindowManager { theme_manager::send_notification(*theme.clone()); } SocketMessage::Transparency(enable) => { - transparency_manager::TRANSPARENCY_ENABLED.store(enable, Ordering::SeqCst); + crate::settings::settings().update(|settings| settings.shared.transparency.enabled = enable); } SocketMessage::ToggleTransparency => { - let current = transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst); - transparency_manager::TRANSPARENCY_ENABLED.store(!current, Ordering::SeqCst); + crate::settings::settings().update(|settings| { + settings.shared.transparency.enabled = !settings.shared.transparency.enabled; + }); } SocketMessage::TransparencyAlpha(alpha) => { - transparency_manager::TRANSPARENCY_ALPHA.store(alpha, Ordering::SeqCst); + crate::settings::settings().update(|settings| settings.shared.transparency.alpha = alpha); } SocketMessage::BorderColour(kind, r, g, b) => self.set_border_colour(kind, r, g, b), SocketMessage::BorderWidth(width) => { diff --git a/komorebi-for-kde/komorebi/src/settings.rs b/komorebi-for-kde/komorebi/src/settings.rs index 11ce4186..43cb3dc3 100644 --- a/komorebi-for-kde/komorebi/src/settings.rs +++ b/komorebi-for-kde/komorebi/src/settings.rs @@ -67,6 +67,16 @@ pub fn display_index_preferences() -> HashMap { .clone() } +/// `transparency`: whether windows that are not focused are made see-through. +pub fn transparency_enabled() -> bool { + settings().snapshot().shared.transparency.enabled +} + +/// `transparency_alpha`: the opacity, 0 to 255, of a see-through window. +pub fn transparency_alpha() -> u8 { + settings().snapshot().shared.transparency.alpha +} + #[cfg(test)] mod tests { use std::sync::atomic::Ordering; diff --git a/komorebi-for-kde/komorebi/src/state.rs b/komorebi-for-kde/komorebi/src/state.rs index 2d37869d..dc45d00b 100644 --- a/komorebi-for-kde/komorebi/src/state.rs +++ b/komorebi-for-kde/komorebi/src/state.rs @@ -101,10 +101,8 @@ pub struct GlobalState { impl Default for GlobalState { fn default() -> Self { Self { - transparency_enabled: crate::transparency_manager::TRANSPARENCY_ENABLED - .load(std::sync::atomic::Ordering::SeqCst), - transparency_alpha: crate::transparency_manager::TRANSPARENCY_ALPHA - .load(std::sync::atomic::Ordering::SeqCst), + transparency_enabled: crate::settings::transparency_enabled(), + transparency_alpha: crate::settings::transparency_alpha(), transparency_blacklist: TRANSPARENCY_BLACKLIST.lock().clone(), ignore_identifiers: IGNORE_IDENTIFIERS.lock().clone(), manage_identifiers: MANAGE_IDENTIFIERS.lock().clone(), diff --git a/komorebi-for-kde/komorebi/src/static_config.rs b/komorebi-for-kde/komorebi/src/static_config.rs index 42cdbe65..0f199f2f 100644 --- a/komorebi-for-kde/komorebi/src/static_config.rs +++ b/komorebi-for-kde/komorebi/src/static_config.rs @@ -64,7 +64,6 @@ use crate::monitor::MonitorExt; use crate::monitor_reconciliator; use crate::ring::Ring; use crate::theme_manager; -use crate::transparency_manager; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crate::workspace::Workspace; @@ -351,10 +350,10 @@ impl From<&WindowManager> for StaticConfig { border: Option::from(border_manager::BORDER_ENABLED.load(Ordering::SeqCst)), border_colours, transparency: Option::from( - transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst), + crate::settings::transparency_enabled(), ), transparency_alpha: Option::from( - transparency_manager::TRANSPARENCY_ALPHA.load(Ordering::SeqCst), + crate::settings::transparency_alpha(), ), transparency_ignore_rules: None, // border_style: Option::from(STYLE.load()), @@ -555,10 +554,15 @@ impl ApplyGlobals for StaticConfig { // border_manager::send_notification(None); // } // - transparency_manager::TRANSPARENCY_ENABLED - .store(self.transparency.unwrap_or(false), Ordering::SeqCst); - transparency_manager::TRANSPARENCY_ALPHA - .store(self.transparency_alpha.unwrap_or(200), Ordering::SeqCst); + // KDE resets both when the key is absent (unlike Windows, which keeps the value) + crate::settings::settings().update(|settings| { + SharedDelta { + transparency: Some(self.transparency.unwrap_or(false)), + transparency_alpha: Some(self.transparency_alpha.unwrap_or(200)), + ..SharedDelta::default() + } + .apply(&mut settings.shared); + }); // the order every other place takes them in (floating, transparency, ignore, manage, regex): // a thread that takes two in another order can wait for one that holds what it needs diff --git a/komorebi-for-kde/komorebi/src/transparency_manager.rs b/komorebi-for-kde/komorebi/src/transparency_manager.rs index 00d26d02..33518f56 100644 --- a/komorebi-for-kde/komorebi/src/transparency_manager.rs +++ b/komorebi-for-kde/komorebi/src/transparency_manager.rs @@ -19,12 +19,7 @@ use crate::window::should_act; use crate::window_manager::WindowManager; use komorebi_backend::WindowId; use std::collections::HashSet; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicU8; -use std::sync::atomic::Ordering; -pub static TRANSPARENCY_ENABLED: AtomicBool = AtomicBool::new(false); -pub static TRANSPARENCY_ALPHA: AtomicU8 = AtomicU8::new(200); /// The opacity of a window that is not see-through at all. const OPAQUE: u8 = 255; @@ -107,8 +102,10 @@ pub fn transparent_windows(wm: &WindowManager) -> Vec { /// are made opaque, and the others are given [`TRANSPARENCY_ALPHA`]. With transparency off, every /// window is opaque. A failure is logged. pub fn apply(wm: &mut WindowManager) { - let alpha = TRANSPARENCY_ALPHA.load(Ordering::SeqCst); - let wanted: HashSet = if TRANSPARENCY_ENABLED.load(Ordering::SeqCst) { + // one snapshot, so the flag and the alpha are from the same configuration + let settings = crate::settings::settings().snapshot(); + let alpha = settings.shared.transparency.alpha; + let wanted: HashSet = if settings.shared.transparency.enabled { transparent_windows(wm).into_iter().collect() } else { HashSet::new() diff --git a/komorebi-for-kde/komorebi/tests/transparency.rs b/komorebi-for-kde/komorebi/tests/transparency.rs index 016a6b6f..8b35cc57 100644 --- a/komorebi-for-kde/komorebi/tests/transparency.rs +++ b/komorebi-for-kde/komorebi/tests/transparency.rs @@ -13,8 +13,6 @@ use komorebi::core::config_generation::MatchingRule; use komorebi::core::config_generation::MatchingStrategy; use komorebi::state::GlobalState; use komorebi::transparency_manager; -use komorebi::transparency_manager::TRANSPARENCY_ALPHA; -use komorebi::transparency_manager::TRANSPARENCY_ENABLED; use komorebi::window::Window; use komorebi::window_manager::WindowManager; use komorebi::window_manager_event::KWinNotification; @@ -75,8 +73,10 @@ static TRANSPARENCY: std::sync::Mutex<()> = std::sync::Mutex::new(()); /// The settings are process-wide, as they are on Windows: one test at a time, from the defaults fn transparency_settings() -> std::sync::MutexGuard<'static, ()> { let guard = TRANSPARENCY.lock().unwrap_or_else(|e| e.into_inner()); - TRANSPARENCY_ENABLED.store(false, std::sync::atomic::Ordering::SeqCst); - TRANSPARENCY_ALPHA.store(200, std::sync::atomic::Ordering::SeqCst); + komorebi::settings::settings().update(|settings| { + settings.shared.transparency.enabled = false; + settings.shared.transparency.alpha = 200; + }); TRANSPARENCY_BLACKLIST.lock().clear(); guard } diff --git a/komorebi-for-kde/komorebi/tests/transparency_config.rs b/komorebi-for-kde/komorebi/tests/transparency_config.rs index 8d138ee4..111d593a 100644 --- a/komorebi-for-kde/komorebi/tests/transparency_config.rs +++ b/komorebi-for-kde/komorebi/tests/transparency_config.rs @@ -12,7 +12,6 @@ use komorebi::backend::with_backend; use komorebi::core::SocketMessage; use komorebi::static_config::StaticConfig; use komorebi::static_config::StaticConfigExt; -use komorebi::transparency_manager; use komorebi::window::Window; use komorebi::window_manager::WindowManager; use komorebi::window_manager_event::KWinNotification; @@ -22,7 +21,6 @@ use parking_lot::Mutex; use std::os::unix::net::UnixListener; use std::path::PathBuf; use std::sync::Arc; -use std::sync::atomic::Ordering; fn write_config(name: &str, json: &str) -> PathBuf { let path = PathBuf::from(format!( @@ -61,9 +59,9 @@ fn the_transparency_keys_of_the_file_are_the_transparency_settings() { with_backend(fake.clone(), || StaticConfig::postload(&path, &wm)).unwrap(); let _ = std::fs::remove_file(&socket); - assert!(transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst)); + assert!(komorebi::settings::transparency_enabled()); assert_eq!( - transparency_manager::TRANSPARENCY_ALPHA.load(Ordering::SeqCst), + komorebi::settings::transparency_alpha(), 120 ); @@ -98,9 +96,9 @@ fn the_transparency_keys_of_the_file_are_the_transparency_settings() { ) .unwrap(); }); - assert!(!transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst)); + assert!(!komorebi::settings::transparency_enabled()); assert_eq!( - transparency_manager::TRANSPARENCY_ALPHA.load(Ordering::SeqCst), + komorebi::settings::transparency_alpha(), 200 ); assert_eq!(fake.opacity_of(46_002), 255, "opaque again");