Merge pull request #897 from gpanders/primary-clipboard

clipboard: add Clipboard variant for primary clipboard
This commit is contained in:
Mitchell Hashimoto
2023-11-16 21:45:01 -08:00
committed by GitHub
6 changed files with 9 additions and 6 deletions

View File

@ -2727,6 +2727,7 @@ fn completeClipboardReadOSC52(
const kind: u8 = switch (clipboard_type) { const kind: u8 = switch (clipboard_type) {
.standard => 'c', .standard => 'c',
.selection => 's', .selection => 's',
.primary => 'p',
}; };
// Wrap our data with the OSC code // Wrap our data with the OSC code

View File

@ -474,7 +474,7 @@ pub const Surface = struct {
) bool { ) bool {
return switch (clipboard_type) { return switch (clipboard_type) {
.standard => true, .standard => true,
.selection => self.app.opts.supports_selection_clipboard, .selection, .primary => self.app.opts.supports_selection_clipboard,
}; };
} }

View File

@ -658,7 +658,7 @@ pub const Surface = struct {
// GLFW can read clipboards immediately so just do that. // GLFW can read clipboards immediately so just do that.
const str: [:0]const u8 = switch (clipboard_type) { const str: [:0]const u8 = switch (clipboard_type) {
.standard => glfw.getClipboardString() orelse return glfw.mustGetErrorCode(), .standard => glfw.getClipboardString() orelse return glfw.mustGetErrorCode(),
.selection => selection: { .selection, .primary => selection: {
// Not supported except on Linux // Not supported except on Linux
if (comptime builtin.os.tag != .linux) break :selection ""; if (comptime builtin.os.tag != .linux) break :selection "";
@ -684,7 +684,7 @@ pub const Surface = struct {
_ = self; _ = self;
switch (clipboard_type) { switch (clipboard_type) {
.standard => glfw.setClipboardString(val), .standard => glfw.setClipboardString(val),
.selection => { .selection, .primary => {
// Not supported except on Linux // Not supported except on Linux
if (comptime builtin.os.tag != .linux) return; if (comptime builtin.os.tag != .linux) return;
glfwNative.setX11SelectionString(val.ptr); glfwNative.setX11SelectionString(val.ptr);

View File

@ -589,7 +589,7 @@ fn gtkClipboardRead(
fn getClipboard(widget: *c.GtkWidget, clipboard: apprt.Clipboard) ?*c.GdkClipboard { fn getClipboard(widget: *c.GtkWidget, clipboard: apprt.Clipboard) ?*c.GdkClipboard {
return switch (clipboard) { return switch (clipboard) {
.standard => c.gtk_widget_get_clipboard(widget), .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 { pub fn getCursorPos(self: *const Surface) !apprt.CursorPos {

View File

@ -27,9 +27,10 @@ pub const IMEPos = struct {
/// The clipboard type. /// The clipboard type.
/// ///
/// If this is changed, you must also update ghostty.h /// 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 standard = 0, // ctrl+c/v
selection = 1, // also known as the "primary" clipboard selection = 1,
primary = 2,
}; };
pub const ClipboardRequestType = enum(u8) { pub const ClipboardRequestType = enum(u8) {

View File

@ -2139,6 +2139,7 @@ const StreamHandler = struct {
const clipboard_type: apprt.Clipboard = switch (kind) { const clipboard_type: apprt.Clipboard = switch (kind) {
'c' => .standard, 'c' => .standard,
's' => .selection, 's' => .selection,
'p' => .primary,
else => .standard, else => .standard,
}; };