core: support OSC 9 and OSC 777 for showing desktop notifications

This commit is contained in:
Gregory Anders
2023-11-12 09:39:03 -05:00
parent 1deafe34fb
commit 3f4ea2f763
8 changed files with 217 additions and 11 deletions

View File

@@ -117,6 +117,9 @@ pub const App = struct {
/// Called when the cell size changes.
set_cell_size: ?*const fn (SurfaceUD, u32, u32) callconv(.C) void = null,
/// Show a desktop notification to the user.
show_desktop_notification: ?*const fn (SurfaceUD, [*:0]const u8, [*:0]const u8) void = null,
};
/// Special values for the goto_tab callback.
@@ -939,6 +942,20 @@ pub const Surface = struct {
const scale = try self.getContentScale();
return .{ .x = pos.x * scale.x, .y = pos.y * scale.y };
}
/// Show a desktop notification.
pub fn showDesktopNotification(
self: *const Surface,
title: [:0]const u8,
body: [:0]const u8,
) !void {
const func = self.app.opts.show_desktop_notification orelse {
log.info("runtime embedder does not support show_desktop_notification", .{});
return;
};
func(self.opts.userdata, title, body);
}
};
/// Inspector is the state required for the terminal inspector. A terminal

View File

@@ -50,3 +50,13 @@ pub const ClipboardRequest = union(ClipboardRequestType) {
/// A request to write clipboard contents via OSC 52.
osc_52_write: Clipboard,
};
/// A desktop notification.
pub const DesktopNotification = struct {
/// The title of the notification. May be an empty string to not show a
/// title.
title: []const u8,
/// The body of a notification. This will always be shown.
body: []const u8,
};

View File

@@ -45,6 +45,15 @@ pub const Message = union(enum) {
/// The child process running in the surface has exited. This may trigger
/// a surface close, it may not.
child_exited: void,
/// Show a desktop notification.
desktop_notification: struct {
/// Desktop notification title.
title: WriteReq,
/// Desktop notification body.
body: WriteReq,
},
};
/// A surface mailbox.