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, confirm_close_surface: bool,
mouse_interval: u64, mouse_interval: u64,
macos_non_native_fullscreen: bool, 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 { pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig {
var arena = ArenaAllocator.init(alloc_gpa); 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 // On macOS, we have to opt-in to using alt because option
// by default is a unicode character sequence. // by default is a unicode character sequence.
if (comptime builtin.target.isDarwin()) { if (comptime builtin.target.isDarwin()) {
if (!self.config.macos_option_as_alt) { switch (self.config.macos_option_as_alt) {
log.debug("macos_option_as_alt disabled, not sending esc prefix", .{}); .false => break :alt,
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. // then we strip the alt modifier from the mods for translation.
const translate_mods = translate_mods: { const translate_mods = translate_mods: {
var translate_mods = mods; var translate_mods = mods;
if (self.app.config.@"macos-option-as-alt") switch (self.app.config.@"macos-option-as-alt") {
translate_mods.alt = false; .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; break :translate_mods translate_mods;
}; };

View File

@ -249,7 +249,7 @@ pub const Config = struct {
/// (i.e. alt+ctrl+a). /// (i.e. alt+ctrl+a).
/// ///
/// This does not work with GLFW builds. /// 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. /// This is set by the CLI parser for deinit.
_arena: ?ArenaAllocator = null, _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. /// Color represents a color using RGB.
pub const Color = struct { pub const Color = struct {
r: u8, r: u8,