apprt: add new_window_layout action

layouts
Mitchell Hashimoto 2025-11-28 14:43:39 -08:00
parent 2f78a6d97b
commit dbd0d2396c
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 38 additions and 0 deletions

View File

@ -30,6 +30,8 @@ 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;
// 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
@ -776,6 +778,7 @@ typedef enum {
GHOSTTY_ACTION_NEW_TAB,
GHOSTTY_ACTION_CLOSE_TAB,
GHOSTTY_ACTION_NEW_SPLIT,
GHOSTTY_ACTION_NEW_WINDOW_LAYOUT,
GHOSTTY_ACTION_CLOSE_ALL_WINDOWS,
GHOSTTY_ACTION_TOGGLE_MAXIMIZE,
GHOSTTY_ACTION_TOGGLE_FULLSCREEN,
@ -834,6 +837,7 @@ typedef enum {
typedef union {
ghostty_action_split_direction_e new_split;
ghostty_layout_window_t new_window_layout;
ghostty_action_fullscreen_e toggle_fullscreen;
ghostty_action_move_tab_s move_tab;
ghostty_action_goto_tab_e goto_tab;

View File

@ -91,6 +91,9 @@ pub const Action = union(Key) {
/// relative to the target.
new_split: SplitDirection,
/// Create a new window, tab, etc. as necessary to apply the given layout.
new_window_layout: Layout,
/// Close all open windows.
close_all_windows,
@ -320,6 +323,7 @@ pub const Action = union(Key) {
new_tab,
close_tab,
new_split,
new_window_layout,
close_all_windows,
toggle_maximize,
toggle_fullscreen,
@ -448,6 +452,17 @@ pub const Action = union(Key) {
}
};
// See apprt.layout
pub const Layout = struct {
window: apprt.layout.Window,
pub const C = *const apprt.layout.Window;
pub fn cval(self: *const Layout) C {
return &self.window;
}
};
// This is made extern (c_int) to make interop easier with our embedded
// runtime. The small size cost doesn't make a difference in our union.
pub const SplitDirection = enum(c_int) {

View File

@ -3,6 +3,25 @@ const Allocator = std.mem.Allocator;
const configpkg = @import("../config.zig");
const datastruct = @import("../datastruct/main.zig");
/// Window represents a desired predefined layout for a window hierarchy:
/// a set of tabs, each with their own split tree.
pub const Window = struct {
/// NOTE: For now, we guarantee tabs.len == 1. This is to simplify
/// the initial implementation. In the future we will support layouts
/// for multiple tabs.
tabs: []const SplitTree,
pub const CApi = struct {
pub fn get_tabs_len(self: *const Window) callconv(.c) usize {
return self.tabs.len;
}
pub fn get_tabs(self: *const Window) callconv(.c) [*]const SplitTree {
return &self.tabs;
}
};
};
/// SplitTree represents a desired layout of splits and their associated
/// surface configurations. This is used by apprts to launch and modify
/// predefined terminal layouts.