From 32eb226fa3de2d3909872439005fbb6f9cbea864 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 7 Aug 2023 14:52:20 -0700 Subject: [PATCH] non-macos doesn't support directional bindings --- src/config.zig | 14 +++++++++++++- src/input/Binding.zig | 1 + src/input/key.zig | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/config.zig b/src/config.zig index 961a67252..ef56f3d42 100644 --- a/src/config.zig +++ b/src/config.zig @@ -3,6 +3,7 @@ const std = @import("std"); const builtin = @import("builtin"); const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; +const apprt = @import("apprt.zig"); const inputpkg = @import("input.zig"); const terminal = @import("terminal/main.zig"); const internal_os = @import("os/main.zig"); @@ -1206,7 +1207,18 @@ pub const Keybinds = struct { }; 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) { .unbind => self.set.remove(binding.trigger), else => try self.set.put(alloc, binding.trigger, binding.action), diff --git a/src/input/Binding.zig b/src/input/Binding.zig index ca51a72a2..c4090b804 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -3,6 +3,7 @@ const Binding = @This(); const std = @import("std"); +const builtin = @import("builtin"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; const key = @import("key.zig"); diff --git a/src/input/key.zig b/src/input/key.zig index 5e91f8bcf..6e0c1c234 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -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 test { const testing = std.testing;