Skip to content

kcms/keyboard: Improve preview of keyboard layouts

Ismael Asensio requested to merge work/iasensio/tastenbrett-improvements into master

We have a nice tool to display previews of the keyboard layouts (tastenbrett), using their reported geometry via XKB.

The looks are a bit rough though, so let's polish some rough edges (literally!)

How to Test

  • Within the KCM keyboard selecting "Preview layout" on a certain layout
  • or more easily using the CLI to show the different models and language layouts:
    • tastenbrett -m pc104 -l us
    • tastenbrett -m pc105 -l es
    • tastenbrett -m thinkpad -l us
    • tastenbrett -m microsoft -l us

Some general screenshots

BEFORE AFTER
US PC104 kb-pc104_us-before kb-pc104_us-after
ES PC105 kb-pc105_es-before kb-pc105_es-after
Thinkpad kb-thinkpad_us-before kb-thinkpad_us-after
LK PC86 kb-pc86_lk-before kb-pc86_lk-after
ISO Return key iso-return-before iso-return-after
Hide ISO prefix (latest commit) Screenshot_20240816_054204 Screenshot_20240816_054118
Hide KP prefix (latest commit) Screenshot_20240816_054220 Screenshot_20240816_054108

Commits

Changes are split out in different commits but it is my idea to merge them as necessary

  • Use the defined colors to draw keys, labels and shapes

  • Do not draw outlines for shapes

    Except when it is an explicit outline or for the key tooltips

  • Respect corner radius for complex shapes (ex. Return ISO key)

    Use arcTo to draw the corners of the shapes so they match the aspect of simpler rectangles

  • Center the labels on complex shaped keys

    We cannot adapt easily to the actual key shape, but by centering the text it is less likely to be out of bounds.

    Mainly fixes the Return text cutting the shape on ISO layouts

  • Reduce visual impact of 3rd/4th level symbols

    On layouts that make use of 3rd level symbols (Alt-Gr), those are useful to show but very heavy visually, so let's reduce their impact to make the layout more clear

  • Improve text sizing for keycaps

    Use a fixed point size for labels instead of adapting to height individually, which leads to high inconsistencies between them.

    Use a higher font size for single characters (leters, numbers, symbols) and a smaller one for command keys. Values were chosen empirically.

    In case the text is still longer than the avilable width, let's still use Text.Fit but allowing to wrap up to two lines, which improves cases like Num Lock

  • Remove repeated code to replace "_"

  • Hide unnecessary keycap prefixes like ISO or KP

    They can take up necessary space like in "ISO Left Tab"

Edited by Ismael Asensio

Merge request reports