mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #435 from mitchellh/app-mailbox
core: surface should not use app mailbox
This commit is contained in:
22
src/App.zig
22
src/App.zig
@ -199,8 +199,7 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
|
|||||||
switch (message) {
|
switch (message) {
|
||||||
.reload_config => try self.reloadConfig(rt_app),
|
.reload_config => try self.reloadConfig(rt_app),
|
||||||
.new_window => |msg| try self.newWindow(rt_app, msg),
|
.new_window => |msg| try self.newWindow(rt_app, msg),
|
||||||
.close => |surface| try self.closeSurface(rt_app, surface),
|
.close => |surface| try self.closeSurface(surface),
|
||||||
.focus => |surface| try self.focusSurface(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),
|
||||||
.redraw_surface => |surface| try self.redrawSurface(rt_app, surface),
|
.redraw_surface => |surface| try self.redrawSurface(rt_app, surface),
|
||||||
@ -208,7 +207,7 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reloadConfig(self: *App, rt_app: *apprt.App) !void {
|
pub fn reloadConfig(self: *App, rt_app: *apprt.App) !void {
|
||||||
log.debug("reloading configuration", .{});
|
log.debug("reloading configuration", .{});
|
||||||
if (try rt_app.reloadConfig()) |new| {
|
if (try rt_app.reloadConfig()) |new| {
|
||||||
log.debug("new configuration received, applying", .{});
|
log.debug("new configuration received, applying", .{});
|
||||||
@ -216,16 +215,12 @@ fn reloadConfig(self: *App, rt_app: *apprt.App) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn closeSurface(self: *App, rt_app: *apprt.App, surface: *Surface) !void {
|
pub fn closeSurface(self: *App, surface: *Surface) !void {
|
||||||
_ = rt_app;
|
|
||||||
|
|
||||||
if (!self.hasSurface(surface)) return;
|
if (!self.hasSurface(surface)) return;
|
||||||
surface.close();
|
surface.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focusSurface(self: *App, rt_app: *apprt.App, surface: *Surface) !void {
|
pub fn focusSurface(self: *App, surface: *Surface) void {
|
||||||
_ = rt_app;
|
|
||||||
|
|
||||||
if (!self.hasSurface(surface)) return;
|
if (!self.hasSurface(surface)) return;
|
||||||
self.focused_surface = surface;
|
self.focused_surface = surface;
|
||||||
}
|
}
|
||||||
@ -236,7 +231,7 @@ fn redrawSurface(self: *App, rt_app: *apprt.App, surface: *apprt.Surface) !void
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new window
|
/// Create a new window
|
||||||
fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
|
pub fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
|
||||||
if (!@hasDecl(apprt.App, "newWindow")) {
|
if (!@hasDecl(apprt.App, "newWindow")) {
|
||||||
log.warn("newWindow is not supported by this runtime", .{});
|
log.warn("newWindow is not supported by this runtime", .{});
|
||||||
return;
|
return;
|
||||||
@ -253,7 +248,7 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start quitting
|
/// Start quitting
|
||||||
fn setQuit(self: *App) !void {
|
pub fn setQuit(self: *App) !void {
|
||||||
if (self.quit) return;
|
if (self.quit) return;
|
||||||
self.quit = true;
|
self.quit = true;
|
||||||
}
|
}
|
||||||
@ -292,11 +287,6 @@ pub const Message = union(enum) {
|
|||||||
/// should close.
|
/// should close.
|
||||||
close: *Surface,
|
close: *Surface,
|
||||||
|
|
||||||
/// The last focused surface. The app keeps track of this to
|
|
||||||
/// enable "inheriting" various configurations from the last
|
|
||||||
/// surface.
|
|
||||||
focus: *Surface,
|
|
||||||
|
|
||||||
/// Quit
|
/// Quit
|
||||||
quit: void,
|
quit: void,
|
||||||
|
|
||||||
|
@ -42,10 +42,11 @@ const Renderer = renderer.Renderer;
|
|||||||
/// Allocator
|
/// Allocator
|
||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
|
|
||||||
/// The mailbox for sending messages to the main app thread.
|
/// The app that this surface is attached to.
|
||||||
app_mailbox: App.Mailbox,
|
app: *App,
|
||||||
|
|
||||||
/// The windowing system surface
|
/// The windowing system surface and app.
|
||||||
|
rt_app: *apprt.runtime.App,
|
||||||
rt_surface: *apprt.runtime.Surface,
|
rt_surface: *apprt.runtime.Surface,
|
||||||
|
|
||||||
/// The font structures
|
/// The font structures
|
||||||
@ -180,7 +181,7 @@ pub fn init(
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
config: *const configpkg.Config,
|
config: *const configpkg.Config,
|
||||||
app: *App,
|
app: *App,
|
||||||
app_mailbox: App.Mailbox,
|
rt_app: *apprt.runtime.App,
|
||||||
rt_surface: *apprt.runtime.Surface,
|
rt_surface: *apprt.runtime.Surface,
|
||||||
) !void {
|
) !void {
|
||||||
// Initialize our renderer with our initialized surface.
|
// Initialize our renderer with our initialized surface.
|
||||||
@ -351,6 +352,7 @@ pub fn init(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create our terminal grid with the initial size
|
// Create our terminal grid with the initial size
|
||||||
|
const app_mailbox: App.Mailbox = .{ .rt_app = rt_app, .mailbox = &app.mailbox };
|
||||||
var renderer_impl = try Renderer.init(alloc, .{
|
var renderer_impl = try Renderer.init(alloc, .{
|
||||||
.config = try Renderer.DerivedConfig.init(alloc, config),
|
.config = try Renderer.DerivedConfig.init(alloc, config),
|
||||||
.font_group = font_group,
|
.font_group = font_group,
|
||||||
@ -409,7 +411,8 @@ pub fn init(
|
|||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.app_mailbox = app_mailbox,
|
.app = app,
|
||||||
|
.rt_app = rt_app,
|
||||||
.rt_surface = rt_surface,
|
.rt_surface = rt_surface,
|
||||||
.font_lib = font_lib,
|
.font_lib = font_lib,
|
||||||
.font_group = font_group,
|
.font_group = font_group,
|
||||||
@ -1019,11 +1022,7 @@ pub fn focusCallback(self: *Surface, focused: bool) !void {
|
|||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
|
|
||||||
// Notify our app if we gained focus.
|
// Notify our app if we gained focus.
|
||||||
if (focused) {
|
if (focused) self.app.focusSurface(self);
|
||||||
_ = self.app_mailbox.push(.{
|
|
||||||
.focus = self,
|
|
||||||
}, .{ .forever = {} });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schedule render which also drains our mailbox
|
// Schedule render which also drains our mailbox
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
@ -1871,11 +1870,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
|
|||||||
.unbind => unreachable,
|
.unbind => unreachable,
|
||||||
.ignore => {},
|
.ignore => {},
|
||||||
|
|
||||||
.reload_config => {
|
.reload_config => try self.app.reloadConfig(self.rt_app),
|
||||||
_ = self.app_mailbox.push(.{
|
|
||||||
.reload_config = {},
|
|
||||||
}, .{ .instant = {} });
|
|
||||||
},
|
|
||||||
|
|
||||||
.csi => |data| {
|
.csi => |data| {
|
||||||
// We need to send the CSI sequence as a single write request.
|
// We need to send the CSI sequence as a single write request.
|
||||||
@ -2072,13 +2067,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
|
|||||||
try self.io_thread.wakeup.notify();
|
try self.io_thread.wakeup.notify();
|
||||||
},
|
},
|
||||||
|
|
||||||
.new_window => {
|
.new_window => try self.app.newWindow(self.rt_app, .{ .parent = self }),
|
||||||
_ = self.app_mailbox.push(.{
|
|
||||||
.new_window = .{
|
|
||||||
.parent = self,
|
|
||||||
},
|
|
||||||
}, .{ .instant = {} });
|
|
||||||
},
|
|
||||||
|
|
||||||
.new_tab => {
|
.new_tab => {
|
||||||
if (@hasDecl(apprt.Surface, "newTab")) {
|
if (@hasDecl(apprt.Surface, "newTab")) {
|
||||||
@ -2130,15 +2119,9 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
|
|||||||
|
|
||||||
.close_surface => self.close(),
|
.close_surface => self.close(),
|
||||||
|
|
||||||
.close_window => {
|
.close_window => try self.app.closeSurface(self),
|
||||||
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
|
||||||
},
|
|
||||||
|
|
||||||
.quit => {
|
.quit => try self.app.setQuit(),
|
||||||
_ = self.app_mailbox.push(.{
|
|
||||||
.quit = {},
|
|
||||||
}, .{ .instant = {} });
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ pub const Surface = struct {
|
|||||||
app.core_app.alloc,
|
app.core_app.alloc,
|
||||||
&config,
|
&config,
|
||||||
app.core_app,
|
app.core_app,
|
||||||
.{ .rt_app = app, .mailbox = &app.core_app.mailbox },
|
app,
|
||||||
self,
|
self,
|
||||||
);
|
);
|
||||||
errdefer self.core_surface.deinit();
|
errdefer self.core_surface.deinit();
|
||||||
|
@ -378,7 +378,7 @@ pub const Surface = struct {
|
|||||||
app.app.alloc,
|
app.app.alloc,
|
||||||
&config,
|
&config,
|
||||||
app.app,
|
app.app,
|
||||||
.{ .rt_app = app, .mailbox = &app.app.mailbox },
|
app,
|
||||||
self,
|
self,
|
||||||
);
|
);
|
||||||
errdefer self.core_surface.deinit();
|
errdefer self.core_surface.deinit();
|
||||||
|
@ -852,7 +852,7 @@ pub const Surface = struct {
|
|||||||
self.app.core_app.alloc,
|
self.app.core_app.alloc,
|
||||||
&config,
|
&config,
|
||||||
self.app.core_app,
|
self.app.core_app,
|
||||||
.{ .rt_app = self.app, .mailbox = &self.app.core_app.mailbox },
|
self.app,
|
||||||
self,
|
self,
|
||||||
);
|
);
|
||||||
errdefer self.core_surface.deinit();
|
errdefer self.core_surface.deinit();
|
||||||
|
Reference in New Issue
Block a user