Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get underlying window handle #193

Merged
merged 3 commits into from
Jan 12, 2024
Merged

Add ability to get underlying window handle #193

merged 3 commits into from
Jan 12, 2024

Conversation

notgull
Copy link
Member

@notgull notgull commented Jan 10, 2024

Adds the get_ref and get_mut functions, which can be used to get
references (mutable or otherwise) to the underlying window handle.

cc rust-windowing/raw-window-handle#158 (comment)

Adds the `get_ref` and `get_mut` functions, which can be used to get
references (mutable or otherwise) to the underlying window handle.

cc rust-windowing/raw-window-handle#158 (comment)

Signed-off-by: John Nunley <[email protected]>
@ids1024
Copy link
Member

ids1024 commented Jan 10, 2024

For iced-rs/iced#2191, I also ended up needing Arc<Window> to create a softbuffer::Context and softbuffer::Surface from the same HasWindowHandle + HasDisplayHandle. Not sure how best to avoid that there.

Using Arc isn't really a problem even, it just seems a little odd from an API standpoint.

Having accessors like this seems reasonable, regardless.

@notgull
Copy link
Member Author

notgull commented Jan 10, 2024

For iced-rs/iced#2191, I also ended up needing Arc<Window> to create a softbuffer::Context and softbuffer::Surface from the same HasWindowHandle + HasDisplayHandle. Not sure how best to avoid that there.

Probably by using an owned display handle, tracked in rust-windowing/winit#3365

Copy link
Member

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

How about calling them window() and window_mut()?
See the Rust API Guidelines.

Signed-off-by: John Nunley <[email protected]>
@notgull notgull requested a review from daxpedda January 11, 2024 02:13
@kpreid
Copy link
Contributor

kpreid commented Jan 11, 2024

In a previous much-different version of softbuffer, the window_mut() operation that existed then had to be unsafe, because mutable access is sufficient to swap it with a completely unrelated handle, thus violating the invariant that the context referred to the expected window, allowing the window in use to be dropped. Is that not still a problem here? I have not kept up with how raw-window-handle works these days.

If that invariant still applies, then window_mut() needs to be unsafe.

@notgull
Copy link
Member Author

notgull commented Jan 11, 2024

Good catch! Yes that still happens, let me fix it

There are considerations to be made here, so remove it for now.

Signed-off-by: John Nunley <[email protected]>
Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

LGTM after the removal of window_mut

@ids1024
Copy link
Member

ids1024 commented Jan 12, 2024

Perhaps it would also make sense to have a .context() accessor on Surface, and a .display() accessor on Context. But that is probably less often useful.

@notgull notgull merged commit 832064c into master Jan 12, 2024
39 checks passed
@notgull notgull deleted the notgull/getref branch January 12, 2024 16:40
@notgull notgull mentioned this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants