Change Window
from a borrowed handle to a weakly owned handle
#174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the idea discussed with @glowcoil on Discord a few days ago, which is to make the
Window
handle'static
and clone-able, so that it can be easily stored in theWindowHandler
.Note this PR is based on #172 for now, which is why the new example shows up in the diff. This can be changed depending on #172's merge status.This has been properly rebased now.This makes the following breaking API changes, for all platforms and backends:
Window
type.Window
type is now an owned, weak handle to the actual underlying window.Window
type clone-able.Window
argument passed to theWindowHandler
builder is now a fully owned value instead of a temporary borrow, which enables the handler to store it for its whole lifetime.Window
argument onWindowHandler::on_frame
andWindowHandler::on_event
methods.Window
methods now only take&self
instead of&mut self
.Window
methods are now internally fallible: they will panic if the actual window the handle points to has been destroyed. This can only happen if theWindowHandler
misbehaves and clones theWindow
outside of its own lifetime.GlContext
has received the same treatment, for the same reasons: it's now a weak, owned clone-able handle to the GL context of a window, and its methods will also panic if the underlying context is destroyed.As of now, this PR is still a WIP:
The X11 backend is complete and functional, but it will probably need to be rebased on top of Switch from xcb crate to x11rb #173 before this PR can be merged.It's done!I started working on the Win32 backend, but it's not done yet.Done!I haven't touched the Cocoa backend, and it will not build at all at the moment.Done, but still needs testing.As of now, this PR will not build on macOS or Windows until I've completed the work mentioned above.