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 safe constructors for display and window handles #156

Open
notgull opened this issue Nov 13, 2023 · 3 comments
Open

Add safe constructors for display and window handles #156

notgull opened this issue Nov 13, 2023 · 3 comments

Comments

@notgull
Copy link
Member

notgull commented Nov 13, 2023

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.

@kchibisov
Copy link
Member

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

@kchibisov
Copy link
Member

Also, isn't Default basically it?

@notgull
Copy link
Member Author

notgull commented Nov 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants