mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 20:07:55 +00:00
macos: add option to prompt user for confirmation on OSC 52 commands
This commit is contained in:
@@ -17,6 +17,7 @@ const CoreInspector = @import("../inspector/main.zig").Inspector;
|
||||
const CoreSurface = @import("../Surface.zig");
|
||||
const configpkg = @import("../config.zig");
|
||||
const Config = configpkg.Config;
|
||||
const ClipboardPromptReason = @import("../apprt/structs.zig").ClipboardPromptReason;
|
||||
|
||||
const log = std.log.scoped(.embedded_window);
|
||||
|
||||
@@ -68,10 +69,11 @@ pub const App = struct {
|
||||
SurfaceUD,
|
||||
[*:0]const u8,
|
||||
*apprt.ClipboardRequest,
|
||||
ClipboardPromptReason,
|
||||
) callconv(.C) void,
|
||||
|
||||
/// Write the clipboard value.
|
||||
write_clipboard: *const fn (SurfaceUD, [*:0]const u8, c_int) callconv(.C) void,
|
||||
write_clipboard: *const fn (SurfaceUD, [*:0]const u8, c_int, bool) callconv(.C) void,
|
||||
|
||||
/// Create a new split view. If the embedder doesn't support split
|
||||
/// views then this can be null.
|
||||
@@ -506,7 +508,7 @@ pub const Surface = struct {
|
||||
) void {
|
||||
const alloc = self.app.core_app.alloc;
|
||||
|
||||
// Attempt to complete the request, but if its unsafe we may request
|
||||
// Attempt to complete the request, but we may request
|
||||
// confirmation.
|
||||
self.core_surface.completeClipboardRequest(
|
||||
state.*,
|
||||
@@ -518,6 +520,17 @@ pub const Surface = struct {
|
||||
self.opts.userdata,
|
||||
str.ptr,
|
||||
state,
|
||||
.unsafe,
|
||||
);
|
||||
|
||||
return;
|
||||
},
|
||||
error.UnauthorizedPaste => {
|
||||
self.app.opts.confirm_read_clipboard(
|
||||
self.opts.userdata,
|
||||
str.ptr,
|
||||
state,
|
||||
.read,
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -526,8 +539,8 @@ pub const Surface = struct {
|
||||
else => log.err("error completing clipboard request err={}", .{err}),
|
||||
};
|
||||
|
||||
// We don't defer this because the unsafe paste route preserves
|
||||
// the clipboard request.
|
||||
// We don't defer this because the clipboard confirmation route
|
||||
// preserves the clipboard request.
|
||||
alloc.destroy(state);
|
||||
}
|
||||
|
||||
@@ -535,11 +548,13 @@ pub const Surface = struct {
|
||||
self: *const Surface,
|
||||
val: [:0]const u8,
|
||||
clipboard_type: apprt.Clipboard,
|
||||
confirm: bool,
|
||||
) !void {
|
||||
self.app.opts.write_clipboard(
|
||||
self.opts.userdata,
|
||||
val.ptr,
|
||||
@intCast(@intFromEnum(clipboard_type)),
|
||||
confirm,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -678,7 +678,9 @@ pub const Surface = struct {
|
||||
self: *const Surface,
|
||||
val: [:0]const u8,
|
||||
clipboard_type: apprt.Clipboard,
|
||||
confirm: bool,
|
||||
) !void {
|
||||
_ = confirm;
|
||||
_ = self;
|
||||
switch (clipboard_type) {
|
||||
.standard => glfw.setClipboardString(val),
|
||||
|
||||
@@ -515,7 +515,10 @@ pub fn setClipboardString(
|
||||
self: *const Surface,
|
||||
val: [:0]const u8,
|
||||
clipboard_type: apprt.Clipboard,
|
||||
confirm: bool,
|
||||
) !void {
|
||||
// TODO: implement confirmation dialog when clipboard-write is "ask"
|
||||
_ = confirm;
|
||||
const clipboard = getClipboard(@ptrCast(self.gl_area), clipboard_type);
|
||||
c.gdk_clipboard_set_text(clipboard, val.ptr);
|
||||
}
|
||||
|
||||
@@ -41,3 +41,18 @@ pub const ClipboardRequest = union(enum) {
|
||||
/// A request to write clipboard contents via OSC 52.
|
||||
osc_52: u8,
|
||||
};
|
||||
|
||||
/// The reason for displaying a clipboard prompt to the user
|
||||
pub const ClipboardPromptReason = enum(i32) {
|
||||
/// For pasting data only. Pasted data contains potentially unsafe
|
||||
/// characters
|
||||
unsafe = 1,
|
||||
|
||||
/// The user must authorize the application to read from the clipboard
|
||||
read = 2,
|
||||
|
||||
/// The user must authorize the application to write to the clipboard
|
||||
write = 3,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user