diff --git a/src/Surface.zig b/src/Surface.zig index 80d18f47e..c4516700d 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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, } } diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 7c2f0514a..e9f2a403c 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -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; }; diff --git a/src/config.zig b/src/config.zig index b1e847153..773017a9a 100644 --- a/src/config.zig +++ b/src/config.zig @@ -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,