Bug 503891 - Layouts from ~/.config/xkb are not listed in settings
Summary: Layouts from ~/.config/xkb are not listed in settings
Status: RESOLVED DOWNSTREAM
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_keyboard (other bugs)
Version First Reported In: 6.3.4
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-07 18:07 UTC by Damglador
Modified: 2025-05-11 05:26 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
A user-defined custom Layout (31.66 KB, image/png)
2025-05-08 19:43 UTC, Damglador
Details
Search for "Custom" layouts in the list (26.69 KB, image/png)
2025-05-08 19:52 UTC, Damglador
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Damglador 2025-05-07 18:07:57 UTC
SUMMARY
I have two files in /home/damglador/.config/xkb/symbols/: ua + us. 
They define the following layouts:
default partial alphanumeric_keys
xkb_symbols "custom" {
    include "us(basic)"
    name[Group1]= "English (Custom)";
    key <AE01>	{[               1,          exclam,    onesuperior                      ]};
    key <AE02>	{[               2,              at,    twosuperior,               U2019 ]};
    include "level3(ralt_switch)"
    
};
default partial alphanumeric_keys
xkb_symbols "custom" {
    include "ua(unicode)"
    name[Group1]= "Ukrainian (Custom)";
    key <AE01>	{[               1,          exclam,    onesuperior                      ]};
    key <AE02>	{[               2,        quotedbl,    twosuperior,               U2019 ]};
    
};
I can set these layouts by editing ~/.config/kxkbrc and adding VariantList=custom,custom, and the layouts work like they should. Despite that, they don't show up in the list of keyboard layouts in settings, and they also can't be previewed in settings, even though tecla from GNOME can do that.

STEPS TO REPRODUCE
1. Add a xkb symbols file as ~/.config/xkb/symbols/us with the config from above inside of it
2. Log out and back in
3. Check keyboard layout list in settings
4. Exit ~/.config/kxkbrc so for us VariantList is set to custom
5. Log out and back in
6. Test the layout
7. Try to preview the layout in settings

OBSERVED RESULT
Instead of showing a preview of layout, it shows an error.
It doesn't list the custom layout amongst all other layouts 

EXPECTED RESULT
Preview should work and keyboard layouts from ~/.config/xkb should be listed amongst default layouts

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.3.4
KDE Frameworks Version: 6.13.0
Qt Version: 6.9.0
Kernel Version: 6.14.5-2-cachyos (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 5600H with Radeon Graphics
Memory: 13.5 GiB of RAM
Graphics Processor 1: AMD Radeon Graphics
Graphics Processor 2: NVIDIA GeForce RTX 3060 Laptop GPU

ADDITIONAL INFORMATION
Comment 1 TraceyC 2025-05-07 23:01:45 UTC
Thanks for the bug report. Could you clarify something? In your steps to reproduce, in #1, you say to use the first config with the us file.

Then in step #4, you say to exit the file, but that is after logging out and back in, I assume kate was opened automatically on your system with that file?
Also, in step #4 you say "VariantList is set to custom" but I don't see that in the config you pasted.

Can you please paste the full text of what should be in ~/.config/xkb/symbols/us?
Also, can you attach a screenshot of it appearing in your keyboard layout list?

Thanks.
Comment 2 Damglador 2025-05-08 19:42:48 UTC
Sorry, there should be "Edit" instead of "Exit", my bad. Here are the files:

==== /home/damglador/.config/xkb/symbols/us ====
default partial alphanumeric_keys
xkb_symbols "custom" {
    include "us(basic)"
    name[Group1]= "English (Custom)";
    key <AE01>  {[               1,          exclam,    onesuperior                      ]};
    key <AE02>  {[               2,              at,    twosuperior,               U2019 ]};
    include "level3(ralt_switch)"
    
};

======== ~/.config/kxkbrc ========
[Layout]
CurrentLayout=2
DisplayNames=,
LayoutList=us,ua
LayoutLoopCount=2
Options=grp:shift_caps_toggle,grp:caps_toggle
ResetOldOptions=true
Use=true
VariantList=custom,custom


From my understanding, a file like /usr/share/X11/xkb/rules/evdev.extras.xml or /usr/share/X11/xkb/rules/evdev.xml might be required for it to show up in settings, but 
1. I don't think it reads ~/.config/xkb/rules/evdev.extras.xml, at least in my testing it didn't, maybe I did something wrong. 
2. Docs don't mention it https://community.kde.org/Plasma/Wayland#Custom_keyboard_maps_(XKB) 
3. Holy jeez it makes it so complicated. Would be much nicer if settings just picked up all these custom layouts and put them wherever in the list, and I think they should do that, because there is group named "A user-defined custom Layout", but it only contains one broken layout.
Comment 3 Damglador 2025-05-08 19:43:35 UTC
Created attachment 181086 [details]
A user-defined custom Layout
Comment 4 Damglador 2025-05-08 19:52:35 UTC
Created attachment 181087 [details]
Search for "Custom" layouts in the list

Here it should've found my two layouts, us(custom) and ua(custom) which are named name[Group1]= "English (Custom)"; and name[Group1]= "Ukrainian (Custom)"; respectively. But at the same time, these names are pulled by the language switcher tray and toast when these layouts are manually set in ~/.config/kxkbrc.
Comment 5 TraceyC 2025-05-08 20:24:05 UTC
Thanks for clarifying and providing the file details. I am able to reproduce this behavior on git-master
1. The custom layout is listed as "A user-defined custom Layout" in Add Layout, and it isn't listed in the defined group
2. The error when trying to preview it

The keyboard geometry failed to load. This often indicates that the selected model does not support a specific layout or layout variant.... 

Keycodes above 256 (e.g. <I256>) are not supported by X and are ignored
Error:            Can't find file "custom" for symbols include
                  Exiting
                  Abandoning symbols file "(null)"
Comment 6 Damglador 2025-05-08 20:44:01 UTC
For me the "A user-defined custom Layout" is only one, when I have 2 custom layouts. It is also completely broken, if I add it to my keyboard layout list and apply, the tray icon for displaying current keyboard layout disappears and I can't switch keyboard layouts.
Comment 7 Nate Graham 2025-05-08 21:47:07 UTC
I've added custom layouts like this in the past and it worked, so either the specific way you're doing it isn't working in the KCM, or else your custom layout is broken.
Comment 8 Wismill 2025-05-09 00:18:36 UTC
- ~/.config/xkb/symbols/us replaces the *default* US layout, because 1) it has the same file name 2) of the “default” in “default partial alphanumeric_keys xkb_symbols "custom"”
- ~/.config/xkb/symbols/ua: same, but for the default Ukrainian layout

