raw-window-handle icon indicating copy to clipboard operation
raw-window-handle copied to clipboard

Add safe constructors for display and window handles

Open notgull opened this issue 1 year ago • 3 comments

There are some DisplayHandle and WindowHandle variants that are completely safe to construct. For instance:

  • Most DisplayHandles are just indicators of the currently running display system and don't involve any borrowed state.
  • An [Xlib/Xcb]DisplayHandle with a display of None can be constructed safely.
  • Win32WindowHandle, [Xlib/Xcb]WindowHandle and WASM web handles involve window IDs with no borrowed state.

It should be possible to construct these safely, with constructors on the safe types.

notgull avatar Nov 13 '23 01:11 notgull

The reason everything in unsafe is forward compat, I guess? Because unsafe -> safe is a breaking change, but not otherwise.

kchibisov avatar Nov 13 '23 01:11 kchibisov

Also, isn't Default basically it?

kchibisov avatar Nov 13 '23 01:11 kchibisov

I was thinking more along these lines:

impl DisplayHandle<'static> {
    pub fn windows() -> Self {
        unsafe { Self::borrow_raw(WindowsDisplayHandle::new().into()) }
    }

    pub fn xlib_no_display() -> Self {
        unsafe { Self::borrow_raw(XlibDisplayHandle::new(None).into()) }
    }
}

Basically, to allow for more ways of creating DisplayHandle and WindowHandle without needing to go through borrow_raw.

notgull avatar Nov 13 '23 02:11 notgull