From dbd0d2396cd62fed8655ddfe5c8bac9eec552d39 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 28 Nov 2025 14:43:39 -0800 Subject: [PATCH] apprt: add new_window_layout action --- include/ghostty.h | 4 ++++ src/apprt/action.zig | 15 +++++++++++++++ src/apprt/layout.zig | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index 6cafe8773..1d3db534f 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -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; diff --git a/src/apprt/action.zig b/src/apprt/action.zig index 00bf8685a..bc8f8a0e6 100644 --- a/src/apprt/action.zig +++ b/src/apprt/action.zig @@ -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) { diff --git a/src/apprt/layout.zig b/src/apprt/layout.zig index eb2d28a49..32c1aa145 100644 --- a/src/apprt/layout.zig +++ b/src/apprt/layout.zig @@ -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.