refactor(kde): move transparency enabled and alpha to settings

Plan step 10, S4. TRANSPARENCY_ENABLED and TRANSPARENCY_ALPHA are no
longer statics: the Transparency and TransparencyAlpha commands and
ToggleTransparency write settings().shared.transparency with one update, the
load applies both keys as one update, the transparency manager reads the flag
and the alpha from one snapshot, and state and the config dump use the
accessors. KDE's load RESETS both keys when absent (false, 200), unlike
Windows which keeps the value; the delta passed to SharedDelta::apply is built
with unwrap_or so that stays exactly as it was. tests/transparency.rs and
transparency_config.rs use settings() (the latter pins the load with and
without the keys).

BEHAVIOUR: (1) ToggleTransparency was a load then a store and is now one
update, so two toggles cannot lose each other; (2) the load publishes both keys
together. Gate: KDE VM suite for transparency/opacity.

Verified: KDE cargo test --locked -p komorebi-linux --lib --tests (lite
env): 58 binaries, 623 passed, 0 failed. VM suites not run.
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent acbe816fb4
commit 28db46e4f1
7 files changed
+40 -32

No files matched your search

@@ -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) => {
+10
View File
@@ -67,6 +67,16 @@ pub fn display_index_preferences() -> HashMap<usize, String> {
.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;
+2 -4
View File
@@ -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(),
+11 -7
View File
@@ -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
@@ -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<u32> {
/// 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<u32> = 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<u32> = if settings.shared.transparency.enabled {
transparent_windows(wm).into_iter().collect()
} else {
HashSet::new()
@@ -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
}
@@ -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");