From a8651882a752ecba3d3ad2177d7b288969d4a31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 May 2025 00:29:53 +0200 Subject: [PATCH] add cut/copy/paste keys The origin of these keys are old sun keyboards. They are getting picked up by the custom (progammable) keyboard scene (see https://github.com/manna-harbour/miryoku for a popular layout). Support in ghosty is quite handy because it allows to bind copy/paste in a way that doesn't overlap with ctrl-c/ctrl-v, which can have special bindings in some terminal applications. --- include/ghostty.h | 5 +++++ src/apprt/gtk/key.zig | 4 ++++ src/input/key.zig | 8 ++++++++ src/input/keycodes.zig | 3 +++ 4 files changed, 20 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index 941223943..950f5ef80 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -292,6 +292,11 @@ typedef enum { GHOSTTY_KEY_AUDIO_VOLUME_MUTE, GHOSTTY_KEY_AUDIO_VOLUME_UP, GHOSTTY_KEY_WAKE_UP, + + // "Legacy, Non-standard, and Special Keys" § 3.7 + GHOSTTY_KEY_COPY, + GHOSTTY_KEY_CUT, + GHOSTTY_KEY_PASTE, } ghostty_input_key_e; typedef struct { diff --git a/src/apprt/gtk/key.zig b/src/apprt/gtk/key.zig index 3dcfaed98..fc3296366 100644 --- a/src/apprt/gtk/key.zig +++ b/src/apprt/gtk/key.zig @@ -388,6 +388,10 @@ const keymap: []const RawEntry = &.{ .{ gdk.KEY_KP_Delete, .numpad_delete }, .{ gdk.KEY_KP_Begin, .numpad_begin }, + .{ gdk.KEY_Copy, .copy }, + .{ gdk.KEY_Cut, .cut }, + .{ gdk.KEY_Paste, .paste }, + .{ gdk.KEY_Shift_L, .shift_left }, .{ gdk.KEY_Control_L, .control_left }, .{ gdk.KEY_Alt_L, .alt_left }, diff --git a/src/input/key.zig b/src/input/key.zig index 9dad37d78..28aa3ccf4 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -454,6 +454,11 @@ pub const Key = enum(c_int) { audio_volume_up, wake_up, + // "Legacy, Non-standard, and Special Keys" § 3.7 + copy, + cut, + paste, + /// Converts an ASCII character to a key, if possible. This returns /// null if the character is unknown. /// @@ -797,6 +802,9 @@ pub const Key = enum(c_int) { .audio_volume_up, .wake_up, .help, + .copy, + .cut, + .paste, => null, .unidentified, diff --git a/src/input/keycodes.zig b/src/input/keycodes.zig index b4004088e..a85f36d31 100644 --- a/src/input/keycodes.zig +++ b/src/input/keycodes.zig @@ -130,6 +130,9 @@ const code_to_key = code_to_key: { .{ "PageUp", .page_up }, .{ "Delete", .delete }, .{ "End", .end }, + .{ "Copy", .copy }, + .{ "Cut", .cut }, + .{ "Paste", .paste }, .{ "PageDown", .page_down }, .{ "ArrowRight", .arrow_right }, .{ "ArrowLeft", .arrow_left },