Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Italian keyboard: Cannot input some chars #1080

Closed
ferama opened this issue Aug 25, 2021 · 7 comments
Closed

Italian keyboard: Cannot input some chars #1080

ferama opened this issue Aug 25, 2021 · 7 comments
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. keyboard Keyboard mapping/handling macOS Issue applies to Apple macOS

Comments

@ferama
Copy link

ferama commented Aug 25, 2021

What Operating System(s) are you seeing this problem on?

macOS

WezTerm version

latest, built from source too

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

I'm on a M1 Mac using Italian Keyboard. It seems there is no way to input chars like ']' on '}'. I can successfully input '[' and '{' instead. The ']' char on Italian keyboard require a combination of Option plus the key containing "+". The '}' instead, requires Shift+Option+ the key containing "+"

I'm absolutely new to rust but I tried to find the source of the issue. I noticed that if in this file https://github.com/wez/wezterm/blob/main/window/src/os/macos/window.rs I comment from line 1817 to line 1829 I can successfully input the chars above.

            let raw_modifiers = modifiers;
            let mut modifiers = modifiers;

            let (key, raw_key) = if chars.is_empty() || chars == unmod {
                (key, None)
            } else {
                let raw = key_string_to_key_code(unmod);
                match (&key, &raw) {
                    // Avoid eg: \x01 when we can use CTRL-A
                    (KeyCode::Char(c), Some(raw)) if c.is_ascii_control() => (raw.clone(), None),
                    // ==========================================================
                    // Commented the following trying to debug some input not working properly
                    // ==========================================================
                    // (KeyCode::Char(k), Some(KeyCode::Char(r)))
                    //     if k.is_ascii_punctuation() && r.is_ascii_punctuation() =>
                    // {
                    //     // Well, `chars` is supposed to represent the processed and modified
                    //     // interpretation of the keypress, and `unmod` the same, but ignoring
                    //     // any modifier keys.  eg: `ALT-l` has unmod=`l` and chars=`¬`.
                    //     // However, SUPER+SHIFT+[ yields chars=`[` and unmod=`{` which is
                    //     // the opposite of what we want.
                    //     // If both chars and unmod are punctuation then let's take unmod,
                    //     // and filter out the SHIFT state if present.
                    //     modifiers -= Modifiers::SHIFT;
                    //     (KeyCode::Char(*r), None)
                    // }
                    _ => (key, raw),
                }
            };

I'm not actually able to contribute with a proper fix to the issue but I hope that the hint can be helpful

To Reproduce

No response

Configuration

no config

Expected Behavior

No response

Logs

No response

Anything else?

No response

@ferama ferama added the bug Something isn't working label Aug 25, 2021
@wez wez added the macOS Issue applies to Apple macOS label Aug 25, 2021
@wez
Copy link
Owner

wez commented Aug 25, 2021

