xkb swap sterling £ and numbersign # on a gb keyboard

xkb swap sterling £ and numbersign # on a gb keyboard



i use a mac gb keyboard layout

mac-gb.png


default layout

pressing shift + 3 outputs sterling £
and pressing option + 3 outputs numbersign #

what i needed to do was change the keyboard layout
change the keys so pressing shift and 3 ouputs # instead of £

pressing shift + 3 outputs sterling #
and pressing option + 3 outputs numbersign £

the wayland window manager i use dwl configuration has a section called TAGKEYS
which uses xkb key names for keyboard shortcuts that allow you to move a window to a specific tag ( virtual desktop )

pressing super + shift + 2 moves the window to the second tag
pressing super + shift + 3 should move the window to the third tag

dwl config.h

C:
TAGKEYS(          XKB_KEY_1, XKB_KEY_exclam,                     0),
TAGKEYS(          XKB_KEY_2, XKB_KEY_at,                         1),
TAGKEYS(          XKB_KEY_3, XKB_KEY_numbersign,                 2),
TAGKEYS(          XKB_KEY_4, XKB_KEY_dollar,                     3),
TAGKEYS(          XKB_KEY_5, XKB_KEY_percent,                    4),
TAGKEYS(          XKB_KEY_6, XKB_KEY_asciicircum,                5),
TAGKEYS(          XKB_KEY_7, XKB_KEY_ampersand,                  6),
TAGKEYS(          XKB_KEY_8, XKB_KEY_asterisk,                   7),
TAGKEYS(          XKB_KEY_9, XKB_KEY_parenleft,                  8),

the problem is the xkb name used is numbersign

Code:
XKB_KEY_3, XKB_KEY_numbersign

which is triggered by pressing alt + 3,
so we need to change numbersign to be activate by shift + 3

otherwise we cant move a window to the third tag
because shift + 3 is outputting sterling £

i tried changing the code to sterling in the config.h but it didnt work

xkb directory

create the ~/.config/xkb directory and sub directories

Code:
mkdir -p ~/.config/xkb/{symbols,rules,compat,keycodes,types}

xkb directory stucture

Code:
/home/username/.config/xkb
├── compat
├── keycodes
├── rules
│   ├── evdev
│   └── evdev.xml
├── symbols
│   ├── custom
│   └── gb
└── types

6 directories, 4 files

Code:
rules/evdev

Code:
! option = symbols
  custom:swap_sterling_numbersign = +custom(swap_sterling_numbersign)

! include %S/evdev

Code:
rules/evdev.xml

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>swap_sterling_numbersign</name>
            <shortDescription>swap_sterling_numbersign</shortDescription>
            <description>GB(swap_sterling_numbersign)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
  </layoutList>
  <optionList>
    <group allowMultipleSelection="true">
      <configItem>
        <name>custom</name>
        <description>custom options</description>
      </configItem>
      <option>
        <configItem>
          <name>custom:swap_sterling_numbersign</name>
          <description>swap sterling and numbersign</description>
        </configItem>
      </option>
    </group>
  </optionList>
</xkbConfigRegistry>

Code:
symbols/custom

Code:
// swap sterling and numbersign
partial modifier_keys
xkb_symbols "swap_sterling_numbersign" {
    key <AE03> { [ 3, numbersign, sterling ] };
};

Code:
symbols/gb

Code:
// swap sterling and numbersign
default partial alphanumeric_keys
xkb_symbols "swap_sterling_numbersign" {
    name[Group1]= "swap_sterling_numbersign - Mac";
    key <AE03> { [ 3, numbersign, sterling ] };
};

xkb option name

Code:
custom:swap_sterling_numbersign

dwl config.h

C:
static const struct xkb_rule_names xkb_rules = {
    /* can specify fields: rules, model, layout, variant, options */
    /* example:
    .options = "ctrl:nocaps",
    */
    .layout = "gb",
    .model = "104",
    .options = "ctrl:swap_lalt_lctl,custom:swap_sterling_numbersign,caps:none",
    .rules = "evdev",
    .variant = "mac",
};

now pressing shift + 3 outputs #
and pressing alt + 3 outputs £

and i can move windows to the third tag with dwl

for other window managers
you just need to add custom:swap_sterling_numbersign as xkb option

the new xkb option works on wayland or x11 with window managers
and with gnome and kde ( i havent tried any other desktops )
 
the fix change from the default

Code:
key <AE03> { [ 3, sterling, numbersign ] };

to

Code:
key <AE03> { [ 3, numbersign, sterling ] };
 
Back
Top