config: macos-option-as-alt now accepts "left", "right"

This commit is contained in:
Mitchell Hashimoto
2023-08-14 12:50:21 -07:00
parent 721087be76
commit cbd6a325e9
3 changed files with 25 additions and 7 deletions

View File

@ -142,7 +142,7 @@ const DerivedConfig = struct {
confirm_close_surface: bool,
mouse_interval: u64,
macos_non_native_fullscreen: bool,
macos_option_as_alt: bool,
macos_option_as_alt: configpkg.OptionAsAlt,
pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig {
var arena = ArenaAllocator.init(alloc_gpa);
@ -1042,9 +1042,11 @@ pub fn charCallback(
// On macOS, we have to opt-in to using alt because option
// by default is a unicode character sequence.
if (comptime builtin.target.isDarwin()) {
if (!self.config.macos_option_as_alt) {
log.debug("macos_option_as_alt disabled, not sending esc prefix", .{});
break :alt;
switch (self.config.macos_option_as_alt) {
.false => break :alt,
.true => {},
.left => if (mods.sides.alt != .left) break :alt,
.right => if (mods.sides.alt != .right) break :alt,
}
}

View File

@ -394,8 +394,16 @@ pub const Surface = struct {
// then we strip the alt modifier from the mods for translation.
const translate_mods = translate_mods: {
var translate_mods = mods;
if (self.app.config.@"macos-option-as-alt")
translate_mods.alt = false;
switch (self.app.config.@"macos-option-as-alt") {
.false => {},
.true => translate_mods.alt = false,
.left => if (mods.sides.alt == .left) {
translate_mods.alt = false;
},
.right => if (mods.sides.alt == .right) {
translate_mods.alt = false;
},
}
break :translate_mods translate_mods;
};

View File

@ -249,7 +249,7 @@ pub const Config = struct {
/// (i.e. alt+ctrl+a).
///
/// This does not work with GLFW builds.
@"macos-option-as-alt": bool = false,
@"macos-option-as-alt": OptionAsAlt = .false,
/// This is set by the CLI parser for deinit.
_arena: ?ArenaAllocator = null,
@ -1036,6 +1036,14 @@ fn equal(comptime T: type, old: T, new: T) bool {
}
}
/// Valid values for macos-option-as-alt.
pub const OptionAsAlt = enum {
false,
true,
left,
right,
};
/// Color represents a color using RGB.
pub const Color = struct {
r: u8,