Skip to content

Add ability to get underlying window handle - #193

Merged
notgull merged 3 commits into
masterfrom
notgull/getref
Jan 12, 2024
Merged

notgull merged 3 commits into
masterfrom
notgull/getref

Conversation

@notgull

@notgull notgull commented Jan 10, 2024

Copy link
Copy Markdown
Collaborator

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 <dev@notgull.net>
@ids1024

ids1024 commented Jan 10, 2024

Copy link
Copy Markdown
Member

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

notgull commented Jan 10, 2024

Copy link
Copy Markdown
Collaborator Author

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

@daxpedda daxpedda left a comment

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.

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

Signed-off-by: John Nunley <dev@notgull.net>
@notgull
notgull requested a review from daxpedda January 11, 2024 02:13
@kpreid

kpreid commented Jan 11, 2024 •

Copy link
Copy Markdown
Contributor

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

notgull commented Jan 11, 2024

Copy link
Copy Markdown
Collaborator Author

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 <dev@notgull.net>

@madsmtm madsmtm left a comment

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.

LGTM after the removal of window_mut

@ids1024

ids1024 commented Jan 12, 2024

Copy link
Copy Markdown
Member

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
@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