Modifying keyboard layout in wayland

Ubuntu Version

Ubuntu 26.04 LTS

Desktop Environment (if applicable)

KDE Plasma

Problem Description

Before updating to 26.04.1 I had modified .xmodmap to give me grave accents on the vowels in my dvorak keyboard layout. This no longer works now that I have gone to Ubuntu Studio 26.04.1, I presume because it uses Wayland instead of X11. I have searched for a way to easily modify the keyboard layout, but in vain.

I did try the input-remapper package, but couldn’t work out how to get the accents over the letters. Does anyone have a simple solution for me?

A post was split to a new topic: Technical Feedback and Suggestions

Wayland compositors are usually using the same XKB keyboard layout library and definitions as X11 server/clients. Both library and configuration format are very flexible and allow easy customization, also user specific.

This blog post from the author describes it. Here is another blog post describing exactly your problem - switching from xmodmap to the native Wayland layout definition.

If you have questions about implementing it, show your current keyboard layouts and earlier Xmodmap content.

Thanks for the reply. I did find the second of those links, but it looked pretty complicated to follow; but I’ll go back and have another look and see if I can understand it. My current keyboard layout is Dvorak (English UK, dvorak with UK punctuation) and the bit of .Xmodmap that I edited reads

keycode  38 = a A a A agrave NoSymbol agrave
keycode  39 = o O o O ograve NoSymbol ograve
keycode  40 = e E e E egrave NoSymbol egrave
keycode  41 = u U u U ugrave NoSymbol ugrave
keycode  42 = i I i I igrave NoSymbol igrave

so that the Level 3 Shift key always produced vowels with grave accents.

I am confused. The Level 3 is the third column. The accented characters in your case would be produced by the Level 5 and Level 7 (actually, Level 5 + Level 3 normally) shifts.

Please, show your ~/.config/kxkbrc.

Me too! Here is the .config/kxkbrc

cat kxkbrc
[$Version]
update_info=kxkb.upd:remove-empty-lists,kxkb.upd:add-back-resetoptions,kxkb_variants.upd:split-variants

[Layout]
LayoutList=gb
Model=pc105
Options=lv3:ralt_switch,compose:rctrl,lv3:ralt_switch_multikey
ResetOldOptions=true
Use=true
VariantList=dvorakukp

How do you produce accented characters exactly? What key do you press/hold/whatever?

The key immediately to the right of the space bar (labelled Level 3 Shift on my keyboard map) and the relevant vowel key. With my previous setup that produced à etc, but now it gives me à,ô,é,û,î - so they are all wrong apart from the à.

The following worked for me.

~> cat .config/xkb/symbols/gb
xkb_symbols "dvorakukpa" {
    include "gb(dvorakukp)"

    name[Group1]="English (UK, Dvorak, with UK punctuation and accented characters)";

    key <AC01>  { [         a,          A,    agrave,    agrave ] };
    key <AD09>  { [         o,          O,    ograve,    ograve ] };
    key <AD03>  { [         e,          E,    egrave,    egrave ] };
    key <AD07>  { [         u,          U,    ugrave,    ugrave ] };
    key <AD08>  { [         i,          I,    igrave,    igrave ] };
};
~> cat .config/xkb/rules/evdev.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xkbConfigRegistry SYSTEM "xkb.dtd">
<xkbConfigRegistry version="1.1">
  <layoutList>
    <layout>
      <configItem>
        <name>gb</name>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>dvorakukpa</name>
            <shortDescription>dvorakukpa</shortDescription>
            <description>English (UK, Dvorak, with UK punctuation and accented characters)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
  </layoutList>
</xkbConfigRegistry>
~> 

Now I can select it in the keyboard configuration:

Switch to it:

And pressing the corresponding letter with AltGr:

Screenshot_20261003_180148

I have not verified other characters, I am not familiar with this layout.

Thanks again for the help.

