From 5290070be938ae745b706f81871155604220e8b0 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Thu, 16 Nov 2023 16:35:48 -0600 Subject: [PATCH] clipboard: add Clipboard variant for primary clipboard In practice, the primary and selection clipboards are treated exactly the same, but this allows OSC 52 sequences to use either 's' or 'p' as the clipboard target. --- src/Surface.zig | 1 + src/apprt/embedded.zig | 2 +- src/apprt/glfw.zig | 4 ++-- src/apprt/gtk/Surface.zig | 2 +- src/apprt/structs.zig | 5 +++-- src/termio/Exec.zig | 1 + 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 13c5c6873..0c7783df9 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2727,6 +2727,7 @@ fn completeClipboardReadOSC52( const kind: u8 = switch (clipboard_type) { .standard => 'c', .selection => 's', + .primary => 'p', }; // Wrap our data with the OSC code diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index a62bab5db..cf2a2dc15 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -474,7 +474,7 @@ pub const Surface = struct { ) bool { return switch (clipboard_type) { .standard => true, - .selection => self.app.opts.supports_selection_clipboard, + .selection, .primary => self.app.opts.supports_selection_clipboard, }; } diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index a4178dfb5..53cd31c1d 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -658,7 +658,7 @@ pub const Surface = struct { // GLFW can read clipboards immediately so just do that. const str: [:0]const u8 = switch (clipboard_type) { .standard => glfw.getClipboardString() orelse return glfw.mustGetErrorCode(), - .selection => selection: { + .selection, .primary => selection: { // Not supported except on Linux if (comptime builtin.os.tag != .linux) break :selection ""; @@ -684,7 +684,7 @@ pub const Surface = struct { _ = self; switch (clipboard_type) { .standard => glfw.setClipboardString(val), - .selection => { + .selection, .primary => { // Not supported except on Linux if (comptime builtin.os.tag != .linux) return; glfwNative.setX11SelectionString(val.ptr); diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index dadb8b7d8..5a7b2da0b 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -589,7 +589,7 @@ fn gtkClipboardRead( fn getClipboard(widget: *c.GtkWidget, clipboard: apprt.Clipboard) ?*c.GdkClipboard { return switch (clipboard) { .standard => c.gtk_widget_get_clipboard(widget), - .selection => c.gtk_widget_get_primary_clipboard(widget), + .selection, .primary => c.gtk_widget_get_primary_clipboard(widget), }; } pub fn getCursorPos(self: *const Surface) !apprt.CursorPos { diff --git a/src/apprt/structs.zig b/src/apprt/structs.zig index d452bc8eb..abb062503 100644 --- a/src/apprt/structs.zig +++ b/src/apprt/structs.zig @@ -27,9 +27,10 @@ pub const IMEPos = struct { /// The clipboard type. /// /// If this is changed, you must also update ghostty.h -pub const Clipboard = enum(u1) { +pub const Clipboard = enum(u2) { standard = 0, // ctrl+c/v - selection = 1, // also known as the "primary" clipboard + selection = 1, + primary = 2, }; pub const ClipboardRequestType = enum(u8) { diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index fa85c53d4..f0b2d707a 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -2139,6 +2139,7 @@ const StreamHandler = struct { const clipboard_type: apprt.Clipboard = switch (kind) { 'c' => .standard, 's' => .selection, + 'p' => .primary, else => .standard, };