Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ghostty.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ GHOSTTY_API ghostty_surface_t ghostty_surface_new(ghostty_app_t,
const ghostty_surface_config_s*);
GHOSTTY_API void ghostty_surface_free(ghostty_surface_t);
GHOSTTY_API void* ghostty_surface_userdata(ghostty_surface_t);
GHOSTTY_API void ghostty_surface_set_userdata(ghostty_surface_t, void*);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The void* parameter type doesn't communicate to C callers that NULL is a valid and meaningful value (it detaches the userdata). The existing getter already returns plain void* without a nullability annotation, so this is consistent — but it's worth noting for embedder documentation. If the project ever adopts _Nullable/_Nonnull annotations (common in Apple SDKs), this parameter would be the natural first candidate.

Suggested change
GHOSTTY_API void ghostty_surface_set_userdata(ghostty_surface_t, void*);
GHOSTTY_API void ghostty_surface_set_userdata(ghostty_surface_t, void* _Nullable);

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

GHOSTTY_API ghostty_app_t ghostty_surface_app(ghostty_surface_t);
GHOSTTY_API ghostty_surface_config_s ghostty_surface_inherited_config(ghostty_surface_t, ghostty_surface_context_e);
GHOSTTY_API void ghostty_surface_update_config(ghostty_surface_t, ghostty_config_t);
Expand Down
11 changes: 11 additions & 0 deletions src/apprt/embedded.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,17 @@ pub const CAPI = struct {
return surface.userdata;
}

/// Sets the userdata associated with the surface.
///
/// Hosts that retain a heap object as the surface userdata must be able to
/// clear it before that object is freed: the surface can outlive the
/// userdata (e.g. a queued mailbox action drains after the host released
/// its callback context), and callbacks would otherwise hand back a
/// dangling pointer. Passing null detaches the userdata.
export fn ghostty_surface_set_userdata(surface: *Surface, userdata: ?*anyopaque) void {
surface.userdata = userdata;
}

/// Returns the app associated with a surface.
export fn ghostty_surface_app(surface: *Surface) *App {
return surface.app;
Expand Down