winit: Blocking alt keys on macOS

In a terminal emulator like Alacritty, it’s possible to send control characters directly to the shell using the alt and control keys. However this gets problematic with keyboard layouts that use the alt key for accessing alternative key characters. This is mainly an issue on macOS since other platforms usually use the AltGr key.

The concrete problem is that when alt is held down, the modified key is received, instead of the normal key. So for example Option + F will generate ƒ instead of f. In iTerm it’s possible to pick between sending escapes and sending modified keys, however Alacritty currently can’t offer that since winit will always send the modified keys.

Now I’m not really familiar with how this works under the hood in winit, but ideally I’d like an option in the window builder (maybe possible to change at runtime?) to prevent alt from modifying the characters, so that Option + F will still send f.

Alternatively it would be necessary for Alacritty to define its own mappings and ignore the ReceivedCharacter event, which would likely result in a bit of duplication between winit and Alacritty.

More information about this issue can be found here: https://github.com/jwilm/alacritty/issues/2017

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 18
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Also jwilm/alacritty#1610

Once this issue is resolved, I think we will find that most users find this an acceptable alternative given the ecosystem, as you point out. There are only two other oddities which need to be fixed after this, and Alacritty can feel like an integrated terminal emulator on a Mac.

If someone is going to test it on alacritty they could apply the following patch to use mentioned PR in addition to the patch above.

diff --git a/Cargo.toml b/Cargo.toml
index 415ceb9..e0db73b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,3 +13,4 @@ incremental = false

 [patch.crates-io]
 servo-freetype-sys = { path = "servo-freetype-proxy" }
+winit = { git = "https://github.com/kjmph/winit", branch = "fix-alt-modifier" }