mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-23 12:16:11 +03:00
core: use arrays instead of WriteReq for desktop notifications
This commit is contained in:
@ -722,18 +722,8 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const title: [:0]const u8 = switch (notification.title) {
|
const title = std.mem.sliceTo(¬ification.title, 0);
|
||||||
.small => |v| v.data[0..v.len :0],
|
const body = std.mem.sliceTo(¬ification.body, 0);
|
||||||
// Stream handler only sends small messages
|
|
||||||
else => unreachable,
|
|
||||||
};
|
|
||||||
|
|
||||||
const body: [:0]const u8 = switch (notification.body) {
|
|
||||||
.small => |v| v.data[0..v.len :0],
|
|
||||||
// Stream handler only sends small messages
|
|
||||||
else => unreachable,
|
|
||||||
};
|
|
||||||
|
|
||||||
try self.showDesktopNotification(title, body);
|
try self.showDesktopNotification(title, body);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,10 @@ pub const Message = union(enum) {
|
|||||||
/// Show a desktop notification.
|
/// Show a desktop notification.
|
||||||
desktop_notification: struct {
|
desktop_notification: struct {
|
||||||
/// Desktop notification title.
|
/// Desktop notification title.
|
||||||
title: WriteReq,
|
title: [63:0]u8,
|
||||||
|
|
||||||
/// Desktop notification body.
|
/// Desktop notification body.
|
||||||
body: WriteReq,
|
body: [255:0]u8,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2394,28 +2394,16 @@ const StreamHandler = struct {
|
|||||||
title: []const u8,
|
title: []const u8,
|
||||||
body: []const u8,
|
body: []const u8,
|
||||||
) !void {
|
) !void {
|
||||||
// Subtract one to leave room for the sentinel
|
var message = apprt.surface.Message{ .desktop_notification = undefined };
|
||||||
const max_length = apprt.surface.Message.WriteReq.Small.Max - 1;
|
|
||||||
if (title.len >= max_length or body.len >= max_length) {
|
|
||||||
log.warn("requested notification is too long", .{});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var req_title: apprt.surface.Message.WriteReq.Small = .{};
|
const title_len = @min(title.len, message.desktop_notification.title.len);
|
||||||
@memcpy(req_title.data[0..title.len], title);
|
@memcpy(message.desktop_notification.title[0..title_len], title[0..title_len]);
|
||||||
req_title.data[title.len] = 0;
|
message.desktop_notification.title[title_len] = 0;
|
||||||
req_title.len = @intCast(title.len);
|
|
||||||
|
|
||||||
var req_body: apprt.surface.Message.WriteReq.Small = .{};
|
const body_len = @min(body.len, message.desktop_notification.body.len);
|
||||||
@memcpy(req_body.data[0..body.len], body);
|
@memcpy(message.desktop_notification.body[0..body_len], body[0..body_len]);
|
||||||
req_body.data[body.len] = 0;
|
message.desktop_notification.body[body_len] = 0;
|
||||||
req_body.len = @intCast(body.len);
|
|
||||||
|
|
||||||
_ = self.ev.surface_mailbox.push(.{
|
_ = self.ev.surface_mailbox.push(message, .{ .forever = {} });
|
||||||
.desktop_notification = .{
|
|
||||||
.title = .{ .small = req_title },
|
|
||||||
.body = .{ .small = req_body },
|
|
||||||
},
|
|
||||||
}, .{ .forever = {} });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user