Using compact mac keyboard with Arch

January 31, 2014

My keyboard of choice is the Apple Compact keyboard. This is not a great choice for Linux, or any other OS/hardware combination that is not all Apple. For starters the keyboard is missing two really important keys # and del, and secondly the function keys do alot of work on this keyboard with the idea of them being function keys secondary to their main focus which is do other important things.

This all makes absolute sense when you are using Apple hardware, but when you need to get into a pc's bios, then things become much more challenging. The bios problem was just an indication of what was to come.

Virtual Consoles and X Windows

A basic install of Arch and quite a bit of early configuration involves spending quite alot of time in the virtual console. In most installations of desktop linux, time spent here is minimal. The installer quickly gets you past the point where you need to use the virtual console. You only end up back there when something goes wrong and X won't start. Of course this is precisely the time when you don't want to deal with many of the keys on your keyboard being mapped to the wrong values.

Arch encourages you to deal with the issue early and has some useful pages on the wiki to help you out. To cut a very long story short I've been able to get a reasonably polished vconsole environment with the following characteristics

  • a colour scheme, where I can read all the colors (solarized)
  • a keyboard where all the main keys work
  • a working LAlt-3 mapping to #
  • the §± key mapped to #
  • a prompt that matches (almost) my usual 2 line prompt
  • a font that is reasonably usable

This involved working with alot of low level packages and some fairly crude hacking of configuration files.

At about the same time I've been able to get the same level of functionality working under X. This involved working with an entirely different set of packages. The Arch wiki has 19 different pages in its Keyboard Section and this is only scratching the surface. The main package for dealing with keyboards in X XKB has a frankly quite staggering level of complexity. Arch does little to protect you from this, though in its defence, its wiki is a very good at providing an abridged view of all of this. In a classic example of the utility of the Arch way, exposure to this complexity led to understanding (admittedly only partial). This understanding allowed me to find a quite simple way to make my keyboard work. At the same time its given me the capability to do more complex things in the future (e.g. get the multimedia keys working).

"Give a man a fish ... Teach a man to fish ..."

Virtual Console Details

/etc/vconsole.conf:- key map, and font (Lat2-Terminus16), plus solarized colors.

Hack my keymap to swap keycodes. Keymap in /usr/share/kbd/i386/qwerty in my case file is (which is a simple text file)

Use showkey to see what keycode is generated by a keypress, and modify e.g. my entry for the 3 key became

keycode   4 = three            sterling         numbersign
  control keycode   4 = Escape

Notice the 'numbersign' this makes the third level press (Alt-3) print #

n.b. I'm not convinced that hacking my keymap is the best way to do this. However it works for now

Virtual Console Colors

I'm a big fan of the solarized color scheme, mostly because it is so legible and restfful. Default color terminal in Unix always seem to have the problem of having a completely illegible blue. The virtual console on Arch is no exception. However the AUR has an elegant solution

With this I now have a virtual console that is almost as nice as my terminal on X.

XKB Details

In the end I only had to make a small change to make m keyboard work under X. The amount of learning required to make that change was immense. Here is the main config file

# /etc/X11/xorg.conf.d/10-keyboard.conf
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbModel" "macbook79"
        Option "XkbLayout" "gb"
        Option "XkbOptions" "ctrl:nocaps,lv3:alt_switch"

XKB Model

My keyboard is a 79 key macbook keyboard. XKB has a list of various models in /usr/share/X11/xkb/rules/. The complexity of stuff in this folder is somewhat boggling. However there is a list of model types base.lst and "macbook79" is one of them.

The "XkbOptions" do the following:

  1. Make the caps lock key a ctrl key
  2. Make both alt key level 3 switches. This allows alt-3 to generate a # and was necessary because the default seemed to only do this for the right alt key.

All of this is controlled by the above config file pulling things from /usr/share/X11/xkb/ and constructing a configuration. Whilst I now have some understanding of how this works, it is in no way sufficient to write much more about this. But at least I am now aware of the complexity and have some idea of just how much stuff is going on under the hood to make that simple configuration file so powerful.