apprt newWindow/newTab do not have to return a surface

This commit is contained in:
Mitchell Hashimoto
2023-02-23 08:44:01 -08:00
parent 153004eb6f
commit fb13838532
3 changed files with 35 additions and 27 deletions

View File

@ -144,14 +144,14 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
return;
}
const window = try rt_app.newWindow();
if (self.config.@"window-inherit-font-size") {
if (msg.parent) |parent| {
if (self.hasSurface(parent)) {
window.core_surface.setFontSize(parent.font_size);
}
}
}
const parent = if (msg.parent) |parent| parent: {
break :parent if (self.hasSurface(parent))
parent
else
null;
} else null;
try rt_app.newWindow(parent);
}
/// Create a new tab in the parent window
@ -172,8 +172,7 @@ fn newTab(self: *App, rt_app: *apprt.App, msg: Message.NewTab) !void {
return;
}
const window = try rt_app.newTab(parent);
if (self.config.@"window-inherit-font-size") window.core_surface.setFontSize(parent.font_size);
try rt_app.newTab(parent);
}
/// Start quitting

View File

@ -74,27 +74,19 @@ pub const App = struct {
}
/// Create a new window for the app.
pub fn newWindow(self: *App) !*Surface {
// Grab a surface allocation because we're going to need it.
var surface = try self.app.alloc.create(Surface);
errdefer self.app.alloc.destroy(surface);
// Create the surface -- because windows are surfaces for glfw.
try surface.init(self);
errdefer surface.deinit();
return surface;
pub fn newWindow(self: *App, parent_: ?*CoreSurface) !void {
_ = try self.newSurface(parent_);
}
/// Create a new tab in the parent surface.
pub fn newTab(self: *App, parent: *CoreSurface) !*Surface {
pub fn newTab(self: *App, parent: *CoreSurface) !void {
if (!Darwin.enabled) {
log.warn("tabbing is not supported on this platform", .{});
return error.TabbingNotSupported;
return;
}
// Create the new window
const window = try self.newWindow();
const window = try self.newWindow(parent);
// Add the new window the parent window
const parent_win = glfwNative.getCocoaWindow(parent.rt_surface.window).?;
@ -112,14 +104,31 @@ pub const App = struct {
// point in the grid.
const size = parent.rt_surface.getSize() catch |err| {
log.err("error querying window size for size callback on new tab err={}", .{err});
return window;
return;
};
parent.sizeCallback(size) catch |err| {
log.err("error in size callback from new tab err={}", .{err});
return window;
return;
};
}
return window;
fn newSurface(self: *App, parent_: ?*CoreSurface) !*Surface {
// Grab a surface allocation because we're going to need it.
var surface = try self.app.alloc.create(Surface);
errdefer self.app.alloc.destroy(surface);
// Create the surface -- because windows are surfaces for glfw.
try surface.init(self);
errdefer surface.deinit();
// If we have a parent, inherit some properties
if (self.app.config.@"window-inherit-font-size") {
if (parent_) |parent| {
surface.core_surface.setFontSize(parent.font_size);
}
}
return surface;
}
/// Close the given surface.

View File

@ -99,7 +99,7 @@ pub fn main() !void {
defer app_runtime.terminate();
// Create an initial window
_ = try app_runtime.newWindow();
try app_runtime.newWindow(null);
// Run the GUI event loop
try app_runtime.run();