mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
embedded: use separate struct to pass options to new_tab_cb
This commit is contained in:
@ -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_goto_tab_cb)(void *, int32_t);
|
||||
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 {
|
||||
void *userdata;
|
||||
|
@ -65,7 +65,7 @@ extension Ghostty {
|
||||
focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) },
|
||||
goto_tab_cb: { userdata, n in AppState.gotoTab(userdata, n: n) },
|
||||
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.
|
||||
@ -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 }
|
||||
|
||||
var userInfo: [AnyHashable : Any] = [:];
|
||||
if config.font_size != 0 {
|
||||
userInfo[Notification.NewTabKey] = config.font_size as UInt8;
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.ghosttyNewTab,
|
||||
object: surface,
|
||||
userInfo: [
|
||||
Notification.NewTabKey: fontSize,
|
||||
]
|
||||
userInfo: userInfo
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,13 @@ pub const App = struct {
|
||||
/// Toggle fullscreen for current window.
|
||||
toggle_fullscreen: ?*const fn (SurfaceUD, bool) callconv(.C) void = null,
|
||||
|
||||
/// New tab with desired font size in points
|
||||
/// TODO: u8 should be something that's nullable
|
||||
new_tab: ?*const fn (SurfaceUD, u8) callconv(.C) void = null,
|
||||
/// New tab with options.
|
||||
new_tab: ?*const fn (SurfaceUD, apprt.App.NewTabOptions) 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,
|
||||
@ -600,14 +604,16 @@ pub const Surface = struct {
|
||||
return;
|
||||
};
|
||||
|
||||
// TODO: Do we check this here? Or do we check this in embedder?
|
||||
//
|
||||
const font_size: u8 = font_size: {
|
||||
if (!self.app.config.@"window-inherit-font-size") break :font_size 0;
|
||||
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
|
||||
|
Reference in New Issue
Block a user