diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index f328792a..c67a3456 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -496,6 +496,8 @@ fn main() -> Result<()> { // File logging worker guard has to have an assignment in the main fn to work let (_guard, _color_guard) = setup()?; + WindowsApi::foreground_lock_timeout()?; + #[cfg(feature = "deadlock_detection")] detect_deadlocks(); diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 4ac889d6..57528456 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -105,7 +105,9 @@ use windows::Win32::UI::WindowsAndMessaging::SET_WINDOW_POS_FLAGS; use windows::Win32::UI::WindowsAndMessaging::SHOW_WINDOW_CMD; use windows::Win32::UI::WindowsAndMessaging::SPIF_SENDCHANGE; use windows::Win32::UI::WindowsAndMessaging::SPI_GETACTIVEWINDOWTRACKING; +use windows::Win32::UI::WindowsAndMessaging::SPI_GETFOREGROUNDLOCKTIMEOUT; use windows::Win32::UI::WindowsAndMessaging::SPI_SETACTIVEWINDOWTRACKING; +use windows::Win32::UI::WindowsAndMessaging::SPI_SETFOREGROUNDLOCKTIMEOUT; use windows::Win32::UI::WindowsAndMessaging::SW_HIDE; use windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE; use windows::Win32::UI::WindowsAndMessaging::SW_MINIMIZE; @@ -679,6 +681,42 @@ impl WindowsApi { .process() } + #[tracing::instrument] + pub fn foreground_lock_timeout() -> Result<()> { + let mut value: u32 = 0; + + Self::system_parameters_info_w( + SPI_GETFOREGROUNDLOCKTIMEOUT, + 0, + std::ptr::addr_of_mut!(value).cast(), + SPIF_SENDCHANGE, + )?; + + tracing::info!("current value of ForegroundLockTimeout is {value}"); + + if value != 0 { + tracing::info!("updating value of ForegroundLockTimeout to {value} in order to enable keyboard-driven focus updating"); + + Self::system_parameters_info_w( + SPI_SETFOREGROUNDLOCKTIMEOUT, + 0, + 0 as *mut c_void, + SPIF_SENDCHANGE, + )?; + + Self::system_parameters_info_w( + SPI_GETFOREGROUNDLOCKTIMEOUT, + 0, + std::ptr::addr_of_mut!(value).cast(), + SPIF_SENDCHANGE, + )?; + + tracing::info!("updated value of ForegroundLockTimeout is now {value}"); + } + + Ok(()) + } + #[allow(dead_code)] pub fn focus_follows_mouse() -> Result { let mut is_enabled: BOOL = unsafe { std::mem::zeroed() };