Skip to content

Add a handle for views#187

Open
notgull wants to merge 1 commit intomasterfrom
notgull/view
Open

Add a handle for views#187
notgull wants to merge 1 commit intomasterfrom
notgull/view

Conversation

@notgull
Copy link
Member

@notgull notgull commented Feb 14, 2026

This MR adds a handle type specifically for views. "Views" are defined
as sub-areas of windows that graphics APIs can render into. This is
separated from Windows, which may be a key difference for some APIs.

So far this MR only implements views that wrap around windows, and views
that wrap around NSView from AppKit. Discussion must be done to
determine if this is the best way to go about this, as well as if we
should add other views.

Ref: #123

@notgull
Copy link
Member Author

notgull commented Feb 21, 2026

AI: Change name to SurfaceHandle.

This MR adds a handle type specifically for views. "Views" are defined
as sub-areas of windows that graphics APIs can render into. This is
separated from Windows, which may be a key difference for some APIs.

So far this MR only implements views that wrap around windows, and views
that wrap around NSView from AppKit. Discussion must be done to
determine if this is the best way to go about this, as well as if we
should add other views.

Ref: #123
Signed-off-by: John Nunley <dev@notgull.net>
@notgull
Copy link
Member Author

notgull commented Feb 22, 2026

I'm actually wondering if this isn't the right play here. Maybe just having a macOS window handle with a back-pointer to the NSWindow would work, just like how we are currently planning to do Wayland windows.

struct AppkitWindowHandle {
    ns_view: NonNull<c_void>,
    ns_window: Option<NonNull<c_void>>
}

/// [`winit`]: https://crates.io/crates/winit
/// [`sdl2`]: https://crates.io/crates/sdl2
/// [`wgpu`]: https://crates.io/crates/wgpu
/// [`glutin`]: https://crates.io/crates/gl
Copy link
Member

Choose a reason for hiding this comment

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

Glutin and GL are two independent crates

Suggested change
/// [`glutin`]: https://crates.io/crates/gl
/// [`glutin`]: https://crates.io/crates/glutin

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

I think the best way forward with this, would be to change current window handle to SurfaceHandle, and for window handle, have a way to get it from the SurfaceHandle::window_handle(&self) -> WindowHandle?

This thing should be forward compat, I think.

Also, you don't need Window that often, but if you need, you likely need both at the same time, so it's better to have the actual data(pointers, etc) to lay at the same struct and produced together (less change to fail).

Comment on lines +359 to +374
pub enum RawSurfaceHandle {
/// A view that simply represents an entire window.
///
/// This view should be used when you want to render directly into the
/// entire window. In addition, this should be used when there is no
/// meaningful difference between windows and views in the windowing system.
/// For example, in Windows, a `HWND` can correspond to both a view handle
/// as well as a window handle.
Window(RawWindowHandle),

/// A raw view handle for AppKit.
///
/// ## Availability Hints
/// This variant is used on macOS systems.
AppKit(AppKitSurfaceHandle),
}
Copy link
Member

Choose a reason for hiding this comment

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

This thing is technically not forward compat, since if you had e.g. Wayland in Window and with update you made a special variant for that, that won't change the enum and the code will still compile, but it won't work anymore, because the data within enum moved.

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

I think I'd like to wait a bit with this, I'd like to get reference-counting figured out first (#188) (if we haven't figured it out in like 2 weeks, consider this concern resolved).

I also think I agree with Kirill, at least in that I'd rather preserve the WindowHandle we have right now as-is as the surface/view handle, and rather introduce a wrapper on top that is the actual "window" handle.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants