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

Implement HasRawWindowHandle trait for win/mac #1586

Merged
merged 5 commits into from
Feb 20, 2021

Conversation

djeedai
Copy link
Contributor

@djeedai djeedai commented Feb 13, 2021

Implement the HasRawWindowHandle trait for Windows and macOS platforms,
to allow access to native window handles for interop.

Implement the HasRawWindowHandle trait for Windows and macOS platforms,
to allow access to native window handles for interop.
RawWindowHandle::Windows(handle)
} else {
panic!("Cannot retrieved HWMD for window.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn’t it HWND

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m not convinced panicking is right for any of these. I think they should return an empty window handle and maybe log a warning. Given that the raw window handle can represent empty handles.

Copy link
Member

Choose a reason for hiding this comment

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

If we're okay with the idea that a RawWindowHandle can potentially be empty then I agree, otherwise we could consider making this an Option<RawWindowHandle>.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an external crate, that is depended on by various things like wgpu and video libraries (and some other gui/rendering libraries). The RawWindowHandles all explicitly have an empty state and consumers have to handle that.

Copy link
Contributor Author

@djeedai djeedai Feb 13, 2021

Choose a reason for hiding this comment

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

Right, typo. Fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a panic! is justified because if we have a WindowHandle without a native HWND I'm assuming we're in serious trouble. Or is there a valid state where that happens?

Copy link
Member

Choose a reason for hiding this comment

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

It might be possible when the window is in the process of being set up or torn down? Elsewhere in the windows backend we log when we can't get the HWND, so I might just keep doing that. 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is better to log. These handles are meant to represent empty states and users of them are expected to handle those states (its better to have an error on screen than a program crash!)

druid-shell/Cargo.toml Outdated Show resolved Hide resolved
@cmyr cmyr added the S-needs-review waits for review label Feb 15, 2021
@cmyr
Copy link
Member

cmyr commented Feb 16, 2021

@rjwittams are you satisfied? feel free to approve & merge if so. :)

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Okay happy to get this in with the panic replaced by a tracing::error!() message.

Is there a reason we don't want to add this for x11 & gtk as well?

@cmyr cmyr added S-waiting-on-author waits for changes from the submitter and removed S-needs-review waits for review labels Feb 17, 2021
@rjwittams
Copy link
Collaborator

rjwittams commented Feb 17, 2021

I am happy too modulo the panics.
I think that at a minimum the other shell platforms should return the appropriate empty handle for that platform and log that it is unimplemented.
This is the pattern we have for other shell features.

@cmyr
Copy link
Member

cmyr commented Feb 17, 2021

I could imagine this just not being implemented on those platforms, since it's defined in a trait, and if you're using a raw window handle I would expect you to be compiling or cfging to a specific platform? But curious to hear if this was a decision or an omission.

@djeedai
Copy link
Contributor Author

djeedai commented Feb 20, 2021

curious to hear if this was a decision or an omission.

This was discussed. I have no access to non-Windows platforms and little knowledge about them, so rather than doing a blind implementation likely to be buggy, implementations on those missing platforms is left for a future change by whoever can contribute it. I did Windows and @rjwittams did macOS.

@rjwittams
Copy link
Collaborator

Looks good. Could you get it up to date with master (should be a quick merge or rebase, whichever you prefer as we'll squash it anyway), as I'm not sure if the log vs tracing changes may confound Githubs 'this is ok to merge' detection...

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Okay I'm also happy once CI is.

Let's open an issue about the missing impl for x11.

@cmyr cmyr merged commit 2da53f0 into linebender:master Feb 20, 2021
@djeedai djeedai deleted the raw-win-handle branch February 20, 2021 20:24
derekdreery pushed a commit to derekdreery/druid that referenced this pull request Apr 6, 2021
* Implement HasRawWindowHandle trait for win/mac

Implement the HasRawWindowHandle trait for Windows and macOS platforms,
to allow access to native window handles for interop.

* Remove libc dependency

* Fix typo in HWND

* Return empty handle and log error on fail

* Fix typo
xarvic pushed a commit to xarvic/druid that referenced this pull request Apr 7, 2021
* Implement HasRawWindowHandle trait for win/mac

Implement the HasRawWindowHandle trait for Windows and macOS platforms,
to allow access to native window handles for interop.

* Remove libc dependency

* Fix typo in HWND

* Return empty handle and log error on fail

* Fix typo
@xStrom xStrom removed the S-waiting-on-author waits for changes from the submitter label Apr 14, 2022
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.

4 participants