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

Load custom xkb keymap #3999

Closed
Pu-Anlai opened this issue Mar 31, 2019 · 17 comments
Closed

Load custom xkb keymap #3999

Pu-Anlai opened this issue Mar 31, 2019 · 17 comments
Labels
enhancement New feature or incremental improvement

Comments

@Pu-Anlai
Copy link

Pu-Anlai commented Mar 31, 2019

I use a custom keyboard layout defined in ~/.config/xkb/custom.xkb which I upload to X using xkbcomp ~/.config/xkb/custom.xkb $DISPLAY. Is there any way to do the same in Sway? I tried input * xkb_layout ~/.config/xkb/custom.xkb but that didn't work.

I guess I could register my layout globally and then just load it with input * xkb_layout custom but a) I'd like to do this from within my home folder and b) making a layout available like that is unexpectedly complicated; I edited both the .lst and .xml files in /usr/share/X11/xkb/rules and that didn't work. Those changes could also be gone with the next system update.

@emersion emersion added the enhancement New feature or incremental improvement label Mar 31, 2019
@ghost
Copy link

ghost commented Apr 1, 2019

Maybe it's not the same thing you mean, but I installed my own custom layout in /usr/share/X11/xkb/symbols/, with a custom name so it doesn't touch / isn't touched by anything else, and it works just fine. No need to register anything, just input YOURKEYBOARD xkb_layout YOURNAME

@mdeff
Copy link
Contributor

mdeff commented Apr 2, 2019

I did that as well: custom keyboard layout in /usr/share/X11/xkb/symbols/custom, then input * xkb_layout custom.

@progandy
Copy link
Contributor

progandy commented Apr 3, 2019

Local user settings for keyboard layouts can be stored in ~/.xkb/symbols/ and then loaded by their names just like global layouts. (source)

@mdeff
Copy link
Contributor

mdeff commented Apr 3, 2019

Confirmed to work! Thanks for the tip @progandy. I'll do that from now on.

mdeff added a commit to mdeff/dotfiles that referenced this issue Apr 3, 2019
previously globally defined in /usr/share/X11/xkb/symbols/custom
ref: swaywm/sway#3999
@ddevault ddevault closed this as completed Apr 3, 2019
@Pu-Anlai Pu-Anlai changed the title Load custom xkb layout from file Load custom xkb keymap Apr 4, 2019
@Pu-Anlai
Copy link
Author

Pu-Anlai commented Apr 4, 2019

My apologies, I should have been more specific with my question. It's been a while since I set up my layout so I forgot about the xkb nomenclature. The thing is that my keyboard layout file not only contains an xkb_symbols section but also xkb_types and xkb_keycodes sections. This is all contained in a struct named xkb_keymap. This is the format returned by xkbcomp. I could probably get rid of the xkb_keycodes section but xkb_types is essential for me as that is where custom modifier levels are defined.

So when I try to load this file by doing input [identifier] xkb_layout custom, I get an error because only an xkb_symbols section is expected:

2019-04-04 21:40:33 - [sway-1.0/sway/input/seat.c:673] adding device 1133:16388:Logitech_K360 to seat seat0
xkbcommon: ERROR: Include file of wrong type (expected xkb_symbols, got xkb_keymap); Include file "custom" ignored
xkbcommon: ERROR: Abandoning symbols file "(unnamed)"
xkbcommon: ERROR: Failed to compile xkb_symbols
xkbcommon: ERROR: Failed to compile keymap
2019-04-04 21:40:33 - [sway-1.0/sway/input/keyboard.c:518] cannot configure keyboard: keymap does not exist

So I guess my real question would be, is there any way to load an xkb keymap file? I could of course get rid of the xkb_keycodes section and put the xkb_symbols and xkb_types sections into their own files. Then I could load the symbols file with input [identifier] xkb_layout custom_symbols. However, as far as I know, there is no way to load a custom types file, right?

@Emantor
Copy link
Contributor

Emantor commented Apr 4, 2019

Accordding to https://www.vinc17.net/unix/xkb.en.html ~/.xkb/keymap should work.

@Pu-Anlai
Copy link
Author

Pu-Anlai commented Apr 7, 2019