Thanks for digging in!
#760 and #601 are related issues.
This is a bit tricky to get right because the IME also makes things complicated! (#615)

If you have the bandwidth to poke at this a bit further, and since you have and use one of the keyboard layouts that wezterm struggles with, I'd really appreciate it if you could help us find out the path to success!

The goal of the input handling is to capture, in as high-fidelity as possible, the pressed keys and then represent them in a logical and an unambiguous fashion. The code that you commented out was intended to do that, but it doesn't seem universally good.

What would be super helpful to me is:

  • Turn on https://wezfurlong.org/wezterm/config/lua/config/debug_key_events.html
  • Try pressing the keys that produce the typical latin and punctuation symbols, especially where those require different modifiers from a US layout, and report any that aren't working, and whether your proposed change makes those keys work. Please include the key event debug output from the keys that aren't working, and if your change makes things better, the key event debug output with that change applied.
  • For the things that aren't working, I'd like to try to reproduce that on my M1 mac, which has US keyboard. I can enable the Italian layout, but I don't know which keys to press, so I'd appreciate you giving me really basic and explicit steps on what to press and what to expect the output to be.

@ferama
Copy link
Author

ferama commented Aug 25, 2021

With the changes applied and the logs turned on this is the output:

2021-08-25T17:27:42.042Z INFO  wezterm_mux_server_impl::local > setting up /Users/ferama/.local/share/wezterm/gui-sock-8169
 2021-08-25T17:27:42.197Z INFO  wezterm_gui::termwindow        > OpenGL initialized! Apple M1 4.1 Metal - 71.7.1 is_context_loss_possible=false wezterm version: 20210825-100033-155948a2
 2021-08-25T17:27:46.273Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('ç'), modifiers: SHIFT, raw_key: None, raw_modifiers: SHIFT, raw_code: Some(41), repeat_count: 1, key_is_down: true }
 2021-08-25T17:27:55.089Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('@'), modifiers: NONE, raw_key: Some(Char('ò')), raw_modifiers: ALT | RIGHT_ALT, raw_code: Some(41), repeat_count: 1, key_is_down: true }
 2021-08-25T17:27:58.086Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('ò'), modifiers: NONE, raw_key: None, raw_modifiers: NONE, raw_code: Some(41), repeat_count: 1, key_is_down: true }
 2021-08-25T17:27:59.482Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('à'), modifiers: NONE, raw_key: None, raw_modifiers: NONE, raw_code: Some(39), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:00.809Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('#'), modifiers: NONE, raw_key: Some(Char('à')), raw_modifiers: ALT | RIGHT_ALT, raw_code: Some(39), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:04.654Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('°'), modifiers: SHIFT, raw_key: None, raw_modifiers: SHIFT, raw_code: Some(39), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:07.321Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('ù'), modifiers: NONE, raw_key: None, raw_modifiers: NONE, raw_code: Some(42), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:12.644Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('§'), modifiers: SHIFT, raw_key: None, raw_modifiers: SHIFT, raw_code: Some(42), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:16.675Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('é'), modifiers: SHIFT, raw_key: None, raw_modifiers: SHIFT, raw_code: Some(33), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:17.120Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('è'), modifiers: NONE, raw_key: None, raw_modifiers: NONE, raw_code: Some(33), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:18.481Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('['), modifiers: NONE, raw_key: Some(Char('è')), raw_modifiers: ALT | RIGHT_ALT, raw_code: Some(33), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:20.425Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('*'), modifiers: SHIFT, raw_key: None, raw_modifiers: SHIFT, raw_code: Some(30), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:20.836Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('+'), modifiers: NONE, raw_key: None, raw_modifiers: NONE, raw_code: Some(30), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:21.653Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char(']'), modifiers: NONE, raw_key: Some(Char('+')), raw_modifiers: ALT | RIGHT_ALT, raw_code: Some(30), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:23.299Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('{'), modifiers: NONE, raw_key: Some(Char('é')), raw_modifiers: SHIFT | ALT | RIGHT_ALT, raw_code: Some(33), repeat_count: 1, key_is_down: true }
 2021-08-25T17:28:24.286Z INFO  wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('}'), modifiers: NONE, raw_key: Some(Char('*')), raw_modifiers: SHIFT | ALT | RIGHT_ALT, raw_code: Some(30), repeat_count: 1, key_is_down: true }

and this is what is happening on the terminal:
Schermata 2021-08-25 alle 19 30 03

Everything seems to work as expected. Keep in mind that I'm new to wezterm too so I don't know if the changes can have side effects on keybindings or any other sort of things like other keyboard layouts.

To further test it you can set the keyboard layout that you want to test and then turn on virtual keyboard from Mac accessibility settings ;)

@nklmilojevic
Copy link

I'm going to piggy back on this issue, having the same issue with Serbian input:

CleanShot 2021-12-08 at 19 38 59@2x

I tried the fix with commenting out the code but it doesn't work. Any ideas?

@nklmilojevic
Copy link

quick update:

works with send_composed_key_when_left_alt_is_pressed = true in the config

@aorith
Copy link

aorith commented Dec 9, 2021

I haven't tested ferama's solution, but until someone finds a proper fix for this, remapping the keys that don't work is an option.
For example, this is what I use with an Spanish keyboard layout:

  use_ime = false,
  send_composed_key_when_left_alt_is_pressed = true, -- my bluetooth keyboard needs "left" even if I want the "right" alt
  send_composed_key_when_right_alt_is_pressed = true,
  enable_csi_u_key_encoding = false,
  use_dead_keys = true,
  keys = {
    {key="+", mods="ALT", action={SendKey={key="]"}}},
    {key="ç", mods="ALT", action={SendKey={key="}"}}},
    {key=" ", mods="ALT", action={SendKey={key=" "}}},
  },

@wez wez added the keyboard Keyboard mapping/handling label Jan 2, 2022
wez added a commit that referenced this issue Jan 3, 2022
and then remove horrible mac hacks.

This resolves the root cause for some horrible mac key mapping stuff
that is responsible for at least 3 different user issues by making the
default key assignments work from the physical key location.  That makes
them unambiguous.

refs: #601
refs: #760
refs: #1080
refs: #1483
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Jan 3, 2022
@wez
Copy link
Owner

wez commented Jan 3, 2022

I think this is essentially a duplicate of two other issues, but regardless: Thanks to the groundwork laid in #1483 I just pushed a commit that fixes those other mac issues, and I think it resolves this one too. It will show up in the nightly downloads within an hour.

@wez wez closed this as completed in f2ed459 Jan 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. keyboard Keyboard mapping/handling macOS Issue applies to Apple macOS
Projects
None yet
Development

No branches or pull requests

4 participants