rodrigocfd / winsafe

Windows API and GUI in safe, idiomatic Rust.
https://crates.io/crates/winsafe
MIT License
520 stars 30 forks source link

Add support for raw-window-handle #127

Closed notgull closed 6 months ago

notgull commented 6 months ago

It would be nice to be able to use winsafe in things like softbuffer. So it would be nice if it exposed raw-window-handle's HasWindowHandle trait on types like WindowMain. Even if it was an optional feature that would be nice.

rodrigocfd commented 6 months ago

The ptr() method returns the actual pointer to any handle, not just window handles. Conversely, from_ptr() can construct a handle from any pointer. These are the escape hatches to integrate with external libraries.

Aren't these enough?

notgull commented 6 months ago

raw-window-handle has a WindowHandle type, where it is asserted that the window inside is a valid window handle. It has an unsafe constructor to assure this. It would be useful to not have to call this unsafe constructor in my own code.

(Note that one of the conditions for a valid window handle is that is has to belong to the calling thread)

rodrigocfd commented 6 months ago

I understand that some libraries do use raw-window-handle as a dependency, but WinSafe doesn't. So I don't think it's a good idea to add it as dependency just to have an integration – if so, it would be justifiable to add a dependency to every other library in the world.

Interoperation across library boundaries is inherently unsafe. If you don't feel comfortable using unsafe blocks in your project, I suggest you to create an interoperation crate to make the bridge between WinSafe and raw-window-handle. This way the unsafe code would be confined there.