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.
This commit is contained in:
LGUG2Z
2022-08-13 14:40:08 -07:00
parent 6ed52c9387
commit 38ce38d65c

View File

@@ -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<WindowManagerEvent>, Receiver<WindowManagerEvent>) =