8000
  • Expose window HWND on Windows (mirrors apple_view() on macOS) by TheRedDeveloper · Pull Request #603 · not-fl3/miniquad · GitHub
    [go: up one dir, main page]

    Skip to content

    Expose window HWND on Windows (mirrors apple_view() on macOS) - #603

    Open
    TheRedDeveloper wants to merge 3 commits into
    not-fl3:masterfrom
    TheRedDeveloper:hwndexpose
    Open

    TheRedDeveloper wants to merge 3 commits into
    not-fl3:masterfrom
    TheRedDeveloper:hwndexpose

    Conversation

    @TheRedDeveloper
    Copy link
    Copy Markdown

    This adds a window::windows_hwnd() function that returns the main window's HWND as *mut c_void, analogous to the existing window::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.wnd is pub(crate).

    Solution

    • windows.rs: Added a static WINDOW_HWND that is set immediately after CreateWindowExW, and a public get_window_hwnd() function.
    • lib.rs: Added window::windows_hwnd() (gated behind #[cfg(target_os = "windows")]).

    It's just a new public function I need to implement accessibility features on Windows.

    Comment thread 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 {
    Copy link
    Copy Markdown
    Owner

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I would make this one pub(crate).

    Copy link
    Copy Markdown
    Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    get_window_hwnd() is now pub(crate). External access goes through the public window::windows_hwnd() API.

    Comment thread 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());
    Copy link
    Copy Markdown
    Owner

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I wonder if we can store it in NativeDisplay, like on MacOs. Not crytical, but would be nic eto avoid an extra static.

    @TheRedDeveloper TheRedDeveloper Feb 18, 2026 •
    Copy link
    Copy Markdown
    Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    removed the static WINDOW_HWND: AtomicPtr and moved the HWND into NativeDisplayData with a #[cfg(target_os = "windows")] field, matching how macOS stores view.

    Comment thread 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;
    Copy link
    Copy Markdown
    Owner

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Can't we just pass it to set_display call?

    set_display(NativdeDisplayData { .. wnd: wnd as *mut .. } if it makes sense?

    Copy link
    Copy Markdown
    Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    moved it into the set_display struct

    Comment thread 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 {
    Copy link
    Copy Markdown
    Owner

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    do we really need this function? windows_hwnd() seems enough?

    Copy link
    Copy Markdown
    Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    windows_hwnd() now reads from native_display()

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants

    0