diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index b6d0707a..75c56395 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -17,6 +17,7 @@ use std::time::Duration; use clap::Parser; use clap::ValueEnum; +use color_eyre::eyre::anyhow; use color_eyre::Result; use crossbeam_utils::Backoff; use komorebi::animation::AnimationEngine; @@ -193,8 +194,28 @@ fn main() -> Result<()> { let opts: Opts = Opts::parse(); CUSTOM_FFM.store(opts.focus_follows_mouse, Ordering::SeqCst); + let mut set_foreground_window_retries = 5; + let mut set_foreground_window_succeeded = false; + let process_id = WindowsApi::current_process_id(); - WindowsApi::allow_set_foreground_window(process_id)?; + while set_foreground_window_retries > 0 && !set_foreground_window_succeeded { + match WindowsApi::allow_set_foreground_window(process_id) { + Ok(_) => { + set_foreground_window_succeeded = true; + } + Err(error) => { + tracing::error!("{error}"); + set_foreground_window_retries -= 1; + } + } + + if set_foreground_window_retries == 0 { + return Err(anyhow!( + "failed call to AllowSetForegroundWindow after 5 retries" + )); + } + } + WindowsApi::set_process_dpi_awareness_context()?; let session_id = WindowsApi::process_id_to_session_id()?; diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 1d653da2..a821ec85 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -163,7 +163,7 @@ impl WindowManager { // to be consumed by integrating gui applications like bars to know // when to show visual components associated with komorebi's virtual // desktop - tracing::error!("notifying subscribers that we are back on komorebi's associated virtual desktop"); + tracing::debug!("notifying subscribers that we are back on komorebi's associated virtual desktop"); notify_subscribers( Notification { event: NotificationEvent::VirtualDesktop(