Add hook system.
This commit is contained in:
@@ -52,11 +52,18 @@ on_exit: *const fn (ctx: ?*anyopaque) void,
|
||||
/// Called when this terminal takes keyboard focus.
|
||||
on_focus: *const fn (ctx: ?*anyopaque) void,
|
||||
|
||||
/// Called when the child reports a change of state, so the owner can show
|
||||
/// it in the tab strip.
|
||||
on_status: *const fn (ctx: ?*anyopaque, status: Status) void,
|
||||
|
||||
ctx: ?*anyopaque = null,
|
||||
|
||||
/// What a layout can specify for a terminal pane.
|
||||
pub const Options = Session.Options;
|
||||
|
||||
/// What the child is doing. Reported by the session; passed straight through.
|
||||
pub const Status = Session.Status;
|
||||
|
||||
pub fn create(
|
||||
alloc: std.mem.Allocator,
|
||||
opts: Options,
|
||||
@@ -76,6 +83,7 @@ pub fn create(
|
||||
.on_title = cbs.on_title,
|
||||
.on_exit = cbs.on_exit,
|
||||
.on_focus = cbs.on_focus,
|
||||
.on_status = cbs.on_status,
|
||||
.ctx = cbs.ctx,
|
||||
};
|
||||
|
||||
@@ -87,6 +95,7 @@ pub fn create(
|
||||
.on_damage = &onDamage,
|
||||
.on_title = &onSessionTitle,
|
||||
.on_exit = &onSessionExit,
|
||||
.on_status = &onSessionStatus,
|
||||
.ctx = self,
|
||||
});
|
||||
errdefer self.session.destroy();
|
||||
@@ -189,6 +198,11 @@ fn onSessionTitle(ctx: ?*anyopaque, title: []const u8) void {
|
||||
self.on_title(self.ctx, title);
|
||||
}
|
||||
|
||||
fn onSessionStatus(ctx: ?*anyopaque, status: Status) void {
|
||||
const self: *Terminal = @ptrCast(@alignCast(ctx.?));
|
||||
self.on_status(self.ctx, status);
|
||||
}
|
||||
|
||||
fn onNotifyHasFocus(
|
||||
_: *gtk.DrawingArea,
|
||||
_: *gobject.ParamSpec,
|
||||
|
||||
Reference in New Issue
Block a user