diff --git a/Cargo.lock b/Cargo.lock index 80eb7dee5..54d10330a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1501,17 +1501,17 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e30acc718a52fb130fec72b1cb5f55ffeeec9253e1b785e94db222178a6acaa1" +checksum = "0286ba339aa753e70765d521bb0242cc48e1194562bfa2a2ad7ac8a6de28f5d5" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.40.0", - "windows_i686_gnu 0.40.0", - "windows_i686_msvc 0.40.0", - "windows_x86_64_gnu 0.40.0", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.40.0", + "windows_x86_64_msvc 0.42.0", ] [[package]] @@ -1542,9 +1542,9 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3caa4a1a16561b714323ca6b0817403738583033a6a92e04c5d10d4ba37ca10" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" [[package]] name = "windows_aarch64_msvc" @@ -1560,9 +1560,9 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "328973c62dfcc50fb1aaa8e7100676e0b642fe56bac6bafff3327902db843ab4" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" @@ -1578,9 +1578,9 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa5b09fad70f0df85dea2ac2a525537e415e2bf63ee31cf9b8e263645ee9f3c1" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" @@ -1596,9 +1596,9 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_i686_msvc" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1ad4031c1a98491fa195d8d43d7489cb749f135f2e5c4eed58da094bd0d876" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" @@ -1614,15 +1614,15 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520ff37edd72da8064b49d2281182898e17f0688ae9f4070bca27e4b5c162ac7" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" [[package]] name = "windows_x86_64_gnullvm" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046e5b82215102c44fd75f488f1b9158973d02aa34d06ed85c23d6f5520a2853" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" @@ -1638,9 +1638,9 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" -version = "0.40.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0c9c6df55dd1bfa76e131cef44bdd8ec9c819ef3611f04dfe453fd5bfeda28" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "winput" diff --git a/komorebi-core/Cargo.toml b/komorebi-core/Cargo.toml index 849c56a16..660433cbb 100644 --- a/komorebi-core/Cargo.toml +++ b/komorebi-core/Cargo.toml @@ -15,7 +15,7 @@ strum = { version = "0.24", features = ["derive"] } schemars = "0.8" [dependencies.windows] -version = "0.40" +version = "0.42" features = [ "Win32_Foundation", ] diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 30c062da6..f52778c28 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -43,7 +43,7 @@ winput = "0.2" winreg = "0.10" [dependencies.windows] -version = "0.40" +version = "0.42" features = [ "Win32_Foundation", "Win32_Graphics_Dwm", diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 0d90d577f..961a01bc3 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -1,7 +1,6 @@ use std::collections::VecDeque; use std::convert::TryFrom; use std::ffi::c_void; -use std::slice; use std::sync::atomic::Ordering; use color_eyre::eyre::anyhow; @@ -22,6 +21,7 @@ use windows::Win32::Graphics::Dwm::DwmSetWindowAttribute; use windows::Win32::Graphics::Dwm::DWMWA_CLOAKED; use windows::Win32::Graphics::Dwm::DWMWA_WINDOW_CORNER_PREFERENCE; use windows::Win32::Graphics::Dwm::DWMWCP_ROUND; +use windows::Win32::Graphics::Dwm::DWMWINDOWATTRIBUTE; use windows::Win32::Graphics::Dwm::DWM_CLOAKED_APP; use windows::Win32::Graphics::Dwm::DWM_CLOAKED_INHERITED; use windows::Win32::Graphics::Dwm::DWM_CLOAKED_SHELL; @@ -425,7 +425,9 @@ impl WindowsApi { // Behaviour is undefined if an invalid HWND is given // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid - let thread_id = unsafe { GetWindowThreadProcessId(hwnd, Option::from(&mut process_id)) }; + let thread_id = unsafe { + GetWindowThreadProcessId(hwnd, Option::from(std::ptr::addr_of_mut!(process_id))) + }; (process_id, thread_id) } @@ -553,15 +555,29 @@ impl WindowsApi { Ok(String::from_utf16(&class[0..len as usize])?) } - pub fn is_window_cloaked(hwnd: HWND) -> Result { - let mut cloaked = 0_u32.to_be_bytes(); - + pub fn dwm_get_window_attribute( + hwnd: HWND, + attribute: DWMWINDOWATTRIBUTE, + value: &mut T, + ) -> Result<()> { unsafe { - DwmGetWindowAttribute(hwnd, DWMWA_CLOAKED, &mut cloaked)?; + DwmGetWindowAttribute( + hwnd, + attribute, + (value as *mut T).cast(), + u32::try_from(std::mem::size_of::())?, + )?; } + Ok(()) + } + + pub fn is_window_cloaked(hwnd: HWND) -> Result { + let mut cloaked: u32 = 0; + Self::dwm_get_window_attribute(hwnd, DWMWA_CLOAKED, &mut cloaked)?; + Ok(matches!( - u32::from_be_bytes(cloaked), + cloaked, DWM_CLOAKED_APP | DWM_CLOAKED_SHELL | DWM_CLOAKED_INHERITED )) } @@ -612,7 +628,7 @@ impl WindowsApi { pv_param: *mut c_void, update_flags: SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, ) -> Result<()> { - unsafe { SystemParametersInfoW(action, ui_param, pv_param, update_flags) } + unsafe { SystemParametersInfoW(action, ui_param, Option::from(pv_param), update_flags) } .ok() .process() } @@ -681,7 +697,8 @@ impl WindowsApi { DwmSetWindowAttribute( HWND(hwnd), DWMWA_WINDOW_CORNER_PREFERENCE, - slice::from_raw_parts(std::ptr::addr_of!(round).cast(), 4), + std::ptr::addr_of!(round).cast(), + 4, ) } .process() @@ -701,7 +718,7 @@ impl WindowsApi { None, None, instance, - std::ptr::null(), + None, ); SetLayeredWindowAttributes(hwnd, COLORREF(TRANSPARENCY_COLOUR), 0, LWA_COLORKEY); diff --git a/komorebic/Cargo.toml b/komorebic/Cargo.toml index f89264dbf..7568dff3f 100644 --- a/komorebic/Cargo.toml +++ b/komorebic/Cargo.toml @@ -29,7 +29,7 @@ sysinfo = "0.26" uds_windows = "1" [dependencies.windows] -version = "0.40" +version = "0.42" features = [ "Win32_Foundation", "Win32_UI_WindowsAndMessaging"