mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
apprt: move newTab to a surface callback rather than app
This commit is contained in:
32
src/App.zig
32
src/App.zig
@ -124,7 +124,6 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
|
||||
log.debug("mailbox message={s}", .{@tagName(message)});
|
||||
switch (message) {
|
||||
.new_window => |msg| try self.newWindow(rt_app, msg),
|
||||
.new_tab => |msg| try self.newTab(rt_app, msg),
|
||||
.close => |surface| try self.closeSurface(rt_app, surface),
|
||||
.quit => try self.setQuit(),
|
||||
.surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message),
|
||||
@ -160,27 +159,6 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
|
||||
try rt_app.newWindow(parent);
|
||||
}
|
||||
|
||||
/// Create a new tab in the parent window
|
||||
fn newTab(self: *App, rt_app: *apprt.App, msg: Message.NewTab) !void {
|
||||
if (!@hasDecl(apprt.App, "newTab")) {
|
||||
log.warn("newTab is not supported by this runtime", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
const parent = msg.parent orelse {
|
||||
log.warn("parent must be set in new_tab message", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
// If the parent was closed prior to us handling the message, we do nothing.
|
||||
if (!self.hasSurface(parent)) {
|
||||
log.warn("new_tab parent is gone, not launching a new tab", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
try rt_app.newTab(parent);
|
||||
}
|
||||
|
||||
/// Start quitting
|
||||
fn setQuit(self: *App) !void {
|
||||
if (self.quit) return;
|
||||
@ -218,11 +196,6 @@ pub const Message = union(enum) {
|
||||
/// Create a new terminal window.
|
||||
new_window: NewWindow,
|
||||
|
||||
/// Create a new tab within the tab group of the focused window.
|
||||
/// This does nothing if we're on a platform or using a window
|
||||
/// environment that doesn't support tabs.
|
||||
new_tab: NewTab,
|
||||
|
||||
/// Close a surface. This notifies the runtime that a surface
|
||||
/// should close.
|
||||
close: *Surface,
|
||||
@ -246,11 +219,6 @@ pub const Message = union(enum) {
|
||||
/// The parent surface
|
||||
parent: ?*Surface = null,
|
||||
};
|
||||
|
||||
const NewTab = struct {
|
||||
/// The parent surface
|
||||
parent: ?*Surface = null,
|
||||
};
|
||||
};
|
||||
|
||||
/// Mailbox is the way that other threads send the app thread messages.
|
||||
|
@ -910,11 +910,9 @@ pub fn keyCallback(
|
||||
},
|
||||
|
||||
.new_tab => {
|
||||
_ = self.app_mailbox.push(.{
|
||||
.new_tab = .{
|
||||
.parent = self,
|
||||
},
|
||||
}, .{ .instant = {} });
|
||||
if (@hasDecl(apprt.Surface, "newTab")) {
|
||||
try self.rt_surface.newTab();
|
||||
} else log.warn("runtime doesn't implement newTab", .{});
|
||||
},
|
||||
|
||||
.previous_tab => {
|
||||
|
@ -79,7 +79,7 @@ pub const App = struct {
|
||||
}
|
||||
|
||||
/// Create a new tab in the parent surface.
|
||||
pub fn newTab(self: *App, parent: *CoreSurface) !void {
|
||||
fn newTab(self: *App, parent: *CoreSurface) !void {
|
||||
if (!Darwin.enabled) {
|
||||
log.warn("tabbing is not supported on this platform", .{});
|
||||
return;
|
||||
@ -356,6 +356,11 @@ pub const Surface = struct {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new tab in the window containing this surface.
|
||||
pub fn newTab(self: *Surface) !void {
|
||||
try self.app.newTab(&self.core_surface);
|
||||
}
|
||||
|
||||
/// Set the size limits of the window.
|
||||
/// Note: this interface is not good, we should redo it if we plan
|
||||
/// to use this more. i.e. you can't set max width but no max height,
|
||||
|
@ -157,11 +157,6 @@ pub const App = struct {
|
||||
try window.init(self);
|
||||
}
|
||||
|
||||
pub fn newTab(self: *App, parent: *CoreSurface) !void {
|
||||
_ = self;
|
||||
try parent.rt_surface.window.newTab();
|
||||
}
|
||||
|
||||
fn activate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
|
||||
_ = app;
|
||||
_ = ud;
|
||||
@ -584,6 +579,10 @@ pub const Surface = struct {
|
||||
self.window.closeSurface(self);
|
||||
}
|
||||
|
||||
pub fn newTab(self: *Surface) !void {
|
||||
try self.window.newTab();
|
||||
}
|
||||
|
||||
pub fn gotoPreviousTab(self: *Surface) void {
|
||||
self.window.gotoPreviousTab(self);
|
||||
}
|
||||
|
Reference in New Issue
Block a user