non-macos doesn't support directional bindings

This commit is contained in:
Mitchell Hashimoto
2023-08-07 14:52:20 -07:00
parent 47bed51177
commit 32eb226fa3
3 changed files with 27 additions and 1 deletions

View File

@ -3,6 +3,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator; const ArenaAllocator = std.heap.ArenaAllocator;
const apprt = @import("apprt.zig");
const inputpkg = @import("input.zig"); const inputpkg = @import("input.zig");
const terminal = @import("terminal/main.zig"); const terminal = @import("terminal/main.zig");
const internal_os = @import("os/main.zig"); const internal_os = @import("os/main.zig");
@ -1206,7 +1207,18 @@ pub const Keybinds = struct {
}; };
errdefer if (copy) |v| alloc.free(v); errdefer if (copy) |v| alloc.free(v);
const binding = try inputpkg.Binding.parse(value); const binding = binding: {
var binding = try inputpkg.Binding.parse(value);
// Unless we're on native macOS, we don't allow directional
// keys, so we just remap them to "both".
if (comptime !(builtin.target.isDarwin() and apprt.runtime == apprt.embedded)) {
binding.trigger.mods = binding.trigger.mods.removeDirection();
}
break :binding binding;
};
switch (binding.action) { switch (binding.action) {
.unbind => self.set.remove(binding.trigger), .unbind => self.set.remove(binding.trigger),
else => try self.set.put(alloc, binding.trigger, binding.action), else => try self.set.put(alloc, binding.trigger, binding.action),

View File

@ -3,6 +3,7 @@
const Binding = @This(); const Binding = @This();
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const assert = std.debug.assert; const assert = std.debug.assert;
const key = @import("key.zig"); const key = @import("key.zig");

View File

@ -33,6 +33,19 @@ pub const Mods = packed struct(Mods.Int) {
} }
}; };
/// Return the identical mods but with all directional configuration
/// removed and all of it set to "both".
pub fn removeDirection(self: Mods) Mods {
return Mods{
.shift = if (self.shift.pressed()) .both else .none,
.ctrl = if (self.ctrl.pressed()) .both else .none,
.alt = if (self.alt.pressed()) .both else .none,
.super = if (self.super.pressed()) .both else .none,
.caps_lock = self.caps_lock,
.num_lock = self.num_lock,
};
}
// For our own understanding // For our own understanding
test { test {
const testing = std.testing; const testing = std.testing;