mirror of
https://github.com/bitwarden/browser
synced 2026-01-31 08:43:54 +00:00
Add extension method to retrieve center coordinates from window handle
This commit is contained in:
@@ -13,6 +13,7 @@ pub use types::{
|
||||
};
|
||||
|
||||
pub use com::PluginAuthenticator;
|
||||
pub use util::HwndExt;
|
||||
|
||||
use crate::win_webauthn::{
|
||||
types::{
|
||||
|
||||
@@ -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<u16>;
|
||||
|
||||
Reference in New Issue
Block a user