Files
komorebi/komorebi/tests/border_config.rs
T
LGUG2Z 9a0693f5d1 feat(kwin): focus follows mouse through KWin's focus policy
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.
2026-10-28 07:20:49 -07:00

98 lines
4.0 KiB
Rust

//! The border keys of `komorebi.json` are the border settings: the file sets them when the daemon
//! starts and when it is read again, a key it leaves out leaves the setting as it is, and the
//! settings come out again in the configuration the daemon generates.
//!
//! This file has one test because it changes the process-wide border 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::border_manager;
use komorebi::static_config::StaticConfig;
use komorebi::window_manager::WindowManager;
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-{name}-{}.json", std::process::id()));
std::fs::write(&path, json).unwrap();
path
}
#[test]
fn the_border_keys_of_the_file_are_the_border_settings() {
let fake = Arc::new(FakeBackend::with_one_monitor());
fake.set_borders_drawn(true);
let path = write_config(
"set",
r#"{ "border": true, "border_width": 6, "border_offset": 2, "border_radius": 12 }"#,
);
let (_sender, receiver) = crossbeam_channel::bounded(1);
let socket = PathBuf::from(format!("/tmp/kmb-config-{}.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);
// the file made the settings, and the settings make the look
assert_eq!(border_manager::BORDER_WIDTH.load(Ordering::SeqCst), 6);
assert_eq!(border_manager::BORDER_OFFSET.load(Ordering::SeqCst), 2);
assert_eq!(border_manager::BORDER_RADIUS.load(Ordering::SeqCst), 12);
let border = border_manager::current_look()
.border
.expect("borders are on");
assert_eq!((border.width, border.radius), (6, 12));
// and they come out again in the generated configuration
let generated = StaticConfig::from(&*wm.lock());
assert_eq!(generated.border, Some(true));
assert_eq!(generated.border_width, Some(6));
assert_eq!(generated.border_offset, Some(2));
assert_eq!(generated.border_radius, Some(12));
// the old names of the keys are the same keys
let aliased = StaticConfig::read_raw(
r#"{ "active_window_border": false, "active_window_border_width": 4,
"active_window_border_offset": 1 }"#,
)
.unwrap();
assert_eq!(aliased.border, Some(false));
assert_eq!(aliased.border_width, Some(4));
assert_eq!(aliased.border_offset, Some(1));
// a file that is read again changes what it sets, with borders off asking for no border
let other = write_config("other", r#"{ "border": false, "border_width": 3 }"#);
with_backend(fake.clone(), || {
StaticConfig::reload(&other, &mut wm.lock()).unwrap();
});
assert_eq!(border_manager::BORDER_WIDTH.load(Ordering::SeqCst), 3);
assert!(!border_manager::BORDER_ENABLED.load(Ordering::SeqCst));
assert_eq!(border_manager::current_look().border, None);
// and one that leaves the keys out leaves the settings as they were
let empty = write_config("empty", "{}");
with_backend(fake.clone(), || {
StaticConfig::reload(&empty, &mut wm.lock()).unwrap();
});
assert_eq!(border_manager::BORDER_WIDTH.load(Ordering::SeqCst), 3);
assert_eq!(border_manager::BORDER_OFFSET.load(Ordering::SeqCst), 2);
assert_eq!(border_manager::BORDER_RADIUS.load(Ordering::SeqCst), 12);
assert!(!border_manager::BORDER_ENABLED.load(Ordering::SeqCst));
for file in [path, other, empty] {
let _ = std::fs::remove_file(file);
}
}