Skip to content

Merge platform-specific handles into Raw*Handle#214

Open
madsmtm wants to merge 2 commits into
masterfrom
madsmtm/no-platform-handles
Open

Merge platform-specific handles into Raw*Handle#214
madsmtm wants to merge 2 commits into
masterfrom
madsmtm/no-platform-handles

Conversation

@madsmtm
Copy link
Copy Markdown
Member

@madsmtm madsmtm commented Mar 14, 2026

Implements the idea discussed in #178 (comment).

Benefits:

  • Fewer types, the API is simpler for users and the docs are less cluttered.

Cons:

  • The thread-safety guarantees that was figured out in breaking: Change thread safety guarantees for window types #192 and Make Win32WindowHandle Send + Sync #209 are now documentation-only (since there isn't a type to attach the Send/Sync impl to). Dubious of how much value this was to begin with though.
  • Bit harder to set fields like hinstance or visual_id afterwards.
    • Could be alleviated with extra helper methods (or making the type exhaustive).
  • Platform handles are split between files instead of being defined "together".
  • Fields have to be public (unless we re-add wrappers in specific cases where needed).

Fixes #178.
Replaces #204 and #194.
Makes #195 less of a problem.

@madsmtm madsmtm added the enhancement New feature or request label Mar 14, 2026
Comment thread src/lib.rs Outdated
Comment thread src/raw_window.rs Outdated
/// let handle = RawWindowHandle::new_weboffscreencanvas(index as usize);
/// # }
/// ```
pub fn new_weboffscreencanvas(obj: usize) -> Self {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Naming scheme? I don't like this name, but new_app_kit / new_ui_kit also sounds kinda weird (though I guess less weird).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would omit the new.

Copy link
Copy Markdown
Member Author

@madsmtm madsmtm Mar 16, 2026

Choose a reason for hiding this comment

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

Moved some of it to #217, the name is now new_wasm_bindgen_offscreen_canvas.

Copy link
Copy Markdown
Member Author

@madsmtm madsmtm Mar 16, 2026

Choose a reason for hiding this comment

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

I can see the argument for omitting new, I think it makes sense for the DisplayHandle helpers, I'm not convinced that it makes sense here?

Then again, my main argument against it would be if we had more methods on RawWindowHandle, then it'd feel like an accessor.

E.g. RawWindowHandle::ns_view(&self) -> Option<NonNull<c_void>>.

Copy link
Copy Markdown
Member Author

@madsmtm madsmtm Mar 16, 2026

Choose a reason for hiding this comment

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

Alternatively maybe from_ui_kit or with_ui_kit?

Only precedent for new_* in the standard library is the unstable new_in methods for allocators. I'm not aware of any constructor methods in std that don't contain either new, from or with though?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

from_ is better, I think.

Comment thread src/raw_display.rs Outdated
/// # use raw_window_handle::RawDisplayHandle;
/// let handle = RawDisplayHandle::new_uikit();
/// ```
pub fn new_uikit() -> Self {
Copy link
Copy Markdown
Member Author

@madsmtm madsmtm Mar 14, 2026

Choose a reason for hiding this comment

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

Do we need this when we have WindowHandle::uikit(), and you could just get it from WindowHandle::uikit().as_raw()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say yes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See also #215.

@madsmtm madsmtm force-pushed the madsmtm/no-platform-handles branch 2 times, most recently from 94a09de to dafd51f Compare March 14, 2026 10:41
@madsmtm madsmtm linked an issue Mar 14, 2026 that may be closed by this pull request
Base automatically changed from madsmtm/apple-tests to master March 14, 2026 15:01
@madsmtm madsmtm force-pushed the madsmtm/no-platform-handles branch from dafd51f to 56df843 Compare March 16, 2026 04:18
@madsmtm madsmtm force-pushed the madsmtm/no-platform-handles branch from 56df843 to 3b98248 Compare March 16, 2026 04:20
@madsmtm madsmtm marked this pull request as ready for review March 16, 2026 04:45
Comment thread src/lib.rs
///
/// ## Thread-Safety
///
/// WASM objects are usually bound to the main UI "thread" belonging to the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// WASM objects are usually bound to the main UI "thread" belonging to the
/// Wasm objects are usually bound to the main UI "thread" belonging to the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And all the others.

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

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

Merge RawWindowHandle and WindowHandle<'_>?

4 participants