mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
termio: close surface on process exit
This commit is contained in:
@ -479,6 +479,14 @@ pub fn deinit(self: *Surface) void {
|
|||||||
log.info("surface closed addr={x}", .{@ptrToInt(self)});
|
log.info("surface closed addr={x}", .{@ptrToInt(self)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close this surface. This will trigger the runtime to start the
|
||||||
|
/// close process, which should ultimately deinitialize this surface.
|
||||||
|
pub fn close(self: *Surface) void {
|
||||||
|
if (@hasDecl(apprt.Surface, "closeSurface")) {
|
||||||
|
try self.rt_surface.closeSurface();
|
||||||
|
} else log.warn("runtime doesn't implement closeSurface", .{});
|
||||||
|
}
|
||||||
|
|
||||||
/// Called from the app thread to handle mailbox messages to our specific
|
/// Called from the app thread to handle mailbox messages to our specific
|
||||||
/// surface.
|
/// surface.
|
||||||
pub fn handleMessage(self: *Surface, msg: Message) !void {
|
pub fn handleMessage(self: *Surface, msg: Message) !void {
|
||||||
@ -503,6 +511,8 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
|||||||
try self.clipboardWrite(v.data);
|
try self.clipboardWrite(v.data);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.close => self.close(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,11 +963,7 @@ pub fn keyCallback(
|
|||||||
} else log.warn("runtime doesn't implement gotoSplit", .{});
|
} else log.warn("runtime doesn't implement gotoSplit", .{});
|
||||||
},
|
},
|
||||||
|
|
||||||
.close_surface => {
|
.close_surface => self.close(),
|
||||||
if (@hasDecl(apprt.Surface, "closeSurface")) {
|
|
||||||
try self.rt_surface.closeSurface();
|
|
||||||
} else log.warn("runtime doesn't implement closeSurface", .{});
|
|
||||||
},
|
|
||||||
|
|
||||||
.close_window => {
|
.close_window => {
|
||||||
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
||||||
|
@ -23,6 +23,10 @@ pub const Message = union(enum) {
|
|||||||
|
|
||||||
/// Write the clipboard contents.
|
/// Write the clipboard contents.
|
||||||
clipboard_write: WriteReq,
|
clipboard_write: WriteReq,
|
||||||
|
|
||||||
|
/// Close the surface. This will only close the current surface that
|
||||||
|
/// receives this, not the full application.
|
||||||
|
close: void,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A surface mailbox.
|
/// A surface mailbox.
|
||||||
|
@ -130,6 +130,7 @@ pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
|
|||||||
ev_data_ptr.* = .{
|
ev_data_ptr.* = .{
|
||||||
.writer_mailbox = thread.mailbox,
|
.writer_mailbox = thread.mailbox,
|
||||||
.writer_wakeup = thread.wakeup,
|
.writer_wakeup = thread.wakeup,
|
||||||
|
.surface_mailbox = self.surface_mailbox,
|
||||||
.renderer_state = self.renderer_state,
|
.renderer_state = self.renderer_state,
|
||||||
.renderer_wakeup = self.renderer_wakeup,
|
.renderer_wakeup = self.renderer_wakeup,
|
||||||
.renderer_mailbox = self.renderer_mailbox,
|
.renderer_mailbox = self.renderer_mailbox,
|
||||||
@ -142,7 +143,6 @@ pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
|
|||||||
.ev = ev_data_ptr,
|
.ev = ev_data_ptr,
|
||||||
.terminal = &self.terminal,
|
.terminal = &self.terminal,
|
||||||
.grid_size = &self.grid_size,
|
.grid_size = &self.grid_size,
|
||||||
.surface_mailbox = self.surface_mailbox,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -277,6 +277,9 @@ const EventData = struct {
|
|||||||
writer_mailbox: *termio.Mailbox,
|
writer_mailbox: *termio.Mailbox,
|
||||||
writer_wakeup: xev.Async,
|
writer_wakeup: xev.Async,
|
||||||
|
|
||||||
|
/// Mailbox for the surface.
|
||||||
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
/// The stream parser. This parses the stream of escape codes and so on
|
/// The stream parser. This parses the stream of escape codes and so on
|
||||||
/// from the child process and calls callbacks in the stream handler.
|
/// from the child process and calls callbacks in the stream handler.
|
||||||
terminal_stream: terminal.Stream(StreamHandler),
|
terminal_stream: terminal.Stream(StreamHandler),
|
||||||
@ -354,6 +357,11 @@ fn processExit(
|
|||||||
ev.process_exited = true;
|
ev.process_exited = true;
|
||||||
ev.data_stream.close(loop, completion, EventData, ev, ttyClose);
|
ev.data_stream.close(loop, completion, EventData, ev, ttyClose);
|
||||||
|
|
||||||
|
// Notify our surface we want to close
|
||||||
|
_ = ev.surface_mailbox.push(.{
|
||||||
|
.close = {},
|
||||||
|
}, .{ .forever = {} });
|
||||||
|
|
||||||
return .disarm;
|
return .disarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +828,6 @@ const StreamHandler = struct {
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
grid_size: *renderer.GridSize,
|
grid_size: *renderer.GridSize,
|
||||||
terminal: *terminal.Terminal,
|
terminal: *terminal.Terminal,
|
||||||
surface_mailbox: apprt.surface.Mailbox,
|
|
||||||
|
|
||||||
/// This is set to true when a message was written to the writer
|
/// This is set to true when a message was written to the writer
|
||||||
/// mailbox. This can be used by callers to determine if they need
|
/// mailbox. This can be used by callers to determine if they need
|
||||||
@ -1167,7 +1174,7 @@ const StreamHandler = struct {
|
|||||||
std.mem.copy(u8, &buf, title);
|
std.mem.copy(u8, &buf, title);
|
||||||
buf[title.len] = 0;
|
buf[title.len] = 0;
|
||||||
|
|
||||||
_ = self.surface_mailbox.push(.{
|
_ = self.ev.surface_mailbox.push(.{
|
||||||
.set_title = buf,
|
.set_title = buf,
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
}
|
}
|
||||||
@ -1179,14 +1186,14 @@ const StreamHandler = struct {
|
|||||||
|
|
||||||
// Get clipboard contents
|
// Get clipboard contents
|
||||||
if (data.len == 1 and data[0] == '?') {
|
if (data.len == 1 and data[0] == '?') {
|
||||||
_ = self.surface_mailbox.push(.{
|
_ = self.ev.surface_mailbox.push(.{
|
||||||
.clipboard_read = kind,
|
.clipboard_read = kind,
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write clipboard contents
|
// Write clipboard contents
|
||||||
_ = self.surface_mailbox.push(.{
|
_ = self.ev.surface_mailbox.push(.{
|
||||||
.clipboard_write = try apprt.surface.Message.WriteReq.init(
|
.clipboard_write = try apprt.surface.Message.WriteReq.init(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
data,
|
data,
|
||||||
|
Reference in New Issue
Block a user