apprt: move newTab to a surface callback rather than app

This commit is contained in:
Mitchell Hashimoto
2023-02-25 10:38:19 -08:00
parent e4c91d2328
commit 7a0411d65a
4 changed files with 13 additions and 43 deletions

View File

@ -124,7 +124,6 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
log.debug("mailbox message={s}", .{@tagName(message)}); log.debug("mailbox message={s}", .{@tagName(message)});
switch (message) { switch (message) {
.new_window => |msg| try self.newWindow(rt_app, msg), .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), .close => |surface| try self.closeSurface(rt_app, surface),
.quit => try self.setQuit(), .quit => try self.setQuit(),
.surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message), .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); 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 /// Start quitting
fn setQuit(self: *App) !void { fn setQuit(self: *App) !void {
if (self.quit) return; if (self.quit) return;
@ -218,11 +196,6 @@ pub const Message = union(enum) {
/// Create a new terminal window. /// Create a new terminal window.
new_window: NewWindow, 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 /// Close a surface. This notifies the runtime that a surface
/// should close. /// should close.
close: *Surface, close: *Surface,
@ -246,11 +219,6 @@ pub const Message = union(enum) {
/// The parent surface /// The parent surface
parent: ?*Surface = null, parent: ?*Surface = null,
}; };
const NewTab = struct {
/// The parent surface
parent: ?*Surface = null,
};
}; };
/// Mailbox is the way that other threads send the app thread messages. /// Mailbox is the way that other threads send the app thread messages.

View File

@ -910,11 +910,9 @@ pub fn keyCallback(
}, },
.new_tab => { .new_tab => {
_ = self.app_mailbox.push(.{ if (@hasDecl(apprt.Surface, "newTab")) {
.new_tab = .{ try self.rt_surface.newTab();
.parent = self, } else log.warn("runtime doesn't implement newTab", .{});
},
}, .{ .instant = {} });
}, },
.previous_tab => { .previous_tab => {

View File

@ -79,7 +79,7 @@ pub const App = struct {
} }
/// Create a new tab in the parent surface. /// 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) { if (!Darwin.enabled) {
log.warn("tabbing is not supported on this platform", .{}); log.warn("tabbing is not supported on this platform", .{});
return; 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. /// Set the size limits of the window.
/// Note: this interface is not good, we should redo it if we plan /// 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, /// to use this more. i.e. you can't set max width but no max height,

View File

@ -157,11 +157,6 @@ pub const App = struct {
try window.init(self); 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 { fn activate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
_ = app; _ = app;
_ = ud; _ = ud;
@ -584,6 +579,10 @@ pub const Surface = struct {
self.window.closeSurface(self); self.window.closeSurface(self);
} }
pub fn newTab(self: *Surface) !void {
try self.window.newTab();
}
pub fn gotoPreviousTab(self: *Surface) void { pub fn gotoPreviousTab(self: *Surface) void {
self.window.gotoPreviousTab(self); self.window.gotoPreviousTab(self);
} }