From 001e15c2860114bf65e268f709b48342abce99a9 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 20 Mar 2025 20:07:45 -0700 Subject: [PATCH] wip dependency injection --- Cargo.lock | 2 +- Cargo.toml | 2 +- komorebi/src/monitor_reconciliator/mod.rs | 23 ++++++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9bc654bf..9bec0668 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6080,7 +6080,7 @@ dependencies = [ [[package]] name = "win32-display-data" version = "0.1.0" -source = "git+https://github.com/LGUG2Z/win32-display-data?rev=93949750b1f123fb79827ba4d66ffcab68055654#93949750b1f123fb79827ba4d66ffcab68055654" +source = "git+https://github.com/LGUG2Z/win32-display-data?rev=a28c6559a9de2f92c142a714947a9b081776caca#a28c6559a9de2f92c142a714947a9b081776caca" dependencies = [ "itertools 0.14.0", "serde", diff --git a/Cargo.toml b/Cargo.toml index 201bfde5..dd8c083f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } paste = "1" sysinfo = "0.33" uds_windows = "1" -win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "93949750b1f123fb79827ba4d66ffcab68055654" } +win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "a28c6559a9de2f92c142a714947a9b081776caca" } windows-numerics = { version = "0.2" } windows-implement = { version = "0.60" } windows-interface = { version = "0.59" } diff --git a/komorebi/src/monitor_reconciliator/mod.rs b/komorebi/src/monitor_reconciliator/mod.rs index 13c4e2c7..6294c77f 100644 --- a/komorebi/src/monitor_reconciliator/mod.rs +++ b/komorebi/src/monitor_reconciliator/mod.rs @@ -84,10 +84,12 @@ pub fn insert_in_monitor_cache(serial_or_device_id: &str, monitor: Monitor) { monitor_cache.insert(preferred_id, monitor); } -pub fn attached_display_devices() -> color_eyre::Result> { - let all_displays = win32_display_data::connected_displays_all() - .flatten() - .collect::>(); +pub fn attached_display_devices(display_provider: F) -> color_eyre::Result> +where + F: Fn() -> I + Copy, + I: Iterator>, +{ + let all_displays = display_provider().flatten().collect::>(); let mut serial_id_map = HashMap::new(); @@ -154,7 +156,7 @@ pub fn listen_for_notifications(wm: Arc>) -> color_eyre::Re tracing::info!("created hidden window to listen for monitor-related events"); std::thread::spawn(move || loop { - match handle_notifications(wm.clone()) { + match handle_notifications(wm.clone(), win32_display_data::connected_displays_all) { Ok(()) => { tracing::warn!("restarting finished thread"); } @@ -171,7 +173,14 @@ pub fn listen_for_notifications(wm: Arc>) -> color_eyre::Re Ok(()) } -pub fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> { +pub fn handle_notifications( + wm: Arc>, + display_provider: F, +) -> color_eyre::Result<()> +where + F: Fn() -> I + Copy, + I: Iterator>, +{ tracing::info!("listening"); let receiver = event_rx(); @@ -296,7 +305,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let initial_monitor_count = wm.monitors().len(); // Get the currently attached display devices - let attached_devices = attached_display_devices()?; + let attached_devices = attached_display_devices(display_provider)?; // Make sure that in our state any attached displays have the latest Win32 data for monitor in wm.monitors_mut() {