macos: hook up clipboards

This commit is contained in:
Mitchell Hashimoto
2023-02-19 15:18:01 -08:00
parent 8889dd7de2
commit dff45003e1
5 changed files with 73 additions and 13 deletions

View File

@@ -368,6 +368,11 @@ pub const CAPI = struct {
};
}
/// Return the userdata associated with the app.
export fn ghostty_app_userdata(v: *App) ?*anyopaque {
return v.runtime.opts.userdata;
}
export fn ghostty_app_free(ptr: ?*App) void {
if (ptr) |v| {
v.destroy();
@@ -400,6 +405,11 @@ pub const CAPI = struct {
if (ptr) |v| v.app.closeWindow(v);
}
/// Returns the app associated with a surface.
export fn ghostty_surface_app(win: *Window) *App {
return win.app;
}
/// Tell the surface that it needs to schedule a render
export fn ghostty_surface_refresh(win: *Window) void {
win.window.refresh();

View File

@@ -23,15 +23,27 @@ pub const App = struct {
///
/// C type: ghostty_runtime_config_s
pub const Options = extern struct {
/// These are just aliases to make the function signatures below
/// more obvious what values will be sent.
const AppUD = ?*anyopaque;
const SurfaceUD = ?*anyopaque;
/// Userdata that is passed to all the callbacks.
userdata: ?*anyopaque = null,
userdata: AppUD = null,
/// Callback called to wakeup the event loop. This should trigger
/// a full tick of the app loop.
wakeup: *const fn (?*anyopaque) callconv(.C) void,
wakeup: *const fn (AppUD) callconv(.C) void,
/// Called to set the title of the window.
set_title: *const fn (?*anyopaque, [*]const u8) callconv(.C) void,
set_title: *const fn (SurfaceUD, [*]const u8) callconv(.C) void,
/// Read the clipboard value. The return value must be preserved
/// by the host until the next call.
read_clipboard: *const fn (SurfaceUD) callconv(.C) [*:0]const u8,
/// Write the clipboard value.
write_clipboard: *const fn (SurfaceUD, [*:0]const u8) callconv(.C) void,
};
opts: Options,
@@ -114,13 +126,12 @@ pub const Window = struct {
}
pub fn getClipboardString(self: *const Window) ![:0]const u8 {
_ = self;
return "";
const ptr = self.core_win.app.runtime.opts.read_clipboard(self.opts.userdata);
return std.mem.sliceTo(ptr, 0);
}
pub fn setClipboardString(self: *const Window, val: [:0]const u8) !void {
_ = self;
_ = val;
self.core_win.app.runtime.opts.write_clipboard(self.opts.userdata, val.ptr);
}
pub fn setShouldClose(self: *Window) void {