Skip to content

Instantly share code, notes, and snippets.

@Tyrrrz
Created March 15, 2026 16:22
Show Gist options
  • Select an option

  • Save Tyrrrz/fd6ea6c6217272b1ca407902549dbe06 to your computer and use it in GitHub Desktop.

Select an option

Save Tyrrrz/fd6ea6c6217272b1ca407902549dbe06 to your computer and use it in GitHub Desktop.
Fix Ukrainian keyboard layout on Ubuntu

Ukrainian Keyboard Layout Fix (Ubuntu / Wayland)

Fixes two issues with the default ua(unicode) layout on Ubuntu:

  • The \ key incorrectly types ґ instead of \ / /
  • AltGr+г does not produce ґ / Ґ

The fix adds a fixed variant to the system Ukrainian layout that you can select in GNOME Settings like any other layout.

⚠️ These changes modify files under /usr/share/X11/xkb/. They will be lost if the xkb-data package is updated via apt upgrade. Just re-run steps 1–3 if that happens.


Step 1 — Add the variant to the ua symbols file

sudo tee -a /usr/share/X11/xkb/symbols/ua << 'EOF'

partial alphanumeric_keys
xkb_symbols "fixed" {
    include "ua(unicode)"
    name[Group1]= "Ukrainian (Fixed)";
    key <BKSL> { [ backslash, slash ] };
    key <AD07> { [ Cyrillic_ghe, Cyrillic_GHE, Ukrainian_ghe_with_upturn, Ukrainian_GHE_WITH_UPTURN ] };
};
EOF

This creates a new variant called fixed that inherits everything from the default ua(unicode) layout and overrides just the two broken keys.


Step 2 — Register in evdev.lst

sudo sed -i '/^  ua /a\  fixed            Ukrainian (Fixed)' /usr/share/X11/xkb/rules/evdev.lst

Step 3 — Register in evdev.xml

Use Python to safely insert the variant — avoid using sed on XML as it can corrupt the file and break GNOME's layout picker entirely.

sudo python3 - << 'PYEOF'
import re
with open('/usr/share/X11/xkb/rules/evdev.xml', 'r') as f:
    content = f.read()

new_variant = """        <variant>
          <configItem>
            <name>fixed</name>
            <description>Ukrainian (Fixed)</description>
          </configItem>
        </variant>
"""

content = re.sub(
    r'(<layout>\s*<configItem>\s*<name>ua</name>.*?<variantList>)(.*?)(</variantList>)',
    lambda m: m.group(1) + m.group(2) + new_variant + m.group(3),
    content,
    flags=re.DOTALL,
    count=1
)

with open('/usr/share/X11/xkb/rules/evdev.xml', 'w') as f:
    f.write(content)
print("Done")
PYEOF

Step 4 — Activate the layout

gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('xkb', 'ua+fixed')]"

Adjust the list to match your own active layouts. Then log out and back in.

The layout will now appear as Ukrainian (Fixed) in GNOME Settings → Keyboard → Input Sources.


Recovering from a broken state

If GNOME's layout picker stops working (shows only a few layouts, or the taskbar indicator disappears), it usually means evdev.xml was corrupted. Reinstall the package to restore it:

sudo apt install --reinstall xkb-data

Then re-run steps 1–3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment