mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
apprt newWindow/newTab do not have to return a surface
This commit is contained in:
19
src/App.zig
19
src/App.zig
@ -144,14 +144,14 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const window = try rt_app.newWindow();
|
const parent = if (msg.parent) |parent| parent: {
|
||||||
if (self.config.@"window-inherit-font-size") {
|
break :parent if (self.hasSurface(parent))
|
||||||
if (msg.parent) |parent| {
|
parent
|
||||||
if (self.hasSurface(parent)) {
|
else
|
||||||
window.core_surface.setFontSize(parent.font_size);
|
null;
|
||||||
}
|
} else null;
|
||||||
}
|
|
||||||
}
|
try rt_app.newWindow(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new tab in the parent window
|
/// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const window = try rt_app.newTab(parent);
|
try rt_app.newTab(parent);
|
||||||
if (self.config.@"window-inherit-font-size") window.core_surface.setFontSize(parent.font_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start quitting
|
/// Start quitting
|
||||||
|
@ -74,27 +74,19 @@ pub const App = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new window for the app.
|
/// Create a new window for the app.
|
||||||
pub fn newWindow(self: *App) !*Surface {
|
pub fn newWindow(self: *App, parent_: ?*CoreSurface) !void {
|
||||||
// Grab a surface allocation because we're going to need it.
|
_ = try self.newSurface(parent_);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new tab in the parent surface.
|
/// 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) {
|
if (!Darwin.enabled) {
|
||||||
log.warn("tabbing is not supported on this platform", .{});
|
log.warn("tabbing is not supported on this platform", .{});
|
||||||
return error.TabbingNotSupported;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the new window
|
// Create the new window
|
||||||
const window = try self.newWindow();
|
const window = try self.newWindow(parent);
|
||||||
|
|
||||||
// Add the new window the parent window
|
// Add the new window the parent window
|
||||||
const parent_win = glfwNative.getCocoaWindow(parent.rt_surface.window).?;
|
const parent_win = glfwNative.getCocoaWindow(parent.rt_surface.window).?;
|
||||||
@ -112,14 +104,31 @@ pub const App = struct {
|
|||||||
// point in the grid.
|
// point in the grid.
|
||||||
const size = parent.rt_surface.getSize() catch |err| {
|
const size = parent.rt_surface.getSize() catch |err| {
|
||||||
log.err("error querying window size for size callback on new tab err={}", .{err});
|
log.err("error querying window size for size callback on new tab err={}", .{err});
|
||||||
return window;
|
return;
|
||||||
};
|
};
|
||||||
parent.sizeCallback(size) catch |err| {
|
parent.sizeCallback(size) catch |err| {
|
||||||
log.err("error in size callback from new tab err={}", .{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.
|
/// Close the given surface.
|
||||||
|
@ -99,7 +99,7 @@ pub fn main() !void {
|
|||||||
defer app_runtime.terminate();
|
defer app_runtime.terminate();
|
||||||
|
|
||||||
// Create an initial window
|
// Create an initial window
|
||||||
_ = try app_runtime.newWindow();
|
try app_runtime.newWindow(null);
|
||||||
|
|
||||||
// Run the GUI event loop
|
// Run the GUI event loop
|
||||||
try app_runtime.run();
|
try app_runtime.run();
|
||||||
|
Reference in New Issue
Block a user