That sounds like what I need, but in your rules file, the key codes, the letters/numbers seem pretty random - not sure where to check them, but in my dvorak layout the vowels are the first five keys in the middle row. I have created these files, but the layout is not showing up for me in the keyboard options. Will try rebooting to see if it picks them up.

Yes, sorry, you are right. It should have been

xkb_symbols "dvorakukpa" {

    include "gb(dvorakukp)"

    name[Group1]="English (UK, Dvorak, with UK punctuation and accented characters)";

    key <AC01>  { [         a,          A,    agrave,    agrave ] };
    key <AC02>  { [         o,          O,    ograve,    ograve ] };
    key <AC03>  { [         e,          E,    egrave,    egrave ] };
    key <AC04>  { [         u,          U,    ugrave,    ugrave ] };
    key <AC05>  { [         i,          I,    igrave,    igrave ] };
};

I started with the normal layout.

No, it’s not showing up as an option. I have created .config/xkb/symbols/gb

cat .config/xkb/symbols/gb
include "gb(dvorakukp)"

    name[Group1]="English (UK, Dvorak, with UK punctuation and accented characters)";

    key <AC01>  { [         a,          A,    agrave,    agrave ] };
    key <AC02>  { [         o,          O,    ograve,    ograve ] };
    key <AC03>  { [         e,          E,    egrave,    egrave ] };
    key <AC04>  { [         u,          U,    ugrave,    ugrave ] };
    key <AC05>  { [         i,          I,    igrave,    igrave ] };
};

and created .config/xkb/rules/evdev.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xkbConfigRegistry SYSTEM "xkb.dtd">
<xkbConfigRegistry version="1.1">
  <layoutList>
    <layout>
      <configItem>
        <name>gb</name>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>dvorakukpa</name>
            <shortDescription>dvorakukpa</shortDescription>
            <description>English (UK, Dvorak, with UK punctuation and accented characters)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
  </layoutList>
</xkbConfigRegistry>
~>

So that looks ok to me - but it’s not appearing in the English(UK) list for me.

Is it part of the file content? It was the shell prompt. Check that evdev.xml does not include any stray characters.

I did verify it on Ubuntu 26.04 with full KDE environment.

It was - sorry, just blindly copied your input! Will the files need to have their permissions altered?

At present they are

-rw-r--r-- 1 root root 460 Oct 3 17:21 gb

and

-rw-r--r-- 1 root root 587 Oct 3 17:31 evdev.xml

Why they belong to root? They are supposed to be in your home directory and of course belong to you (although I do not think it matters). Where are these files located?

1 Like

They are in my home directory yes. For some reason I couldn’t create the files unless I used sudo.

Sounds like the compositor cannot access them either. Show

ls -ld ~/.config/xkb
ls -lR ~/.config/xkb
1 Like

ls -ld .config/xkb
drwxr-xr-x 4 root root 4096 Oct 3 16:48 .config/xkb
anb-1@serenity:~$ ls -lR ~/.config/xkb
/home/anb-1/.config/xkb:
total 8
drwxr-xr-x 2 root root 4096 Oct 3 17:31 rules
drwxr-xr-x 2 root root 4096 Oct 3 17:21 symbols

/home/anb-1/.config/xkb/rules:
total 4
-rw-r--r-- 1 root root 587 Oct 3 17:31 evdev.xml

/home/anb-1/.config/xkb/symbols:
total 4
-rw-r--r-- 1 root root 460 Oct 3 17:21 gb

Try reassigning them to you

sudo chown -R anb-1: ~/.config/xkb

Assuming your user name is anb-1.

1 Like

The good news is that it is now showing up in the list. The bad news is that when I try to see the layout I get this error message.


Keycodes above 256 (e.g. <I256>) are not supported by X and are ignored
Error:            No Symbols named "dvorakukpa" in the include file "gb"
                  Exiting
                  Abandoning symbols file "(null)"

and it reverts to the original layout.

So near and yet …. but I really appreciate all the help you are giving. Thank you for your time and trouble.