Files
komorebi/komorebi/tests/config_displays.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

100 lines
3.2 KiB
Rust

//! A `komorebi.json` with more than one monitor in it, against an in-memory desktop with three:
//! which monitor takes which configuration.
//!
//! A monitor takes the configuration at the index `display_index_preferences` gives its serial
//! number id, and a monitor without one takes the first configuration that no preference and no
//! monitor has taken. The preferences are process-wide, so this file is one test.
use komorebi::backend::fake::FakeBackend;
use komorebi::backend::with_backend;
use komorebi::core::Rect;
use komorebi::monitor::Monitor;
use komorebi::static_config::StaticConfig;
use parking_lot::Mutex;
use std::os::unix::net::UnixListener;
use std::path::PathBuf;
use std::sync::Arc;
fn screen(width: i32) -> Rect {
Rect {
left: 0,
top: 0,
right: width,
bottom: 1080,
}
}
fn workspace_names(monitor: &Monitor) -> Vec<Option<String>> {
monitor
.workspaces()
.iter()
.map(|workspace| workspace.name.clone())
.collect()
}
#[test]
fn a_monitor_takes_the_configuration_its_display_index_preference_gives_it() {
let fake = Arc::new(FakeBackend::new());
fake.add_monitor(1, "Left", screen(1920), screen(1920));
fake.add_monitor(2, "Right", screen(1920), screen(1920));
fake.add_monitor(3, "Third", screen(1920), screen(1920));
let path = PathBuf::from(format!("/tmp/kmd-{}.json", std::process::id()));
std::fs::write(
&path,
r#"{
"display_index_preferences": { "1": "Left" },
"monitors": [
{ "workspaces": [ { "name": "first" } ] },
{ "workspaces": [ { "name": "second" }, { "name": "second too" } ] }
]
}"#,
)
.unwrap();
let socket = PathBuf::from(format!("/tmp/kmd-{}.sock", std::process::id()));
let (_sender, receiver) = crossbeam_channel::bounded(1);
let wm = with_backend(fake.clone(), || {
let mut wm =
StaticConfig::preload(&path, receiver, Some(UnixListener::bind(&socket).unwrap()))
.unwrap();
wm.init().unwrap();
wm
});
let wm = Arc::new(Mutex::new(wm));
with_backend(fake.clone(), || StaticConfig::postload(&path, &wm)).unwrap();
let _ = std::fs::remove_file(&socket);
let _ = std::fs::remove_file(&path);
let wm = wm.lock();
let monitor = |serial: &str| -> &Monitor {
wm.monitors()
.iter()
.find(|monitor| monitor.serial_number_id == serial)
.unwrap()
};
// the preference makes "Left" the monitor of the second configuration
assert_eq!(
workspace_names(monitor("Left")),
[
Some(String::from("second")),
Some(String::from("second too"))
]
);
// "Right" has no preference: the first configuration that is no one's preference
assert_eq!(
workspace_names(monitor("Right")),
[Some(String::from("first"))]
);
// "Third" has none left, and keeps what it began with
assert_eq!(workspace_names(monitor("Third")), [None]);
// and the state the daemon would generate keeps the preference
let generated = StaticConfig::from(&*wm);
assert_eq!(
generated.display_index_preferences.unwrap().get(&1),
Some(&String::from("Left"))
);
}