From 38ce38d65c6a7c1495490f9f33c7f0445a725091 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 13 Aug 2022 14:40:08 -0700 Subject: [PATCH] fix(wm): improve startup reliability This commit wraps calls to the Windows API which may intermittently fail in backoff blocks, reducing the potential of early exits from errors returned by the Windows API before the tiling has even started. Hopefully this makes calls to 'komorebic start' more relible for use at login time. --- komorebi/src/main.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 101bbcae..ec710159 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -434,8 +434,41 @@ fn main() -> Result<()> { detect_deadlocks(); let process_id = WindowsApi::current_process_id(); - WindowsApi::allow_set_foreground_window(process_id)?; - WindowsApi::set_process_dpi_awareness_context()?; + + { + let mut proceed = false; + let backoff = Backoff::new(); + + while !proceed { + if WindowsApi::allow_set_foreground_window(process_id).is_ok() { + proceed = true; + } else { + tracing::warn!( + "could not allow komorebi to set foreground windows, retrying..." + ); + + backoff.snooze(); + } + } + } + + { + let mut proceed = false; + let backoff = Backoff::new(); + + while !proceed { + if WindowsApi::set_process_dpi_awareness_context().is_ok() { + proceed = true; + } else { + tracing::warn!( + "could not allow komorebi to set itself as dpi-aware, retrying..." + ); + + backoff.snooze(); + } + } + } + Border::create("komorebi-border-window")?; let (outgoing, incoming): (Sender, Receiver) =