You do not see “English (Custom)” in the Plasma config because it loads the info from /usr/share/X11/xkb/rules/evdev.xml, unless you provided a custom ~/.config/xkb/rules/evdev.xml. The entry in the system XML file has label “English (US)”.

However, your config loads correctly: check that the layout switcher widget displays e.g. “English (Custom)”, because the switcher uses the data from the symbols files.

The “Custom” layout labelled as “A user-defined custom Layout” is yet another feature and uses  /usr/share/X11/xkb/symbols/custom, that *is not shipped* by xkeyboard-config. So if you did not created this file, it does not exist, and selecting this entry will break your config! Note that this feature is a hack aimed at X11 users. Under Wayland you should use the ~/.config/xkb files.

So in order to config your custom files and have them correctly labelled, you need:
1. Replace your ~/.config/xkb/symbols/us file (same for the ua) with:

// Required to fix https://github.com/xkbcommon/libxkbcommon/issues/726, unless using libxkbcommon 1.9+
default partial alphanumeric_keys xkb_symbols { include "us(basic)" };

partial alphanumeric_keys 
xkb_symbols "custom" {
    include "us(basic)"
    name[Group1]= "English (Custom)";
    key <AE01>	{[               1,          exclam,    onesuperior                      ]};
    key <AE02>	{[               2,              at,    twosuperior,               U2019 ]};
    include "level3(ralt_switch)"  
};

2. Add a ~/.config/xkb/rules/evdev.xml file following these instructions: https://xkbcommon.org/doc/current/user-configuration.html#discoverable-layouts for both your layouts:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xkbConfigRegistry SYSTEM "xkb.dtd">
<xkbConfigRegistry version="1.1">
  <layoutList>
    <layout>
      <configItem>
        <name>us</name>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>custom</name>
            <shortDescription>us</shortDescription>
            <description>English (custom)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
    <layout>
      <configItem>
        <name>ua</name>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>custom</name>
            <shortDescription>ua</shortDescription>
            <description>Ukrainian (custom)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
  </layoutList>
</xkbConfigRegistry>


I added a link to the reference documentation of libxkbcommon in the KDE wiki.
Comment 9 Nate Graham 2025-05-09 00:19:46 UTC
Thanks so much for your exhaustive answer! I had a feeling it was a setup issue.
Comment 10 Wismill 2025-05-09 00:26:31 UTC
(In reply to Nate Graham from comment #9)
> Thanks so much for your exhaustive answer! I had a feeling it was a setup
> issue.

The wiki ought to be updated to include the step with the XML file (+ the issue I mentioned), so that the user can use the GUI to configure their keyboard config.

I.e. providing a *complete* example of a small variant of a standard layout (e.g. US for illustration), which is probably the most common scenario, like the current issue.
Comment 11 Damglador 2025-05-10 23:41:11 UTC
Is it possible to avoid the need of an xml file for keyboards to be discoverable?
Comment 12 Wismill 2025-05-11 05:26:18 UTC
(In reply to Damglador from comment #11)
> Is it possible to avoid the need of an xml file for keyboards to be
> discoverable?

No, it is mandatory to make it appear in the GUI for keyboard config. But it is not necessary if you use the same id of an exisiting variant. I do not advise it though, as this issue shows it is then confusing.