mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-23 00:44:15 +01:00
KWin has a focus policy that gives the focus to the window under the pointer, so komorebi asks for it and follows where the focus goes, as it does for any change of focus. Both implementations komorebi for Windows names are the same thing here. The KWin backend sets the focus policy and no delay in the user's kwinrc and has KWin read it, and puts the two keys back as the user had them when it is turned off and, with every other setting, when komorebi exits. The state of the daemon says whether it is on. komorebic gets focus-follows-mouse and toggle-focus-follows-mouse. The session node gets a pointer that a test drives from inside the guest: the program komorebi-pointer makes an absolute device with uinput, and komorebi_vm.Pointer sends it commands. vm-focus-follows-mouse moves it over each of two windows and checks the focus, then the policy that is put back. komorebi.json takes focus_follows_mouse, which is on with Windows or Komorebi, and a file that leaves it out turns it off and gives the user's focus policy back. Loading a configuration asks the backend for the focus policy now, so the tests that load one do it with a backend installed.
129 lines
4.7 KiB
Rust
129 lines
4.7 KiB
Rust
//! The transparency keys of `komorebi.json` are the transparency settings: the file sets them when
|
|
//! the daemon starts and when it is read again (a message that tiles and applies the opacity), a key
|
|
//! it leaves out has the default, the ignore rules keep windows opaque, and the settings come out
|
|
//! again in the configuration the daemon generates.
|
|
//!
|
|
//! This file has one test because it changes the process-wide transparency settings, which every
|
|
//! other test that tiles windows would see.
|
|
|
|
use color_eyre::eyre;
|
|
use komorebi::backend::fake::FakeBackend;
|
|
use komorebi::backend::with_backend;
|
|
use komorebi::core::SocketMessage;
|
|
use komorebi::static_config::StaticConfig;
|
|
use komorebi::transparency_manager;
|
|
use komorebi::window::Window;
|
|
use komorebi::window_manager::WindowManager;
|
|
use komorebi::window_manager_event::KWinNotification;
|
|
use komorebi::window_manager_event::SystemNotification;
|
|
use komorebi::window_manager_event::WindowManagerEvent;
|
|
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!(
|
|
"/tmp/kmb-transp-{name}-{}.json",
|
|
std::process::id()
|
|
));
|
|
std::fs::write(&path, json).unwrap();
|
|
path
|
|
}
|
|
|
|
#[test]
|
|
fn the_transparency_keys_of_the_file_are_the_transparency_settings() {
|
|
let fake = Arc::new(FakeBackend::with_one_monitor());
|
|
|
|
let path = write_config(
|
|
"on",
|
|
r#"{
|
|
"transparency": true,
|
|
"transparency_alpha": 120,
|
|
"transparency_ignore_rules": [
|
|
{ "kind": "Exe", "id": "mpv", "matching_strategy": "Equals" }
|
|
]
|
|
}"#,
|
|
);
|
|
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
|
let socket = PathBuf::from(format!("/tmp/kmb-transp-{}.sock", std::process::id()));
|
|
let listener = UnixListener::bind(&socket).unwrap();
|
|
|
|
let wm = with_backend(fake.clone(), || -> eyre::Result<WindowManager> {
|
|
let mut wm = StaticConfig::preload(&path, receiver, Some(listener))?;
|
|
wm.init()?;
|
|
Ok(wm)
|
|
})
|
|
.unwrap();
|
|
let wm = Arc::new(Mutex::new(wm));
|
|
with_backend(fake.clone(), || StaticConfig::postload(&path, &wm)).unwrap();
|
|
let _ = std::fs::remove_file(&socket);
|
|
|
|
assert!(transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst));
|
|
assert_eq!(
|
|
transparency_manager::TRANSPARENCY_ALPHA.load(Ordering::SeqCst),
|
|
120
|
|
);
|
|
|
|
// two windows, one of which the rules keep opaque, and the one without the focus is see-through
|
|
with_backend(fake.clone(), || {
|
|
for (id, exe) in [(46_001, "mpv"), (46_002, "foot"), (46_003, "foot")] {
|
|
fake.open_window(id, exe, exe, &format!("window {id}"));
|
|
wm.lock()
|
|
.process_event(WindowManagerEvent::Show(
|
|
SystemNotification::KWin(KWinNotification::WindowAdded),
|
|
Window::from(id),
|
|
))
|
|
.unwrap();
|
|
}
|
|
});
|
|
assert_eq!(fake.opacity_of(46_002), 120, "a window without the focus");
|
|
assert_eq!(fake.opacity_of(46_003), 255, "the one with the focus");
|
|
assert_eq!(fake.opacity_of(46_001), 255, "a window the rules ignore");
|
|
|
|
// and they come out again in the generated configuration
|
|
let generated = StaticConfig::from(&*wm.lock());
|
|
assert_eq!(generated.transparency, Some(true));
|
|
assert_eq!(generated.transparency_alpha, Some(120));
|
|
|
|
// a file that is read again and leaves the keys out has the defaults
|
|
let empty = write_config("empty", "{}");
|
|
with_backend(fake.clone(), || {
|
|
wm.lock()
|
|
.process_command(
|
|
SocketMessage::ReloadStaticConfiguration(empty.clone()),
|
|
vec![],
|
|
)
|
|
.unwrap();
|
|
});
|
|
assert!(!transparency_manager::TRANSPARENCY_ENABLED.load(Ordering::SeqCst));
|
|
assert_eq!(
|
|
transparency_manager::TRANSPARENCY_ALPHA.load(Ordering::SeqCst),
|
|
200
|
|
);
|
|
assert_eq!(fake.opacity_of(46_002), 255, "opaque again");
|
|
|
|
// the ignore rules add up, and are not asked again
|
|
let more = write_config(
|
|
"more",
|
|
r#"{ "transparency_ignore_rules": [
|
|
{ "kind": "Exe", "id": "mpv", "matching_strategy": "Equals" },
|
|
{ "kind": "Class", "id": "vlc", "matching_strategy": "Equals" }
|
|
] }"#,
|
|
);
|
|
with_backend(fake.clone(), || {
|
|
wm.lock()
|
|
.process_command(
|
|
SocketMessage::ReloadStaticConfiguration(more.clone()),
|
|
vec![],
|
|
)
|
|
.unwrap();
|
|
});
|
|
assert_eq!(komorebi::TRANSPARENCY_BLACKLIST.lock().len(), 2);
|
|
|
|
for file in [path, empty, more] {
|
|
let _ = std::fs::remove_file(file);
|
|
}
|
|
}
|