dstarikov / ctrl2esc

Map Control to Escape if pressed by itself in ChromeOS
MIT License
2 stars 0 forks source link

Mapping/remapping keys in Linux apps #1

Open espoelstra opened 3 years ago

espoelstra commented 3 years ago

I believe it is possible to manage what keys get sent to a Linux app using Sommelier, so perhaps it would be possible to use those rules to make ctrl2esc get evaluated first rather than passing in the keystroke directly? I'm not sure if caps2esc or other remapping tools if they are not X specific would work as well, but maybe a rule in /etc/default/keyboard would be better if Crostini actually has that file and uses it?

Whether you interact with Sommelier or not this depends if you are using the Terminal for Crostini which is a native ChromeOS app, or if you are using an alternate terminal like Kitty or Gnome Terminal etc or working with another GUI app like VS Code or Spotify for Linux etc.

https://chromium.googlesource.com/chromiumos/platform2/+/413a646b5b7067a989bab2ef9fca0c3a4515cc22/vm_tools/sommelier/README.md#accelerators

https://www.reddit.com/r/Crostini/wiki/enable-chrome-shortcuts-in-linux-apps

dstarikov commented 3 years ago

That's a cool idea and could maybe work. I believe I've tried this in the past but wasn't able to make it work.

My solution works pretty much exactly how I want it to so far, except for the case of wayland-only apps. I remap the search key (where caps lock belongs) to Ctrl from ChromeOS settings. Then this custom keyboard will remap Ctrl to Escape whenever its pressed by itself (only in ChromeOS apps). The custom keyboard doesn't work with Linux apps (yet), but the Ctrl remapping from ChromeOS does. So I run xcape as a systemd service on startup and have it remap Ctrl to Escape for Linux GUI apps - this works as intended for all apps that use X11 rather than wayland.

The normal caps2esc program doesn't work on Crostini for me as I am unable to set the priority with nice in Crostini - this seems to be a limitation of the container system Crostini uses.

Virtual IME's are supposed to be added to Crostini eventually - this will enable the touch keyboard from ChromeOS to work with Linux apps, and it should also make this custom keyboard work, eliminating the need for xcape.

dragon788 commented 3 years ago

xcape is X11 only, but caps2esc is display server agnostic I think?

I've been using Interception Tools for Linux with success for this, and know of people producing other plugins for their custom mappings too. caps2esc is a first proof-of-concept plugin that I use everyday, and works both on X and Wayland. The tool is a bit lower level than usual mapping software, but quite flexible, and my plan for a next plugin is a generalized chording mapping tool.

https://unix.stackexchange.com/a/408648/103652

dragon788 commented 3 years ago

This one appears interesting too, https://github.com/wbolster/evcape/blob/master/README.rst

dstarikov commented 3 years ago

Yea I know about caps2esc - I use it on all of my Linux machines and it works great for everything, including X11, wayland, and consoles. I tried using it on crostini, but it didn't work.

I may have actually only tried the older version - I'm not sure if the interception-plugin version still requires nice to increase process priority, but I'll give that another shot.

evcape looks like a great solution to this. From their docs it might require loading an additional kernel module to work, which wouldn't be possible on Crostini, but also definitely worth a shot.

Have you had any luck with either of these on Crostini?

dragon788 commented 3 years ago

I think for anything to work in Crostini you need to set up a Sommelier "accelerator" for the app you are wanting to use the remapping with (or set it up globally but I haven't tried that yet). Since the ctrl2esc or esc2ctrl only affect the ChromeOS input methods, I think that Sommelier actually ends up passing the "real" key that was pressed into any Linux apps, so either Ctrl or "Super" depending on whether the Chrome Settings remapping completely swaps the positions and what the keys are recognized as.