From 4a45892ca2282c85332a3bb114391911764567d2 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 20 Feb 2025 21:09:05 -0800 Subject: [PATCH] chore(deps): bump windows-rs from 0.58 to 0.59 --- Cargo.lock | 18 +++++----- Cargo.toml | 12 +++---- komorebi/src/border_manager/border.rs | 38 ++++++++++++++------ komorebi/src/border_manager/mod.rs | 16 +++++++-- komorebi/src/monitor_reconciliator/hidden.rs | 2 +- komorebi/src/stackbar_manager/stackbar.rs | 22 ++++++------ komorebi/src/windows_api.rs | 38 ++++++++------------ komorebi/src/winevent_listener.rs | 3 +- 8 files changed, 85 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c5330c3..b519ebef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2690,10 +2690,10 @@ dependencies = [ "uds_windows", "which", "win32-display-data", - "windows 0.58.0", - "windows-core 0.58.0", - "windows-implement 0.58.0", - "windows-interface 0.58.0", + "windows 0.59.0", + "windows-core 0.59.0", + "windows-implement 0.59.0", + "windows-interface 0.59.0", "winput", "winreg", ] @@ -2728,7 +2728,7 @@ dependencies = [ "sysinfo", "tracing", "tracing-subscriber", - "windows 0.58.0", + "windows 0.59.0", "windows-icons", ] @@ -2750,7 +2750,7 @@ dependencies = [ "komorebi-client", "random_word", "serde_json_lenient", - "windows 0.58.0", + "windows 0.59.0", ] [[package]] @@ -2789,7 +2789,7 @@ dependencies = [ "sysinfo", "thiserror 2.0.11", "which", - "windows 0.58.0", + "windows 0.59.0", ] [[package]] @@ -5926,12 +5926,12 @@ dependencies = [ [[package]] name = "win32-display-data" version = "0.1.0" -source = "git+https://github.com/LGUG2Z/win32-display-data?rev=3ff53fb6f53ec3ec4f9941a0409fba5e36decc46#3ff53fb6f53ec3ec4f9941a0409fba5e36decc46" +source = "git+https://github.com/LGUG2Z/win32-display-data?rev=14406d46a94d4e29ffe8a789539e453fa15cf3d3#14406d46a94d4e29ffe8a789539e453fa15cf3d3" dependencies = [ "itertools", "serde", "thiserror 1.0.69", - "windows 0.58.0", + "windows 0.59.0", "wmi", ] diff --git a/Cargo.toml b/Cargo.toml index 28ba6917..83552dd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,19 +33,19 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } paste = "1" sysinfo = "0.33" uds_windows = "1" -win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "3ff53fb6f53ec3ec4f9941a0409fba5e36decc46" } -windows-implement = { version = "0.58" } -windows-interface = { version = "0.58" } -windows-core = { version = "0.58" } +win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "14406d46a94d4e29ffe8a789539e453fa15cf3d3" } +windows-implement = { version = "0.59" } +windows-interface = { version = "0.59" } +windows-core = { version = "0.59" } shadow-rs = "0.38" which = "7" [workspace.dependencies.windows] -version = "0.58" +version = "0.59" features = [ - "implement", "Foundation_Numerics", "Win32_Devices", + "Win32_Devices_Display", "Win32_System_Com", "Win32_UI_Shell_Common", # for IObjectArray "Win32_Foundation", diff --git a/komorebi/src/border_manager/border.rs b/komorebi/src/border_manager/border.rs index 0c90fbe0..b6141d78 100644 --- a/komorebi/src/border_manager/border.rs +++ b/komorebi/src/border_manager/border.rs @@ -1,4 +1,5 @@ use crate::border_manager::window_kind_colour; +use crate::border_manager::RenderTarget; use crate::border_manager::WindowKind; use crate::border_manager::BORDER_OFFSET; use crate::border_manager::BORDER_WIDTH; @@ -32,7 +33,6 @@ use windows::Win32::Graphics::Direct2D::Common::D2D_RECT_F; use windows::Win32::Graphics::Direct2D::Common::D2D_SIZE_U; use windows::Win32::Graphics::Direct2D::D2D1CreateFactory; use windows::Win32::Graphics::Direct2D::ID2D1Factory; -use windows::Win32::Graphics::Direct2D::ID2D1HwndRenderTarget; use windows::Win32::Graphics::Direct2D::ID2D1SolidColorBrush; use windows::Win32::Graphics::Direct2D::D2D1_ANTIALIAS_MODE_PER_PRIMITIVE; use windows::Win32::Graphics::Direct2D::D2D1_BRUSH_PROPERTIES; @@ -70,11 +70,25 @@ use windows::Win32::UI::WindowsAndMessaging::WM_PAINT; use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW; use windows_core::PCWSTR; +pub struct RenderFactory(ID2D1Factory); +unsafe impl Sync for RenderFactory {} +unsafe impl Send for RenderFactory {} + +impl Deref for RenderFactory { + type Target = ID2D1Factory; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[allow(clippy::expect_used)] -static RENDER_FACTORY: LazyLock = unsafe { +static RENDER_FACTORY: LazyLock = unsafe { LazyLock::new(|| { - D2D1CreateFactory::(D2D1_FACTORY_TYPE_MULTI_THREADED, None) - .expect("creating RENDER_FACTORY failed") + RenderFactory( + D2D1CreateFactory::(D2D1_FACTORY_TYPE_MULTI_THREADED, None) + .expect("creating RENDER_FACTORY failed"), + ) }) }; @@ -100,7 +114,7 @@ pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL { #[derive(Debug, Clone)] pub struct Border { pub hwnd: isize, - pub render_target: OnceLock, + pub render_target: OnceLock, pub tracking_hwnd: isize, pub window_rect: Rect, pub window_kind: WindowKind, @@ -180,7 +194,7 @@ impl Border { loop { unsafe { - if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() { + if !GetMessageW(&mut msg, None, 0, 0).as_bool() { tracing::debug!("border window event processing thread shutdown"); break; }; @@ -261,7 +275,11 @@ impl Border { render_target.SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - if border.render_target.set(render_target.clone()).is_err() { + if border + .render_target + .set(RenderTarget(render_target.clone())) + .is_err() + { return Err(anyhow!("could not store border render target")); } @@ -275,7 +293,7 @@ impl Border { }; let mut render_targets = RENDER_TARGETS.lock(); - render_targets.insert(border.hwnd, render_target); + render_targets.insert(border.hwnd, RenderTarget(render_target)); Ok(border.clone()) }, Err(error) => Err(error.into()), @@ -300,7 +318,7 @@ impl Border { // this triggers WM_PAINT in the callback below pub fn invalidate(&self) { - let _ = unsafe { InvalidateRect(self.hwnd(), None, false) }; + let _ = unsafe { InvalidateRect(Option::from(self.hwnd()), None, false) }; } pub extern "system" fn callback( @@ -508,7 +526,7 @@ impl Border { } } } - let _ = ValidateRect(window, None); + let _ = ValidateRect(Option::from(window), None); LRESULT(0) } WM_DESTROY => { diff --git a/komorebi/src/border_manager/mod.rs b/komorebi/src/border_manager/mod.rs index 914dba56..a6422da5 100644 --- a/komorebi/src/border_manager/mod.rs +++ b/komorebi/src/border_manager/mod.rs @@ -23,6 +23,7 @@ use serde::Deserialize; use serde::Serialize; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::ops::Deref; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicI32; use std::sync::atomic::AtomicU32; @@ -57,8 +58,19 @@ lazy_static! { static ref BORDER_STATE: Mutex> = Mutex::new(HashMap::new()); static ref WINDOWS_BORDERS: Mutex> = Mutex::new(HashMap::new()); static ref FOCUS_STATE: Mutex> = Mutex::new(HashMap::new()); - static ref RENDER_TARGETS: Mutex> = - Mutex::new(HashMap::new()); + static ref RENDER_TARGETS: Mutex> = Mutex::new(HashMap::new()); +} + +#[derive(Debug, Clone)] +pub struct RenderTarget(pub ID2D1HwndRenderTarget); +unsafe impl Send for RenderTarget {} + +impl Deref for RenderTarget { + type Target = ID2D1HwndRenderTarget; + + fn deref(&self) -> &Self::Target { + &self.0 + } } pub struct Notification(pub Option); diff --git a/komorebi/src/monitor_reconciliator/hidden.rs b/komorebi/src/monitor_reconciliator/hidden.rs index 91954894..307478c8 100644 --- a/komorebi/src/monitor_reconciliator/hidden.rs +++ b/komorebi/src/monitor_reconciliator/hidden.rs @@ -87,7 +87,7 @@ impl Hidden { loop { unsafe { - if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() { + if !GetMessageW(&mut msg, None, 0, 0).as_bool() { tracing::debug!("hidden window event processing thread shutdown"); break; }; diff --git a/komorebi/src/stackbar_manager/stackbar.rs b/komorebi/src/stackbar_manager/stackbar.rs index 71f05252..a03f120e 100644 --- a/komorebi/src/stackbar_manager/stackbar.rs +++ b/komorebi/src/stackbar_manager/stackbar.rs @@ -123,7 +123,7 @@ impl Stackbar { 0, None, None, - HINSTANCE(windows_api::as_ptr!(instance)), + Option::from(HINSTANCE(windows_api::as_ptr!(instance))), None, )?; @@ -133,7 +133,7 @@ impl Stackbar { let mut msg: MSG = MSG::default(); loop { - if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() { + if !GetMessageW(&mut msg, None, 0, 0).as_bool() { tracing::debug!("stackbar window event processing thread shutdown"); break; }; @@ -183,13 +183,13 @@ impl Stackbar { WindowsApi::position_window(self.hwnd, &layout, false)?; unsafe { - let hdc = GetDC(self.hwnd()); + let hdc = GetDC(Option::from(self.hwnd())); let hpen = CreatePen(PS_SOLID, 0, COLORREF(background)); let hbrush = CreateSolidBrush(COLORREF(background)); - SelectObject(hdc, hpen); - SelectObject(hdc, hbrush); + SelectObject(hdc, hpen.into()); + SelectObject(hdc, hbrush.into()); SetBkColor(hdc, COLORREF(background)); let mut logfont = LOGFONTW { @@ -209,14 +209,14 @@ impl Stackbar { let logical_height = -MulDiv( STACKBAR_FONT_SIZE.load(Ordering::SeqCst), 72, - GetDeviceCaps(hdc, LOGPIXELSY), + GetDeviceCaps(Option::from(hdc), LOGPIXELSY), ); logfont.lfHeight = logical_height; let hfont = CreateFontIndirectW(&logfont); - SelectObject(hdc, hfont); + SelectObject(hdc, hfont.into()); for (i, window) in container.windows().iter().enumerate() { if window.hwnd == container.focused_window().copied().unwrap_or_default().hwnd { @@ -283,13 +283,13 @@ impl Stackbar { ); } - ReleaseDC(self.hwnd(), hdc); + ReleaseDC(Option::from(self.hwnd()), hdc); // TODO: error handling - let _ = DeleteObject(hpen); + let _ = DeleteObject(hpen.into()); // TODO: error handling - let _ = DeleteObject(hbrush); + let _ = DeleteObject(hbrush.into()); // TODO: error handling - let _ = DeleteObject(hfont); + let _ = DeleteObject(hfont.into()); } Ok(()) diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 729c2c72..6f53f84a 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -1,7 +1,7 @@ +use core::ffi::c_void; use std::collections::HashMap; use std::collections::VecDeque; use std::convert::TryFrom; -use std::ffi::c_void; use std::mem::size_of; use color_eyre::eyre::anyhow; @@ -236,16 +236,9 @@ impl WindowsApi { callback: MONITORENUMPROC, callback_data_address: isize, ) -> Result<()> { - unsafe { - EnumDisplayMonitors( - HDC(std::ptr::null_mut()), - None, - callback, - LPARAM(callback_data_address), - ) - } - .ok() - .process() + unsafe { EnumDisplayMonitors(None, None, callback, LPARAM(callback_data_address)) } + .ok() + .process() } pub fn valid_hmonitors() -> Result> { @@ -519,7 +512,7 @@ impl WindowsApi { unsafe { SetWindowPos( hwnd, - position, + Option::from(position), layout.left, layout.top, layout.right, @@ -557,7 +550,7 @@ impl WindowsApi { } fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> { - unsafe { PostMessageW(hwnd, message, wparam, lparam) }.process() + unsafe { PostMessageW(Option::from(hwnd), message, wparam, lparam) }.process() } pub fn close_window(hwnd: isize) -> Result<()> { @@ -600,7 +593,7 @@ impl WindowsApi { // Error ignored, as the operation is not always necessary. let _ = SetWindowPos( HWND(as_ptr!(hwnd)), - HWND_TOP, + Option::from(HWND_TOP), 0, 0, 0, @@ -616,7 +609,7 @@ impl WindowsApi { #[allow(dead_code)] pub fn top_window() -> Result { - unsafe { GetTopWindow(HWND::default())? }.process() + unsafe { GetTopWindow(None)? }.process() } pub fn desktop_window() -> Result { @@ -932,7 +925,7 @@ impl WindowsApi { } pub fn is_window(hwnd: isize) -> bool { - unsafe { IsWindow(HWND(as_ptr!(hwnd))) }.into() + unsafe { IsWindow(Option::from(HWND(as_ptr!(hwnd)))) }.into() } pub fn is_window_visible(hwnd: isize) -> bool { @@ -1160,7 +1153,7 @@ impl WindowsApi { CW_USEDEFAULT, None, None, - HINSTANCE(as_ptr!(instance)), + Option::from(HINSTANCE(as_ptr!(instance))), Some(border as _), )? } @@ -1209,7 +1202,7 @@ impl WindowsApi { CW_USEDEFAULT, None, None, - HINSTANCE(as_ptr!(instance)), + Option::from(HINSTANCE(as_ptr!(instance))), None, )? } @@ -1221,7 +1214,7 @@ impl WindowsApi { guid: &windows_core::GUID, flags: REGISTER_NOTIFICATION_FLAGS, ) -> WindowsCrateResult { - unsafe { RegisterPowerSettingNotification(HWND(as_ptr!(hwnd)), guid, flags) } + unsafe { RegisterPowerSettingNotification(HANDLE::from(HWND(as_ptr!(hwnd))), guid, flags) } } pub fn register_device_notification( @@ -1230,15 +1223,14 @@ impl WindowsApi { flags: REGISTER_NOTIFICATION_FLAGS, ) -> WindowsCrateResult { unsafe { - let state_ptr: *const core::ffi::c_void = - &mut filter as *mut _ as *const core::ffi::c_void; - RegisterDeviceNotificationW(HWND(as_ptr!(hwnd)), state_ptr, flags) + let state_ptr: *const c_void = &mut filter as *mut _ as *const c_void; + RegisterDeviceNotificationW(HANDLE::from(HWND(as_ptr!(hwnd))), state_ptr, flags) } } pub fn invalidate_rect(hwnd: isize, rect: Option<&Rect>, erase: bool) -> bool { let rect = rect.map(|rect| &rect.rect() as *const RECT); - unsafe { InvalidateRect(HWND(as_ptr!(hwnd)), rect, erase) }.as_bool() + unsafe { InvalidateRect(Option::from(HWND(as_ptr!(hwnd))), rect, erase) }.as_bool() } pub fn alt_is_pressed() -> bool { diff --git a/komorebi/src/winevent_listener.rs b/komorebi/src/winevent_listener.rs index 1187fff3..710ac0b7 100644 --- a/komorebi/src/winevent_listener.rs +++ b/komorebi/src/winevent_listener.rs @@ -3,7 +3,6 @@ use std::time::Duration; use crossbeam_channel::Receiver; use crossbeam_channel::Sender; -use windows::Win32::Foundation::HWND; use windows::Win32::UI::Accessibility::SetWinEventHook; use windows::Win32::UI::WindowsAndMessaging::DispatchMessageW; use windows::Win32::UI::WindowsAndMessaging::GetMessageW; @@ -41,7 +40,7 @@ pub fn start() { loop { unsafe { - if !GetMessageW(&mut msg, HWND(std::ptr::null_mut()), 0, 0).as_bool() { + if !GetMessageW(&mut msg, None, 0, 0).as_bool() { tracing::debug!("windows event processing thread shutdown"); break; };