mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-08 14:23:23 +00:00
apprt: add Layout type
This commit is contained in:
@@ -18,6 +18,7 @@ pub const gtk = @import("apprt/gtk.zig");
|
||||
pub const none = @import("apprt/none.zig");
|
||||
pub const browser = @import("apprt/browser.zig");
|
||||
pub const embedded = @import("apprt/embedded.zig");
|
||||
pub const layout = @import("apprt/layout.zig");
|
||||
pub const surface = @import("apprt/surface.zig");
|
||||
|
||||
pub const Action = action.Action;
|
||||
@@ -55,5 +56,6 @@ test {
|
||||
_ = Runtime;
|
||||
_ = runtime;
|
||||
_ = action;
|
||||
_ = layout;
|
||||
_ = structs;
|
||||
}
|
||||
|
||||
56
src/apprt/layout.zig
Normal file
56
src/apprt/layout.zig
Normal file
@@ -0,0 +1,56 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const configpkg = @import("../config.zig");
|
||||
const datastruct = @import("../datastruct/main.zig");
|
||||
|
||||
/// SplitTree represents a desired layout of splits and their associated
|
||||
/// surface configurations. This is used by apprts to launch and modify
|
||||
/// predefined terminal layouts.
|
||||
///
|
||||
/// This only represents a desired split tree; it doesn't represent
|
||||
/// tabs, windows, or any other higher-level constructs. These will
|
||||
/// be represented elsewhere. To start, we only support single-tab
|
||||
/// layouts.
|
||||
pub const SplitTree = datastruct.SplitTree(struct {
|
||||
const View = @This();
|
||||
|
||||
/// A unique identifier for this leaf node. This is guaranteed to
|
||||
/// forever unique and not reused during the lifetime of the
|
||||
/// layout. This allows layouts to change at runtime and the apprt
|
||||
/// to diff them.
|
||||
///
|
||||
/// It is up to the creator of the layout to ensure uniqueness
|
||||
/// when creating or updating layouts.
|
||||
id: u64,
|
||||
|
||||
/// The configuration associated with this leaf node when creating
|
||||
/// the associated terminal surface.
|
||||
config: configpkg.Config,
|
||||
|
||||
/// The reference count for this layout node. When it reaches
|
||||
/// zero it will be freed.
|
||||
refs: usize = 1,
|
||||
|
||||
pub fn ref(self: *View, _: Allocator) Allocator.Error!*View {
|
||||
self.refs += 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn unref(self: *View, alloc: Allocator) void {
|
||||
self.refs -= 1;
|
||||
if (self.refs == 0) {
|
||||
self.config.deinit();
|
||||
alloc.destroy(self);
|
||||
}
|
||||
}
|
||||
|
||||
pub const CApi = struct {
|
||||
pub fn get_id(self: *const View) callconv(.c) u64 {
|
||||
return self.id;
|
||||
}
|
||||
|
||||
pub fn get_config(self: *const View) callconv(.c) *const configpkg.Config {
|
||||
return &self.config;
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user