Expose window HWND on Windows (mirrors apple_view() on macOS)#603
Expose window HWND on Windows (mirrors apple_view() on macOS)#603TheRedDeveloper wants to merge 3 commits intonot-fl3:masterfrom
Conversation
src/native/windows.rs
Outdated
| /// Get the main window HWND as a raw pointer. | ||
| /// | ||
| /// Returns `null_mut()` if the window has not been created yet. | ||
| pub fn get_window_hwnd() -> *mut std::ffi::c_void { |
There was a problem hiding this comment.
I would make this one pub(crate).
There was a problem hiding this comment.
get_window_hwnd() is now pub(crate). External access goes through the public window::windows_hwnd() API.
src/native/windows.rs
Outdated
| static IME_USER_DISABLED: AtomicBool = AtomicBool::new(false); | ||
|
|
||
| /// The main window HWND, stored as a raw pointer for cross-crate access. | ||
| static WINDOW_HWND: AtomicPtr<std::ffi::c_void> = AtomicPtr::new(std::ptr::null_mut()); |
There was a problem hiding this comment.
I wonder if we can store it in NativeDisplay, like on MacOs. Not crytical, but would be nic eto avoid an extra static.
There was a problem hiding this comment.
removed the static WINDOW_HWND: AtomicPtr and moved the HWND into NativeDisplayData with a #[cfg(target_os = "windows")] field, matching how macOS stores view.
src/native/windows.rs
Outdated
| }); | ||
|
|
||
| // Store the HWND in NativeDisplayData so external code can access it via window::windows_hwnd() | ||
| crate::native_display().lock().unwrap().hwnd = wnd as *mut std::ffi::c_void; |
There was a problem hiding this comment.
Can't we just pass it to set_display call?
set_display(NativdeDisplayData { .. wnd: wnd as *mut .. } if it makes sense?
There was a problem hiding this comment.
moved it into the set_display struct
src/native/windows.rs
Outdated
| /// Get the main window HWND as a raw pointer. | ||
| /// | ||
| /// Returns `null_mut()` if the window has not been created yet. | ||
| pub(crate) fn get_window_hwnd() -> *mut std::ffi::c_void { |
There was a problem hiding this comment.
do we really need this function? windows_hwnd() seems enough?
There was a problem hiding this comment.
windows_hwnd() now reads from native_display()
This adds a
window::windows_hwnd()function that returns the main window's HWND as*mut c_void, analogous to the existingwindow::apple_view()on macOS.Issue
Downstream crates that integrate with Windows platform APIs (accessibility via UI Automation / AccessKit, drag-and-drop, theming, etc.) need the HWND but currently can't access it since
WindowsDisplay.wndispub(crate).Solution
windows.rs: Added a staticWINDOW_HWNDthat is set immediately afterCreateWindowExW, and a publicget_window_hwnd()function.lib.rs: Addedwindow::windows_hwnd()(gated behind#[cfg(target_os = "windows")]).It's just a new public function I need to implement accessibility features on Windows.