mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-18 19:11:20 +00:00
core: move clipboard to async process
This commit is contained in:
@@ -547,25 +547,27 @@ pub const Surface = struct {
|
||||
self.window.setInputModeCursor(if (visible) .normal else .hidden);
|
||||
}
|
||||
|
||||
/// Read the clipboard. The windowing system is responsible for allocating
|
||||
/// a buffer as necessary. This should be a stable pointer until the next
|
||||
/// time getClipboardString is called.
|
||||
pub fn getClipboardString(
|
||||
self: *const Surface,
|
||||
/// Start an async clipboard request.
|
||||
pub fn clipboardRequest(
|
||||
self: *Surface,
|
||||
clipboard_type: apprt.Clipboard,
|
||||
) ![:0]const u8 {
|
||||
_ = self;
|
||||
return switch (clipboard_type) {
|
||||
.standard => glfw.getClipboardString() orelse glfw.mustGetErrorCode(),
|
||||
state: apprt.ClipboardRequest,
|
||||
) !void {
|
||||
// GLFW can read clipboards immediately so just do that.
|
||||
const str: []const u8 = switch (clipboard_type) {
|
||||
.standard => glfw.getClipboardString() orelse return glfw.mustGetErrorCode(),
|
||||
.selection => selection: {
|
||||
// Not supported except on Linux
|
||||
if (comptime builtin.os.tag != .linux) return "";
|
||||
if (comptime builtin.os.tag != .linux) break :selection "";
|
||||
|
||||
const raw = glfwNative.getX11SelectionString() orelse
|
||||
return glfw.mustGetErrorCode();
|
||||
break :selection std.mem.span(raw);
|
||||
},
|
||||
};
|
||||
|
||||
// Complete our request
|
||||
try self.core_surface.completeClipboardRequest(state, str);
|
||||
}
|
||||
|
||||
/// Set the clipboard.
|
||||
|
||||
@@ -31,3 +31,13 @@ pub const Clipboard = enum(u1) {
|
||||
standard = 0, // ctrl+c/v
|
||||
selection = 1, // also known as the "primary" clipboard
|
||||
};
|
||||
|
||||
/// Clipboard request. This is used to request clipboard contents and must
|
||||
/// be sent as a response to a ClipboardRequest event.
|
||||
pub const ClipboardRequest = union(enum) {
|
||||
/// A direct paste of clipboard contents.
|
||||
paste: void,
|
||||
|
||||
/// A request to write clipboard contents via OSC 52.
|
||||
osc_52: u8,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user