gtk: silence bad accelerator warnings

Before this a commit a keybind of CTRL + \ would create a GTK
accelerator of <Ctrl>\, which is incorrect. It needs to be
<Ctrl>backslash, which can be retrieved with gdk_keyval_name().

Signed-off-by: Tristan Partin <tristan@partin.io>
This commit is contained in:
Tristan Partin
2024-09-05 19:08:29 -05:00
parent 0f4d07e68c
commit a0bc6ae966

View File

@ -20,7 +20,13 @@ pub fn accelFromTrigger(buf: []u8, trigger: input.Binding.Trigger) !?[:0]const u
try writer.writeAll(std.mem.sliceTo(c.gdk_keyval_name(keyval), 0)); try writer.writeAll(std.mem.sliceTo(c.gdk_keyval_name(keyval), 0));
}, },
.unicode => |cp| try writer.print("{u}", .{cp}), .unicode => |cp| {
if (c.gdk_keyval_name(cp)) |name| {
try writer.writeAll(std.mem.sliceTo(name, 0));
} else {
try writer.print("{u}", .{cp});
}
},
} }
// We need to make the string null terminated. // We need to make the string null terminated.
@ -74,6 +80,11 @@ test "accelFromTrigger" {
.mods = .{ .super = true }, .mods = .{ .super = true },
.key = .{ .translated = .q }, .key = .{ .translated = .q },
})).?); })).?);
try testing.expectEqualStrings("<Shift><Ctrl><Alt><Super>backslash", (try accelFromTrigger(&buf, .{
.mods = .{ .ctrl = true, .alt = true, .super = true, .shift = true },
.key = .{ .unicode = 92 },
})).?);
} }
/// A raw entry in the keymap. Our keymap contains mappings between /// A raw entry in the keymap. Our keymap contains mappings between