apprt/embedded: expose C APIs for layouts

layouts
Mitchell Hashimoto 2025-11-28 14:58:58 -08:00
parent dbd0d2396c
commit 781f8c4661
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 43 additions and 5 deletions

View File

@ -30,8 +30,19 @@ typedef void* ghostty_app_t;
typedef void* ghostty_config_t;
typedef void* ghostty_surface_t;
typedef void* ghostty_inspector_t;
typedef void* ghostty_layout_window_t;
typedef void* ghostty_layout_tab_t;
// Layout API
typedef void* ghostty_window_layout_t;
typedef void* ghostty_tab_layout_t;
typedef void* ghostty_tab_layout_leaf_t;
typedef uint16_t ghostty_tab_layout_node_t;
typedef struct {
bool horizontal;
float ratio;
ghostty_tab_layout_node_t left;
ghostty_tab_layout_node_t right;
} ghostty_tab_layout_split_s;
// All the types below are fully defined and must be kept in sync with
// their Zig counterparts. Any changes to these types MUST have an associated
@ -837,7 +848,7 @@ typedef enum {
typedef union {
ghostty_action_split_direction_e new_split;
ghostty_layout_window_t new_window_layout;
ghostty_window_layout_t new_window_layout;
ghostty_action_fullscreen_e toggle_fullscreen;
ghostty_action_move_tab_s move_tab;
ghostty_action_goto_tab_e goto_tab;
@ -1070,6 +1081,19 @@ void ghostty_inspector_metal_render(ghostty_inspector_t, void*, void*);
bool ghostty_inspector_metal_shutdown(ghostty_inspector_t);
#endif
// Layout API
size_t ghostty_window_layout_get_tabs_len(ghostty_window_layout_t);
const ghostty_tab_layout_t* ghostty_window_layout_get_tabs(ghostty_window_layout_t);
bool ghostty_tab_layout_is_empty(ghostty_tab_layout_t);
size_t ghostty_tab_layout_get_nodes_len(ghostty_tab_layout_t);
bool ghostty_tab_layout_is_split_node(ghostty_tab_layout_t, ghostty_tab_layout_node_t);
ghostty_tab_layout_split_s ghostty_tab_layout_get_split_node(ghostty_tab_layout_t,
ghostty_tab_layout_node_t);
ghostty_tab_layout_leaf_t ghostty_tab_layout_get_leaf_node(ghostty_tab_layout_t,
ghostty_tab_layout_node_t);
uint64_t ghostty_tab_layout_leaf_get_id(ghostty_tab_layout_leaf_t);
ghostty_config_t ghostty_tab_layout_leaf_get_config(ghostty_tab_layout_leaf_t);
// APIs I'd like to get rid of eventually but are still needed for now.
// Don't use these unless you know what you're doing.
void ghostty_set_window_background_blur(ghostty_app_t, void*);

View File

@ -20,6 +20,7 @@ const CoreInspector = @import("../inspector/main.zig").Inspector;
const CoreSurface = @import("../Surface.zig");
const configpkg = @import("../config.zig");
const Config = configpkg.Config;
const layout = @import("layout.zig");
const log = std.log.scoped(.embedded_window);
@ -1340,6 +1341,19 @@ pub const CAPI = struct {
}
}
// Layout C API exports
comptime {
@export(&layout.Window.CApi.get_tabs_len, .{ .name = "ghostty_window_layout_get_tabs_len" });
@export(&layout.Window.CApi.get_tabs, .{ .name = "ghostty_window_layout_get_tabs" });
@export(&layout.SplitTree.CApi.is_empty, .{ .name = "ghostty_tab_layout_is_empty" });
@export(&layout.SplitTree.CApi.len, .{ .name = "ghostty_tab_layout_get_nodes_len" });
@export(&layout.SplitTree.CApi.is_split, .{ .name = "ghostty_tab_layout_is_split_node" });
@export(&layout.SplitTree.CApi.get_split, .{ .name = "ghostty_tab_layout_get_split_node" });
@export(&layout.SplitTree.CApi.get_leaf, .{ .name = "ghostty_tab_layout_get_leaf_node" });
@export(&layout.SplitTree.View.CApi.get_id, .{ .name = "ghostty_tab_layout_leaf_get_id" });
@export(&layout.SplitTree.View.CApi.get_config, .{ .name = "ghostty_tab_layout_leaf_get_config" });
}
/// Create a new app.
export fn ghostty_app_new(
opts: *const apprt.runtime.App.Options,

View File

@ -17,7 +17,7 @@ pub const Window = struct {
}
pub fn get_tabs(self: *const Window) callconv(.c) [*]const SplitTree {
return &self.tabs;
return self.tabs.ptr;
}
};
};

View File

@ -1351,7 +1351,7 @@ pub fn SplitTree(comptime V: type) type {
};
}
pub fn get_leaf(self: *const Self, handle: Node.Handle) *View {
pub fn get_leaf(self: *const Self, handle: Node.Handle) callconv(.c) *View {
return self.nodes[handle.idx()].leaf;
}
};