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

Key press / release is too fast for gnome-terminal #179

Closed
timbertson opened this issue Sep 27, 2022 · 13 comments
Closed

Key press / release is too fast for gnome-terminal #179

timbertson opened this issue Sep 27, 2022 · 13 comments

Comments

@timbertson
Copy link

I just started using xremap over xbindkeys and I love it, but I noticed one issue. I think the fault is in gnome-terminal, because other apps (chrome, firefox, nautilus) are fine. I have the following setup:

keymap:
  - name: Tab shifting
    remap:
      LEFTCTRL-SHIFT-RIGHTBRACE: LEFTCTRL-PAGEDOWN
      LEFTCTRL-SHIFT-LEFTBRACE: LEFTCTRL-PAGEUP

This gives me mac-style shortcuts for switching tabs.

Unfortunately it doesn't work in gnome-terminal or tilix (so it might be a bug in the underlying vte). They don't seem to register the combination, they just end up scrolling up/down or inserting some escape characters into the terminal.

I found that adding a tiny sleep here makes it work:

diff --git src/event_handler.rs src/event_handler.rs
index f1d2267..369e753 100644
--- src/event_handler.rs
+++ src/event_handler.rs
@@ -343,6 +343,7 @@ impl EventHandler {
 
         // Press the main key
         self.send_key(&key_press.key, PRESS)?;
+        std::thread::sleep(std::time::Duration::from_millis(20));
         self.send_key(&key_press.key, RELEASE)?;
 
         // Resurrect the original modifiers

Obviously this a is dumb workaround and not xremap's fault, but would you be open to a PR which added some kind of keypress_duration config which controlled whether we do a short sleep between pressing and releasing the key?

@k0kubun
Copy link
Contributor

k0kubun commented Sep 27, 2022

Just to have more contexts, are you using X11 (not Wayland)?

@timbertson
Copy link
Author

I'm using wayland:

$ echo $XDG_SESSION_TYPE
wayland

I'm running gnome-shell 42.5, fedora 36. I don't see any xwayland or x11 processes running. There is an /usr/libexec/ibus-x11 process running, but I don't know if that's relevant.

@k0kubun
Copy link
Contributor

k0kubun commented Sep 28, 2022

I've seen a similar behavior on Wayland and I feel it's relevant. Just to be sure about it, can you test the same thing on X11?

Wayland has a lot of issues and I'm currently investigating how we could work around them. If this is one of such instances, I'd like to introduce the workaround after confirming that this is indeed the limitation of Wayland.

@timbertson
Copy link
Author

Tested on x11, and it works fine there without the additional sleep. So yes it seems like a wayland thing.

@benhoyt
Copy link

benhoyt commented Oct 6, 2022

I had a very similar issue (Ubuntu 22.04 amd64, Gnome, Wayland), and @timbertson's patch worked for me too, thanks! FWIW, the issue was happening for me in Gnome terminal as well as Sublime Text.

And thanks @k0kubun for this tool. I'm using it with my brother's https://github.com/berwynhoyt/wordstar-keys/tree/main/xremap to get the Wordstar diamond using CapsLock for the control key. It's great!

@berwynhoyt
Copy link
Contributor

Whatsapp Web has this problem even in X11! And, once again, this patch fixes it.

To reproduce this, you need the following .yml file:

virtual_modifiers:
  - CapsLock
keymap:
  - name: test
    remap:
      CapsLock-backspace: [{set_mark: false}, C-shift-right, shift-right, delete]

(This defines a key sequence that is supposed to delete the next word+space.)

Now browse to web.whatsapp.com in google chrome and start typing a message to a friend. Now try the delete-next-word shortcut above. It often does only half the job. But this patch fixes it.

@kzys
Copy link
Contributor

kzys commented Oct 11, 2022

I can reproduce the issue @timbertson has reported. On my laptop (Framework Laptop 12th gen), sleeping 3 seconds works, but sleeping 2 seconds doesn't. Not really sure this is depending on the hardware or not.

I'm unsure that is coming from libinput, a Wayland compositor or something else.

I can open a PR to "fix" the issue by introducing keypress_duration or auto-detect Wayland and sleep a bit. Would it work?

@k0kubun
Copy link
Contributor

k0kubun commented Oct 11, 2022

At this point, I'm okay with temporarily introducing the config, which I might remove once I find a way to fix the root cause. I'll accept a patch if any of you files that.

kzys added a commit to kzys/xremap that referenced this issue Oct 11, 2022
kzys added a commit to kzys/xremap that referenced this issue Oct 11, 2022
@kzys
Copy link
Contributor

kzys commented Oct 11, 2022

Hmm, I accidentally put the delay right before self.send_keys(&missing_modifiers, RELEASE)?; and it worked fine...

kzys added a commit to kzys/xremap that referenced this issue Oct 11, 2022
@k0kubun
Copy link
Contributor

k0kubun commented Oct 11, 2022

Released the workaround as v0.7.6.

@thorrr
Copy link

thorrr commented Oct 14, 2022

Can you provide an example of where to put the keypress_delay_ms modifier? None of the following seem to work:

  - name: Tab shifting
    remap:
      LEFTCTRL-SHIFT-RIGHTBRACE: LEFTCTRL-PAGEDOWN
      LEFTCTRL-SHIFT-LEFTBRACE: LEFTCTRL-PAGEUP
    keypress_delay_ms: 20

Output:

Error: Failed to load config 'config.yml': keymap[3]: unknown field `keypress_delay_ms`, expected one of `name`, `remap`, `application`, `mode` at line 45 column 5
  - name: Tab shifting
    remap:
      LEFTCTRL-SHIFT-RIGHTBRACE: LEFTCTRL-PAGEDOWN
      LEFTCTRL-SHIFT-LEFTBRACE: LEFTCTRL-PAGEUP
      keypress_delay_ms: 20

Output:

Error: Failed to load config 'config.yml': keymap[3].remap: unknown key 'keypress_delay_ms' at line 43 column 7
  - name: Tab shifting
    remap:
      LEFTCTRL-SHIFT-RIGHTBRACE: LEFTCTRL-PAGEDOWN
      LEFTCTRL-SHIFT-LEFTBRACE: LEFTCTRL-PAGEUP
        keypress_delay_ms: 20

Output:

Error: Failed to load config 'config.yml': keymap[3].remap: data did not match any variant of untagged enum Actions at line 43 column 7

@k0kubun
Copy link
Contributor

k0kubun commented Oct 14, 2022

I believe it's top-level, no indentation.

@thorrr
Copy link

thorrr commented Oct 24, 2022

Thanks! This worked. For reference:

keypress_delay_ms: 20

modmap:
  - name: Global
    <....>

keymap:
  - name: Global
    <.....>

bingo084 added a commit to bingo084/dotfiles that referenced this issue Jan 29, 2024
Some pplications have trouble understanding synthesized key events,
especially on Wayland. keypress_delay_ms can be used to workaround
the issue. see https://github.com/k0kubun/xremap?#keypress_delay_ms
and xremap/xremap#179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants