regolith-linux / regolith-desktop

Meta package for the Regolith Desktop Environment
1.51k stars 31 forks source link

How to remove certain key bindings using Xresources? #743

Open ywpkwon opened 2 years ago

ywpkwon commented 2 years ago

Is there good way to remove keybinding using Xresources? --- i.e., not touching /usr/share/regolith/i3/config.d/ nor completely redefining a whole file in ~/.config/regolith2/i3/config.d/.

real use case

For example, by default, both Ctrl + Tab and Ctrl + l are assigned for Next Workspace on Output. Let's say, I want Ctrl + Tab key for another function, and I don't need a key for Next Workspace on Output (Moreover, this function has an alternative keymap anyways.) So, I need to free Ctrl + Tab --- which is i3-wm.binding.ws_next_on_output --- to avoid duplication.

One thing I can imagine is to set a dummy key that I will not use in Xresources and use Ctrl + Tab for another function.

# ~/.config/regolith2/Xresources
i3-wm.binding.ws_next_on_output: <some-dummy-key>

But I don't like it because (1) I need to come up with many different fake keys when I need to free several keys and (2) I feel like it's not clean that dummy keys are being mapped to something.

Is there a something that I can do with Xresources, instead of removing /usr/share/regolith/i3/config.d/30_navigation and rewriting ~/.config/regolith2/i3/config.d/30_navigation?

FYI, this is the relevant default code. (/usr/share/regolith/i3/config.d/30_navigation)

## Navigate // Next Workspace on Output // <><Ctrl> Tab ##
set_from_resource $i3-wm.binding.ws_next_on_output i3-wm.binding.ws_next_on_output Ctrl+Tab
bindsym $mod+$i3-wm.binding.ws_next_on_output workspace next_on_output

## Navigate // Next Workspace on Output // <><Ctrl> l ##
set_from_resource $i3-wm.binding.ws_next_on_output2 i3-wm.binding.ws_next_on_output2 Ctrl+l
bindsym $mod+$i3-wm.binding.ws_next_on_output2 workspace next_on_output
maxmahlke commented 2 years ago

I have the same question. Specifically, I would like to remove the bindings for rebooting and logging out. Adding

i3-wm.binding.reboot:
i3-wm.binding.logout:

did not do the trick.

davidhaley commented 1 year ago

Bump.

UtahDave commented 1 year ago

One default that I wanted to remove was a command that would change the focus of the window I was on when I hit the comand and period keys. This made it so I couldn't use a default bash command of "Alt + period" that I use A LOT.

After some digging around I found this defined in /usr/share/regolith/i3/config.d/40_i3-swap-focus.

I then realized that this came from a regolith package. I ran sudo apt-get remove regolith-i3-swap-focus and then reloaded my config with "alt+shift+c" and now I can use that Bash command like I love.

JustSaX commented 1 year ago

For me worked the following within Xresources: i3-wm.binding.bar_toggle: none

ywpkwon commented 9 months ago

I'm the original poster and came back for regolith3 -- this is a very important feature than it looks.

Without this "disabling keybindng" function, I had to redefine all the default wm config files (in /usr/share/regolith/i3/config.d) just for commenting out a few lines. This made my recent migration from 2 to 3 also cumbersome.

@UtahDave's solution removes all useful bindings in a package. Many times users will need to keep the package with only a few disabled.

@JustSaX 's solution didn't seem right: ERROR: Could not translate string to key symbol: "none"

One quick solution is to bind dummy keys. Since I don't use keypads, my temporary solution is keypad keys.

wm.binding.display: KP_1
wm.binding.kill_app: KP_2
wm.binding.reboot: KP_3
wm.binding.shutdown: KP_4
wm.binding.sleep: KP_5
wm.binding.ws_next: KP_6

Could anybody give some advice: (1) Can we please have this feature? (2) other than keypads (because some day I might use them), are there useful (or dummy) keycodes that normal keyboards usually never use?

arnuschky commented 8 months ago

I am need this too. It's quite essential to disable pre-configured keybindings if the shipped config is a extensive as in Regolith

arnuschky commented 8 months ago

Related i3 issue: https://github.com/i3/i3/discussions/5013

kgilmer commented 8 months ago

Here is how I would go about disabling built-in keybindings. This approach works for both i3 and sway. The process is to move the desired configuration partial from the /usr directory to the user's config such that changes can be made.

  1. Determine what partial(s) need to be moved.

We can search for some string in the config files to find out the file that contains what we're interested in. In this case, we can search for next_on_output as this is the i3/sway directive the original poster wants to change:

~$ find /usr/share/regolith/ | xargs grep -HsF next_on_output
/usr/share/regolith/common/config.d/30_navigation:set_from_resource $wm.binding.ws_next_on_output wm.binding.ws_next_on_output Ctrl+Tab
/usr/share/regolith/common/config.d/30_navigation:bindsym $mod+$wm.binding.ws_next_on_output workspace next_on_output
/usr/share/regolith/common/config.d/30_navigation:set_from_resource $wm.binding.ws_next_on_output2 wm.binding.ws_next_on_output2 Ctrl+l
/usr/share/regolith/common/config.d/30_navigation:bindsym $mod+$wm.binding.ws_next_on_output2 workspace next_on_output

In this case the configuration partial is in common, which means it's shared between i3 and sway. Some configuration partials differ between the two managers and so they will be in i3 or sway specific directories. eg:

~$ ls /usr/share/regolith
common  i3  sway

In any case, what we need to get is the name of the file that contains the configuration information we want to change. In this case it's 30_navigation.

  1. Find the Debian package associated with the config partial
~$ dpkg -S 30_navigation
regolith-wm-navigation: /usr/share/regolith/common/config.d/30_navigation

Now we know the package that's providing the configuration we want to move.

  1. Copy the partial to the user dir for later editing
~$ cp /usr/share/regolith/common/config.d/30_navigation ~/.config/regolith3/sway/config.d/

I have copied this directly into my sway config, but it could also go into a common folder if you prefer. Here you can see where sway loads config from, and here is i3.

  1. Remove the Debian package to avoid multiple declarations (turning a copy into a move)
~$ sudo apt remove regolith-wm-navigation
...
Removing regolith-wm-navigation (4.4.5-1regolith-testing) ...
  1. Verifying expected changes
~$ find /usr/share/regolith/ | xargs grep -HsF next_on_output
~$ find ~/.config/regolith3/sway/config.d/ | xargs grep -HsF next_on_output
/home/kgilmer/.config/regolith3/sway/config.d/30_navigation:set_from_resource $wm.binding.ws_next_on_output wm.binding.ws_next_on_output Ctrl+Tab
...
  1. Modifying the user copy of the config partial.

Now you are free to make changes to the user copy of the config partial. Restarting or reloading your desktop session will be required for changes to take effect.

Summary

Essentially we're just moving a file from one place to another, but we need to use the package manager in order to remove the default.

Caveats

You'll notice an error if you follow these steps. This is due to an issue with partial file load ordering. As referenced above, the i3/sway configurations load the system partials before the user partials. This means that any inter-dependencies between partials may break if a partial is moved to the user directory. The config partial system is simple and does not allow for any dependency expression. Two work arounds that come to mind:

  1. move any broken partials also to the user config. They do not need to be edited. The move will restore the required load order.
  2. directly edit the config files in /usr/share/regolith. This is not recommended unless you're pinning packages as fixes and upgrades may unexpectedly overwrite your changes.
davidystephenson commented 1 month ago

@kgilmer Are these instructions still valid for Regolith 3.2? I'm having trouble understanding some of the steps. The links in step 3 point to some lines in /etc but I don't understand how that tells me what the target location should be. How do I know what the target location should be?

The partial I need to modify to remove the sleep keybinding is in 55_session_keybindings, which is part of regolith-i3-session. Are there other files in that package? When I remove it in step 4, is it OK that I've only copied out the 55_session_keybindings file?

kgilmer commented 4 weeks ago

Are these instructions still valid for Regolith 3.2?

Yep, they should be.

The links in step 3 point to some lines in /etc but I don't understand how that tells me what the target location should be. How do I know what the target location should be?

The target location for the (to be modified) partial is your user directory, specifically ~/.config/regolith3/sway/config.d/ for sway or ~/.config/regolith3/i3/config.d/ for i3.

The links to the i3/sway config (in /etc) directory in step 3 are provided for additional context. You don't need to do anything with them, it was just that I wanted to show where the user partial directory was specified from.

Are there other files in that package?

You can use package manager tools to determine things like this. Here's an example:

~$ dpkg -L regolith-i3-session
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/regolith-i3-session
/usr/share/doc/regolith-i3-session/changelog.Debian.gz
/usr/share/doc/regolith-i3-session/copyright
/usr/share/regolith
/usr/share/regolith/i3
/usr/share/regolith/i3/config.d
/usr/share/regolith/i3/config.d/55_session_keybindings

So, yes that's really the only file in the package. This is by design, that a partial has a corresponding package. It's a good question though, because if not then there would be problems.

When I remove it in step 4, is it OK that I've only copied out the 55_session_keybindings file?

Yes

davidystephenson commented 2 weeks ago

@kgilmer Thank you, this worked once I ran mkdir ~/.config/regolith3/ie/config.d/ first.