embedded: use separate struct to pass options to new_tab_cb

This commit is contained in:
Thorsten Ball
2023-08-18 06:50:47 +02:00
parent 12311e9707
commit cda87a6963
3 changed files with 27 additions and 12 deletions

View File

@ -256,7 +256,12 @@ typedef void (*ghostty_runtime_close_surface_cb)(void *, bool);
typedef void (*ghostty_runtime_focus_split_cb)(void *, ghostty_split_focus_direction_e); typedef void (*ghostty_runtime_focus_split_cb)(void *, ghostty_split_focus_direction_e);
typedef void (*ghostty_runtime_goto_tab_cb)(void *, int32_t); typedef void (*ghostty_runtime_goto_tab_cb)(void *, int32_t);
typedef void (*ghostty_runtime_toggle_fullscreen_cb)(void *, bool); typedef void (*ghostty_runtime_toggle_fullscreen_cb)(void *, bool);
typedef void (*ghostty_runtime_new_tab_cb)(void *, uint8_t);
typedef struct {
uint8_t font_size;
} ghostty_new_tab_config_s;
typedef void (*ghostty_runtime_new_tab_cb)(void *, ghostty_new_tab_config_s);
typedef struct { typedef struct {
void *userdata; void *userdata;

View File

@ -65,7 +65,7 @@ extension Ghostty {
focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) }, focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) },
goto_tab_cb: { userdata, n in AppState.gotoTab(userdata, n: n) }, goto_tab_cb: { userdata, n in AppState.gotoTab(userdata, n: n) },
toggle_fullscreen_cb: { userdata, nonNativeFullscreen in AppState.toggleFullscreen(userdata, useNonNativeFullscreen: nonNativeFullscreen) }, toggle_fullscreen_cb: { userdata, nonNativeFullscreen in AppState.toggleFullscreen(userdata, useNonNativeFullscreen: nonNativeFullscreen) },
new_tab_cb: { userdata, fontSize in AppState.newTab(userdata, fontSize: fontSize) } new_tab_cb: { userdata, newTabConfig in AppState.newTab(userdata, config: newTabConfig) }
) )
// Create the ghostty app. // Create the ghostty app.
@ -263,14 +263,18 @@ extension Ghostty {
) )
} }
static func newTab(_ userdata: UnsafeMutableRawPointer?, fontSize: UInt8) { static func newTab(_ userdata: UnsafeMutableRawPointer?, config: ghostty_new_tab_config_s) {
guard let surface = self.surfaceUserdata(from: userdata) else { return } guard let surface = self.surfaceUserdata(from: userdata) else { return }
var userInfo: [AnyHashable : Any] = [:];
if config.font_size != 0 {
userInfo[Notification.NewTabKey] = config.font_size as UInt8;
}
NotificationCenter.default.post( NotificationCenter.default.post(
name: Notification.ghosttyNewTab, name: Notification.ghosttyNewTab,
object: surface, object: surface,
userInfo: [ userInfo: userInfo
Notification.NewTabKey: fontSize,
]
) )
} }

View File

@ -71,9 +71,13 @@ pub const App = struct {
/// Toggle fullscreen for current window. /// Toggle fullscreen for current window.
toggle_fullscreen: ?*const fn (SurfaceUD, bool) callconv(.C) void = null, toggle_fullscreen: ?*const fn (SurfaceUD, bool) callconv(.C) void = null,
/// New tab with desired font size in points /// New tab with options.
/// TODO: u8 should be something that's nullable new_tab: ?*const fn (SurfaceUD, apprt.App.NewTabOptions) callconv(.C) void = null,
new_tab: ?*const fn (SurfaceUD, u8) callconv(.C) void = null, };
pub const NewTabOptions = extern struct {
/// The font size to inherit. If 0, default font size will be used.
font_size: u8 = 0,
}; };
core_app: *CoreApp, core_app: *CoreApp,
@ -600,14 +604,16 @@ pub const Surface = struct {
return; return;
}; };
// TODO: Do we check this here? Or do we check this in embedder?
//
const font_size: u8 = font_size: { const font_size: u8 = font_size: {
if (!self.app.config.@"window-inherit-font-size") break :font_size 0; if (!self.app.config.@"window-inherit-font-size") break :font_size 0;
break :font_size @intCast(self.core_surface.font_size.points); break :font_size @intCast(self.core_surface.font_size.points);
}; };
func(self.opts.userdata, font_size); const options = apprt.App.NewTabOptions{
.font_size = font_size,
};
func(self.opts.userdata, options);
} }
/// The cursor position from the host directly is in screen coordinates but /// The cursor position from the host directly is in screen coordinates but