From cf728910f2e6b823ce579d454b34677fc14efdfa Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Thu, 20 Nov 2025 10:08:12 -0600 Subject: [PATCH] Add extension method to retrieve center coordinates from window handle --- .../src/win_webauthn/mod.rs | 1 + .../src/win_webauthn/util.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/mod.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/mod.rs index 1bc650b20a6..387868600d8 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/mod.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/mod.rs @@ -13,6 +13,7 @@ pub use types::{ }; pub use com::PluginAuthenticator; +pub use util::HwndExt; use crate::win_webauthn::{ types::{ diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/util.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/util.rs index cbd3d53d329..82ad7bdad99 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/util.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/win_webauthn/util.rs @@ -1,8 +1,9 @@ use windows::{ core::s, Win32::{ - Foundation::{FreeLibrary, HMODULE}, + Foundation::{FreeLibrary, HMODULE, HWND, RECT}, System::LibraryLoader::{LoadLibraryExA, LOAD_LIBRARY_SEARCH_SYSTEM32}, + UI::WindowsAndMessaging::GetWindowRect, }, }; @@ -27,6 +28,22 @@ pub(super) fn free_webauthn_lib(library: HMODULE) -> Result<(), WinWebAuthnError }) } } +pub trait HwndExt { + fn center_position(&self) -> windows::core::Result<(i32, i32)>; +} + +impl HwndExt for HWND { + fn center_position(&self) -> windows::core::Result<(i32, i32)> { + let mut window: RECT = RECT::default(); + unsafe { + GetWindowRect(*self, &mut window)?; + } + // TODO: We may need to adjust for scaling. + let center_x = (window.right + window.left) / 2; + let center_y = (window.bottom + window.top) / 2; + Ok((center_x, center_y)) + } +} pub(super) trait WindowsString { fn to_utf16(&self) -> Vec;