From 7a0411d65a29660da6ebd7697bd2342b5b637b35 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 25 Feb 2023 10:38:19 -0800 Subject: [PATCH] apprt: move newTab to a surface callback rather than app --- src/App.zig | 32 -------------------------------- src/Surface.zig | 8 +++----- src/apprt/glfw.zig | 7 ++++++- src/apprt/gtk.zig | 9 ++++----- 4 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src/App.zig b/src/App.zig index 683a70f47..77ee6c7d0 100644 --- a/src/App.zig +++ b/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. diff --git a/src/Surface.zig b/src/Surface.zig index aacac1fec..39094766f 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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 => { diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index dbdb925d3..31c117c36 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -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, diff --git a/src/apprt/gtk.zig b/src/apprt/gtk.zig index 2a9483507..51dfb010d 100644 --- a/src/apprt/gtk.zig +++ b/src/apprt/gtk.zig @@ -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); }