rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.81k stars 168 forks source link

Regular Expressions or Inheritance for `keyd-application-mapper` Classes #505

Open cheyngoodman opened 1 year ago

cheyngoodman commented 1 year ago

I'm wondering if keyd-application-mapper can be updated to accept a regular expression for X11 window class names.

There are cases where I'm trying to apply the same key bindings to an array of applications like both code-oss and firefox. Regular expression could help simplify the configuration as:

[(code-oss|firefox)]
# Swap Modifier Keys
meta = leftcontrol
control = leftmeta

# Preserve WM Meta key bindings
control.space = M-space
control.tab = M-tab
meta.space = C-space
meta.space = C-space

Otherwise, I'm curious about inheritance or anything else that can be used to simplify a configuration where different applications might use similar key bindings.

[mod-swap]
# Swap Modifier Keys
meta = leftcontrol
control = leftmeta

# Preserve WM Meta key bindings
control.space = M-space
control.tab = M-tab
meta.space = C-space
meta.tab = C-tab

[code-oss]
include mod-swap

[firefox]
include mod-swap

# Quit window using Mod+q
control.q = C-S-w

Unfortunately, for cases where you have a set of binds to apply to a set of applications, * and ? wildcards are not enough to help manage a use case like this elegantly.

rvaiya commented 1 year ago

At this point I don't want to break backward compatibility. The next major release (3.0) will probably introduce a different mechanism for application remapping to which I am not opposed to adding something like this, though I am not yet convinced that shared application bindings are common enough to warrant the additional complexity.

cheyngoodman commented 1 year ago

I mostly am trying to use MacOS like keybindings for M-c copy M-v paste on a Mac layout keyboard to keep shortcuts consistent when switching between MacOS and Linux.

I think I only really want to swap Ctrl for Meta globally in VSCode. When hovering over a link and holding Ctrl there is cursor feedback. Then, Firefox can have a similar behavior just without the cursor feedback, so I'm thinking to group application by similar functionalities.

When applying the swapped modifier, if I want to swap all but some combinations there is then a list of "exceptions". I keep trying to restructure the config, but I wind up with an array of applications needing an array of configurations.

The alternate is to swap modifiers by default but then still, I have some applications that I don't want swapped and will still have an array of exception keybinds for an array of applications.

EDIT: Will investigate using layers with inheritance, building off this example: https://github.com/rvaiya/keyd/blob/master/examples/macos.conf

UPDATE: I'm also using a software based KVM to share the same keyboard between Linux workstation and MacOS simultaneously. The layers configuration in default.conf works vary well so far, except when cutting over to the MacOS system while the conversion layers are still applying.

If the keyd user can have the ability to pause the default.conf bindings while over software KVM, then this layers solution will work for me. There was a mention of being able to pause keybindings here, is that pause feature only for keyd-application-mapper or is it for all keyd bindings?

For now I think I can use the MacOS layer configuration and kill the keyd service while on the native MacOS system and restarting it when connecting to the workstation.

#!/bin/sh
case "$1" in
  'macbook')
    sudo systemctl stop keyd
    ;;
  'workstation')
    sudo systemctl start keyd
    ;;
esac

UPDATE2: Even with layer configurations I'm still using an "exclude" list of the root window, terminal and gaming applications that I don't wish to use those layer on. It would still be useful to configure an array of applications with a set of keybinds.

rvaiya commented 1 year ago

I'm also using a software based KVM to share the same keyboard between Linux workstation and MacOS simultaneously. The layers configuration in default.conf works vary well so far, except when cutting over to the MacOS system while the conversion layers are still applying.

If the KVM uses uinput to generate events, then the best solution is to run the server on the macos machine and install the client on your linux machine.

If the keyd user can have the ability to pause the default.conf bindings while over software KVM, then this layers solution will work for me. There was a mention of being able to pause keybindings here, is that pause feature only for keyd-application-mapper or is it for all keyd bindings?

There is no way to 'pause' bindings without killing keyd, but you can override them (e.g keyd -e reset meta=layer(meta)) whenever your script detects a change.

Even with layer configurations I'm still using an "exclude" list of the root window, terminal and gaming applications that I don't wish to use those layer on. It would still be useful to configure an array of applications with a set of keybinds.

At the moment the only way to achieve this is to duplicate the bindings for each application:

e.g

  [xterm]

  meta = layer(meta)

  [firefox]

  meta = layer(meta)

etc..

cheyngoodman commented 1 year ago

Thank you for the suggestions, currently keyd -e reset meta=layer(meta) on change to MacOS is working perfectly. For per app configurations meta = layer(meta) works great as well. Using layers in this method reduced the unnecessary complexity in my configurations.

I am not yet convinced that shared application bindings are common enough to warrant the additional complexity.

Now that I have layers configured a little more properly, I'm not sure this additional complexity is worth it either.

qadzek commented 8 months ago

I am not yet convinced that shared application bindings are common enough to warrant the additional complexity.

Just want to add that this is something I would definitely use. I apply the same key bindings for multiple browsers, so my app.conf contains a lot of duplication. For instance, the lines under [firefox*] are repeated under [brave-*] and [vivaldi-*].

dickrp commented 2 months ago

Upvote (although it works just fine as-is, using repetition).

Many applications use "C-delete" and "C-backspace" for deleting words. Others use "A-d" and "A-backspace".

If one uses keyd-application-mapper to make application conventions consistent and if there are more applications than key use conventions, being able to specify a list of application names (instead of just globbing) would reduce repetition in the configuration file.