From d6c0c6f115331d7ac3a601234c64351295b0048e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 15:39:38 -0700 Subject: [PATCH] refactor(windows): move transparency enabled and alpha to settings Plan step 10, S4 for Windows. TRANSPARENCY_ENABLED and TRANSPARENCY_ALPHA are no longer statics: the Transparency, TransparencyAlpha and ToggleTransparency commands write settings().shared.transparency with one update, the load applies the two keys as one update (Windows keeps the value when a key is absent, unlike KDE), the transparency thread, process_event, window.rs and the state/config dump read through the accessors. BEHAVIOUR: ToggleTransparency was a load then a store and is now one update; a load publishes the two keys together. Gate: Windows e2e (transparency, config_reload). Verified: Windows clippy -D warnings --locked --all-targets on komorebi-windows (cross): clean. e2e not run. --- komorebi/src/process_command.rs | 9 +++++---- komorebi/src/process_event.rs | 3 +-- komorebi/src/settings.rs | 10 ++++++++++ komorebi/src/state.rs | 6 ++---- komorebi/src/static_config.rs | 22 +++++++++++----------- komorebi/src/transparency_manager.rs | 8 +------- komorebi/src/window.rs | 7 +++---- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index dffebe53..3848d75f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1435,14 +1435,15 @@ impl WindowManager { } }, 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::Transparency(enable) => { - transparency_manager::TRANSPARENCY_ENABLED.store(enable, Ordering::SeqCst); + crate::settings::settings().update(|settings| settings.shared.transparency.enabled = enable); } SocketMessage::TransparencyAlpha(alpha) => { - transparency_manager::TRANSPARENCY_ALPHA.store(alpha, Ordering::SeqCst); + crate::settings::settings().update(|settings| settings.shared.transparency.alpha = alpha); } SocketMessage::StackbarMode(mode) => { STACKBAR_MODE.store(mode); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 43bb0ae5..3fcac487 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -5,7 +5,6 @@ use std::sync::Arc; use color_eyre::eyre; use color_eyre::eyre::OptionExt; -use crossbeam_utils::atomic::AtomicConsume; use parking_lot::Mutex; use crate::core::Rect; @@ -158,7 +157,7 @@ impl WindowManager { if !should_manage { let mut transparency_override = false; - if transparency_manager::TRANSPARENCY_ENABLED.load_consume() { + if crate::settings::transparency_enabled() { for m in self.monitors() { for w in m.workspaces() { let event_hwnd = event.window().hwnd; diff --git a/komorebi/src/settings.rs b/komorebi/src/settings.rs index 5b1e3242..9664abb8 100644 --- a/komorebi/src/settings.rs +++ b/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/src/state.rs b/komorebi/src/state.rs index 82aa53ec..0e8c13b5 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -39,8 +39,6 @@ use crate::stackbar_manager::STACKBAR_TAB_BACKGROUND_COLOUR; use crate::stackbar_manager::STACKBAR_TAB_HEIGHT; use crate::stackbar_manager::STACKBAR_TAB_WIDTH; use crate::stackbar_manager::STACKBAR_UNFOCUSED_TEXT_COLOUR; -use crate::transparency_manager::TRANSPARENCY_ALPHA; -use crate::transparency_manager::TRANSPARENCY_ENABLED; use crate::workspace::Workspace; use komorebi_themes::colour::Colour; use komorebi_themes::colour::Rgb; @@ -200,8 +198,8 @@ impl Default for GlobalState { )), stackbar_tab_width: STACKBAR_TAB_WIDTH.load(Ordering::SeqCst), stackbar_height: STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst), - transparency_enabled: TRANSPARENCY_ENABLED.load(Ordering::SeqCst), - transparency_alpha: TRANSPARENCY_ALPHA.load(Ordering::SeqCst), + transparency_enabled: crate::settings::transparency_enabled(), + transparency_alpha: crate::settings::transparency_alpha(), transparency_blacklist: TRANSPARENCY_BLACKLIST.lock().clone(), remove_titlebars: REMOVE_TITLEBARS.load(Ordering::SeqCst), ignore_identifiers: IGNORE_IDENTIFIERS.lock().clone(), diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 5f2e1aec..dfbb2888 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -68,7 +68,6 @@ use crate::stackbar_manager::STACKBAR_TAB_HEIGHT; use crate::stackbar_manager::STACKBAR_TAB_WIDTH; use crate::stackbar_manager::STACKBAR_UNFOCUSED_TEXT_COLOUR; use crate::theme_manager; -use crate::transparency_manager; use crate::window; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; @@ -322,10 +321,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()), @@ -540,14 +539,15 @@ impl ApplyGlobals for StaticConfig { border_manager::send_notification(None); } - if let Some(transparency_enabled) = self.transparency { - transparency_manager::TRANSPARENCY_ENABLED - .store(transparency_enabled, Ordering::SeqCst); - } - - if let Some(transparency_alpha) = self.transparency_alpha { - transparency_manager::TRANSPARENCY_ALPHA.store(transparency_alpha, Ordering::SeqCst); - } + // Windows keeps the value when the key is absent (unlike KDE, which resets it) + crate::settings::settings().update(|settings| { + SharedDelta { + transparency: self.transparency, + transparency_alpha: self.transparency_alpha, + ..SharedDelta::default() + } + .apply(&mut settings.shared); + }); // the order documented at the statics in lib.rs let mut floating_applications = FLOATING_APPLICATIONS.lock(); diff --git a/komorebi/src/transparency_manager.rs b/komorebi/src/transparency_manager.rs index 8547b84e..dccb9d90 100644 --- a/komorebi/src/transparency_manager.rs +++ b/komorebi/src/transparency_manager.rs @@ -2,12 +2,9 @@ use crossbeam_channel::Receiver; use crossbeam_channel::Sender; -use crossbeam_utils::atomic::AtomicConsume; use parking_lot::Mutex; use std::sync::Arc; use std::sync::OnceLock; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicU8; use crate::REGEX_IDENTIFIERS; use crate::TRANSPARENCY_BLACKLIST; @@ -16,9 +13,6 @@ use crate::WindowManager; use crate::WindowsApi; use crate::should_act; -pub static TRANSPARENCY_ENABLED: AtomicBool = AtomicBool::new(false); -pub static TRANSPARENCY_ALPHA: AtomicU8 = AtomicU8::new(200); - static KNOWN_HWNDS: OnceLock>> = OnceLock::new(); pub struct Notification; @@ -71,7 +65,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result 'receiver: for _ in receiver { let known_hwnds = KNOWN_HWNDS.get_or_init(|| Mutex::new(Vec::new())); - if !TRANSPARENCY_ENABLED.load_consume() { + if !crate::settings::transparency_enabled() { for hwnd in known_hwnds.lock().iter() { if let Err(error) = Window::from(*hwnd).opaque() { tracing::error!("failed to make window {hwnd} opaque: {error}") diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 9e084ef6..aabebb0e 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -43,7 +43,6 @@ use crate::windows_api; use crate::windows_api::WindowsApi; use crate::windows_backend::backend; use color_eyre::eyre; -use crossbeam_utils::atomic::AtomicConsume; use komorebi_backend::WindowId; pub use komorebi_config::aspect_ratio::AspectRatio; pub use komorebi_config::aspect_ratio::PredefinedAspectRatio; @@ -632,7 +631,7 @@ impl Window { self.hwnd, false, WindowsApi::get_transparent(self.hwnd).unwrap_or(255), - transparency_manager::TRANSPARENCY_ALPHA.load_consume(), + crate::settings::transparency_alpha(), style, ); @@ -643,7 +642,7 @@ impl Window { self.update_ex_style(&ex_style)?; WindowsApi::set_transparent( self.hwnd, - transparency_manager::TRANSPARENCY_ALPHA.load_consume(), + crate::settings::transparency_alpha(), ) } } @@ -670,7 +669,7 @@ impl Window { self.hwnd, true, WindowsApi::get_transparent(self.hwnd) - .unwrap_or(transparency_manager::TRANSPARENCY_ALPHA.load_consume()), + .unwrap_or(crate::settings::transparency_alpha()), 255, style, );