From 5bbcfb619c896d5b4c2a39a990deb33968802ceb Mon Sep 17 00:00:00 2001 From: Ivan Oreshnikov Date: Wed, 22 Jun 2022 23:41:36 +0200 Subject: [PATCH] Added alternative Alt + character handing for MacOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default on MacOS pressing a key combination containing an Alt key produces a special character: -> ß -> √ ... It is really unfortunate if you want to use those key combinations as shortcuts and this case has to be handles separately by the app. This commit introduces a new configuration flag `neovide_macos_alt_is_meta`. When the flag is set to true then all the Alt- key combinations are treated as shortcuts with no extra character modifications, i.e. pressing `Alt` and `s` indeed emits a shortcut. --- src/window/keyboard_manager.rs | 22 +++++++++++++++++++--- src/window/settings.rs | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/window/keyboard_manager.rs b/src/window/keyboard_manager.rs index d1ce1e8..f63d071 100644 --- a/src/window/keyboard_manager.rs +++ b/src/window/keyboard_manager.rs @@ -147,7 +147,7 @@ impl KeyboardManager { if let Some(original_key_text) = key_text { let mut key_text = original_key_text; if self.alt { - if let Some(modify) = key_event.text_with_all_modifiers() { + if let Some(modify) = key_event_text(key_event) { key_text = modify; } } @@ -194,8 +194,24 @@ fn use_alt(alt: bool) -> bool { // The option or alt key is used on Macos for character set changes // and does not operate the same as other systems. #[cfg(target_os = "macos")] -fn use_alt(_: bool) -> bool { - false +fn use_alt(alt: bool) -> bool { + let settings = SETTINGS.get::(); + settings.macos_alt_is_meta && alt +} + +#[cfg(not(target_os = "macos"))] +fn key_event_text(key_event: &KeyEvent) -> Option<&str> { + key_event.text_with_all_modifiers() +} + +#[cfg(target_os = "macos")] +fn key_event_text(key_event: &KeyEvent) -> Option<&str> { + let settings = SETTINGS.get::(); + if settings.macos_alt_is_meta { + key_event.text + } else { + key_event.text_with_all_modifiers() + } } fn or_empty(condition: bool, text: &str) -> &str { diff --git a/src/window/settings.rs b/src/window/settings.rs index b5f0777..e455dad 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -35,4 +35,5 @@ impl Default for WindowSettings { #[setting_prefix = "input"] pub struct KeyboardSettings { pub use_logo: bool, + pub macos_alt_is_meta: bool, }