From 469515c02bd34201d762c00b996e996100d2a6b1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 26 Aug 2022 10:27:41 -0700 Subject: [PATCH] bind function keys (F1 to F12) --- src/Window.zig | 12 ++++++++++++ src/config.zig | 20 ++++++++++++++++++++ src/input/key.zig | 13 +++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/Window.zig b/src/Window.zig index 21fddb9f1..b884a1756 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -594,6 +594,18 @@ fn keyCallback( .end => .end, .page_up => .page_up, .page_down => .page_down, + .F1 => .f1, + .F2 => .f2, + .F3 => .f3, + .F4 => .f4, + .F5 => .f5, + .F6 => .f6, + .F7 => .f7, + .F8 => .f8, + .F9 => .f9, + .F10 => .f10, + .F11 => .f11, + .F12 => .f12, else => .invalid, }, }; diff --git a/src/config.zig b/src/config.zig index 1fa3dc931..a1adb6bb0 100644 --- a/src/config.zig +++ b/src/config.zig @@ -94,6 +94,26 @@ pub const Config = struct { try result.keybind.set.put(alloc, .{ .key = .page_up }, .{ .csi = "5~" }); try result.keybind.set.put(alloc, .{ .key = .page_down }, .{ .csi = "6~" }); + // From xterm: + // Note that F1 through F4 are prefixed with SS3 , while the other keys are + // prefixed with CSI . Older versions of xterm implement different escape + // sequences for F1 through F4, with a CSI prefix. These can be activated + // by setting the oldXtermFKeys resource. However, since they do not + // correspond to any hardware terminal, they have been deprecated. (The + // DEC VT220 reserves F1 through F5 for local functions such as Setup). + try result.keybind.set.put(alloc, .{ .key = .f1 }, .{ .csi = "11~" }); + try result.keybind.set.put(alloc, .{ .key = .f2 }, .{ .csi = "12~" }); + try result.keybind.set.put(alloc, .{ .key = .f3 }, .{ .csi = "13~" }); + try result.keybind.set.put(alloc, .{ .key = .f4 }, .{ .csi = "14~" }); + try result.keybind.set.put(alloc, .{ .key = .f5 }, .{ .csi = "15~" }); + try result.keybind.set.put(alloc, .{ .key = .f6 }, .{ .csi = "17~" }); + try result.keybind.set.put(alloc, .{ .key = .f7 }, .{ .csi = "18~" }); + try result.keybind.set.put(alloc, .{ .key = .f8 }, .{ .csi = "19~" }); + try result.keybind.set.put(alloc, .{ .key = .f9 }, .{ .csi = "20~" }); + try result.keybind.set.put(alloc, .{ .key = .f10 }, .{ .csi = "21~" }); + try result.keybind.set.put(alloc, .{ .key = .f11 }, .{ .csi = "23~" }); + try result.keybind.set.put(alloc, .{ .key = .f12 }, .{ .csi = "24~" }); + return result; } }; diff --git a/src/input/key.zig b/src/input/key.zig index 2bb40b4c7..ddd1b39f4 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -59,6 +59,19 @@ pub const Key = enum { page_up, page_down, + f1, + f2, + f3, + f4, + f5, + f6, + f7, + f8, + f9, + f10, + f11, + f12, + // To support more keys (there are obviously more!) add them here // and ensure the mapping is up to date in the Window key handler. };