From a550c088dcbfa99888407fc0faffc783159b5afa Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 14 Aug 2021 06:55:28 -0700 Subject: [PATCH] fix(wm): don't attach to the desktop window thread Noticed in the logs when looking at issue #2 that an "Access is denied. (os error 5)" error was being reported when trying to attach to the thread of the special Desktop Window, which only happens when switching to a workspace which doesn't contain any windows. Calling WindowsApi::set_foreground_window on the HWND directly seems to be the better option here. --- komorebi/src/window_manager.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index d1097b68..15e2189e 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -89,7 +89,11 @@ impl WindowManager { hwnd: WindowsApi::desktop_window()?, }; - desktop_window.focus()?; + // Calling this directly instead of the window.focus() wrapper because trying to + // attach to the thread of the desktop window always seems to result in "Access is + // denied (os error 5)" + WindowsApi::set_foreground_window(desktop_window.hwnd()) + .map_err(|error| eyre::anyhow!("{} {}:{}", error, file!(), line!()))?; } }