Accordding to https://www.vinc17.net/unix/xkb.en.html ~/.xkb/keymap should work.

Yeah, but that's for X. The location of the keymap is also incidental because you can put it anywhere and then just upload it to X using xkbcomp [location of file] $DISPLAY.

@progandy
Copy link
Contributor

progandy commented Apr 7, 2019

So I guess my real question would be, is there any way to load an xkb keymap file?

There is no way. Maybe you can create a patch with a new configuration option that makes sway ignore the RMLVO configuration and load a keymap from a file with xkb_keymap_new_from_file

However, as far as I know, there is no way to load a custom types file, right?

That is not straight forward. You could write your own xkb_rules file which in the end produces your desired layout if you really want to. These articles may help you:

@emersion
Copy link
Member

emersion commented Apr 7, 2019

I wouldn't be against a patch that uses xkb_keymap_new_from_file

@Pu-Anlai
Copy link
Author

Pu-Anlai commented Apr 8, 2019

Phew, my C knowledge is pretty much zero. I looked at keyboard.c and input.c and don't think I will be able to implement this at any point in the near future. Unless one of the existing developers has an interest in this, I will try to accomplish this with xkb_rules.

edyounis added a commit to edyounis/sway that referenced this issue Jul 13, 2019
Adds a new commend "xkb_file", which constructs the internal
xkb_keymap from a xkb file rather than an RMLVO configuration.
This allows greater flexibility when specifying xkb configurations.
An xkb file can be dumped with the xkbcomp program.
edyounis added a commit to edyounis/sway that referenced this issue Jul 14, 2019
Adds a new commend "xkb_file", which constructs the internal
xkb_keymap from a xkb file rather than an RMLVO configuration.
This allows greater flexibility when specifying xkb configurations.
An xkb file can be dumped with the xkbcomp program.
edyounis added a commit to edyounis/sway that referenced this issue Jul 17, 2019
Adds a new commend "xkb_file", which constructs the internal
xkb_keymap from a xkb file rather than an RMLVO configuration.
This allows greater flexibility when specifying xkb configurations.
An xkb file can be dumped with the xkbcomp program.
RedSoxFan pushed a commit that referenced this issue Jul 17, 2019
Adds a new commend "xkb_file", which constructs the internal
xkb_keymap from a xkb file rather than an RMLVO configuration.
This allows greater flexibility when specifying xkb configurations.
An xkb file can be dumped with the xkbcomp program.
@CRCulver
Copy link

I have successfully migrated from my X11 setup using xkbcomp like the OP, to Sway using the xkb_file option added through the above-mentioned commits. However, while Wayland applications load my keyboard settings, XWayland applications do not.

Is it reasonable to expect Sway’s xkb_file setting to apply to XWayland windows as well? I cannot find any way to configure XWayland’s keyboard settings, so I assume the Wayland compositor passes them to XWayland.

@emersion
Copy link
Member

Is it reasonable to expect Sway’s xkb_file setting to apply to XWayland windows as well?

Yes.

@CRCulver
Copy link

Shall I therefore reopen this Github issue, or open a new one?

@emersion
Copy link
Member

If it doesn't work, open a bug report.

@isti115
Copy link
Contributor

isti115 commented Jun 27, 2020

Many many thanks to @edyounis I was finally able to recreate what I had earlier done in i3 using Xmodmap. My issue was that inet(evdev) would override what I have defined in my own symbols file, but using a complete xkb_keymap I was able to fix the order and for me it works in xwayland windows, such as firefox as well.

@CodedBinary
Copy link

CodedBinary commented Aug 6, 2020

First I'd like to thank you for getting this far.

I have a somewhat peculiar setup and a peculiar problem with it. Basically, I've rebound the following, and get the following instead:

Key combo Xorg Outcome sway Outcome
Caps + a - nothing
Caps + s + nothing
Caps + d backspace -
Caps + f enter +
Caps + g / enter
Caps + hjkl left down up right left down up right
Caps + qwe.. 123... 123...
Caps + Shift + qwe... !@#... !@#...
Caps + x ` nothing
Caps + c comma *
Caps + v period /
Caps + Alt + q f1 nothing
Caps + Super + h home nothing

Heres my setup:
my .xkeymap: https://pastebin.com/wph6WY1k

First, CAPS (the key, not the sym) is the key i use for accessing the extra layers. This is then bound to NumLock to avoid weirdness when programs look for the caps state, and to stop the light on my keyboard blinking. The rest of the config looks at the state of NumLock, not Lock, for whether they should enter my extra layers (stored in xkb_types, of course). When a key is pressed, it is meant to redirect the keystroke to a different key (not a sym) and clear the relevant modifiers. This part is done in xkb_symbols, next to each key.

One reason this seems so convoluted is I need things like caps+alt+j (caps+j is down) to look like alt+down, with no other modifiers. Similarly, I need shift+caps+x to give me ~ (caps+x gives `) with no modifiers.

Here is a quick rundown of my types:

  • CAPS_Movement is for my hjkl, which has super+caps+h for home, super+caps+l for end, super+caps+j for pgdown, super+caps+k for pgup. Note the 5th level hasn't been used yet.
  • CAPS_NumSuper is for instances where I want precisely Num and Super to change the level I'm on. I don't think I need the super functionality at the moment though. This is what a lot of my simple caps+thing binds use.
  • CAPS_NumSuperShift is for when I want to use Super and Shift to change the level, too - for instance, i dont need to shift backspace, so here I can use shift to make it delete. There are a few media keys that I will try to fix soon that also use this. Similarly, I don't need super functionality at the moment, but I plan to use it for the media keys.
  • CAPS_Num should really be called CAPS_NumAlt. Only alt and numlock change the layer I'm on. This is useful for getting function keys ontop of the qwerty row with caps+alt, and number keys on qwerty row with caps.

Another issue (which I don't think is this program's fault) is that only in vim it doesn't deal handle holding down movements. For instance, I hold down j and I move down once. Weird thing is I hold down downarrow and its as normal - but if I hold down caps+j, which should be exactly downarrow, it moves once.

Other programs seem to handle it normally, but I thought I'd ask if you happened to know anything about why that may be before I pop over somewhere vim related. Let me know if you need me to explain how my config works any more, or if you have a nice way to implement this functionality in a non breaking way.

@Nikola-Milovic
Copy link

Anyone can give their input on why my setup does not work as expected?

Ubuntu 22.04, sway version 1.7

input * xkb_file ~/keyboard/real_prog_dvorak.xkb

If I leave it as is, it does not work for xwayland apps, but works for the terminal and other apps. If I add the

exec_always xkbcomp ~/keyboard/real_prog_dvorak.xkb $DISPLAY

It still does not work, but if I just run xkbcomp ~/keyboard/real_prog_dvorak.xkb $DISPLAY from the terminal afterward, it starts working as expected for the xwayland apps as well

My .xkb can be found here, I got it by dumping it

xkbcomp $DISPLAY current_keymap.xkb

I get some warnings and an error but it seems to be working fine otherwise.

+ ~ ➜ xkbcomp ~/keyboard/real_prog_dvorak.xkb $DISPLAY
Error:            Key <CAPS> added to map for multiple modifiers
                  Using Control, ignoring Lock.
Warning:          No symbols defined for <AB11> (keycode 97)
Warning:          No symbols defined for <JPCM> (keycode 103)
Warning:          No symbols defined for <I120> (keycode 120)
Warning:          No symbols defined for <AE13> (keycode 132)
Warning:          No symbols defined for <I149> (keycode 149)
Warning:          No symbols defined for <I154> (keycode 154)
Warning:          No symbols defined for <I168> (keycode 168)
Warning:          No symbols defined for <I178> (keycode 178)
Warning:          No symbols defined for <I183> (keycode 183)
Warning:          No symbols defined for <I184> (keycode 184)
Warning:          No symbols defined for <FK19> (keycode 197)
Warning:          No symbols defined for <FK24> (keycode 202)
Warning:          No symbols defined for <I217> (keycode 217)
Warning:          No symbols defined for <I219> (keycode 219)
Warning:          No symbols defined for <I222> (keycode 222)
Warning:          No symbols defined for <I230> (keycode 230)
Warning:          No symbols defined for <I248> (keycode 248)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or incremental improvement
Development

No branches or pull requests

10 participants