I shot a UNIX keyboard on ebay.


Of course, it “just works” when you plug it in. However, I want it to work properly, that is, the special keys on the left should show their labels when assigning them e.g. in gnome-keybinding-properties. To do that, it is apparently necessary to edit the xkb rules & xml files which are found in /usr/share/X11/xkb/rules on my distribution.

There is a “Sun Type 5/6” Layout available in gnome-keyboard-properties, but it mysteriously renders the BackSpace key unusuable — this might be a particular bug of my installation, any hints appreciated. (has apparently been fixed in this commit, which probably means fixed in xkeyboard-config 1.8)

Update; the old solution provided problematic (it has been hidden below.) Here is the new approach:

Fix the BackSpace key with this patch:

--- a/usr/share/X11/xkb/symbols/sun_vndr/us  2010-06-16 20:39:59.937546375 +0200
+++ b/usr/share/X11/xkb/symbols/sun_vndr/us 2010-06-15 00:56:22.547604150 +0200
@@ -62,6 +62,8 @@ xkb_symbols "sunbasic" {
     include "inet(evdev)"
     include "us(basic)"
+    // these keys are common to all layouts
+    key <BKSP> { [ BackSpace ]   };
     include "pc(function)"
     include "pc(editing)"
     include "keypad(x11)"

Fix the “too old” AltGr mapping (XOrg changed it from Mode_switch to ISO_Level3_Shift, which is defined in the level3 symbols:)

--- a/usr/share/X11/xkb/symbols/sun_vndr/us  2010-06-16 20:39:59.937546375 +0200
+++ b/usr/share/X11/xkb/symbols/sun_vndr/us 2010-06-15 00:56:22.547604150 +0200
@@ -74,7 +76,8 @@ xkb_symbols "sunbasic" {
     key <LFSH> { [ Shift_L       ]           };
     key <RTSH> { [ Shift_R       ]           };
     key <LALT> { [ Alt_L     ]           };
-    key <ALGR> { [ Mode_switch       ]           };
+//  key <ALGR> { [ Mode_switch       ]           };
+    include "level3(ralt_switch)"
     key <LMTA> { [ Meta_L        ]           };
     key <RMTA> { [ Meta_R        ]           };
     key <LCTL> { [ Control_L     ]           };

Shuffle the modifier maps:

--- a/usr/share/X11/xkb/symbols/sun_vndr/us  2010-06-16 20:39:59.937546375 +0200
+++ b/usr/share/X11/xkb/symbols/sun_vndr/us 2010-06-15 00:56:22.547604150 +0200
@@ -116,9 +119,9 @@ xkb_symbols "sunbasic" {
     modifier_map Control { Control_L, Control_R };
     modifier_map Shift   { Shift_R, Shift_L };
     modifier_map Mod1    { Meta_L, Meta_R };
-    modifier_map Mod2    { Mode_switch };
-    modifier_map Mod3    { Num_Lock };
-    modifier_map Mod4    { Alt_L };
+//  modifier_map Mod2    { Mode_switch };
+    modifier_map Mod2    { Num_Lock };
+    modifier_map Mod3    { Alt_L };

Gnome wants its so-called “<Alt>”-binding on Mod1. I put the ♦Meta-keys there, because they’re in the right place. It further requires Mod2 to be Num_Lock, otherwise it is not happy and a lot of modifier keys stop working when Num_Lock is enabled. (Only the Mod2 is ignored when calculating the overlaps.) The former Mode_switch is mapped to Mod5 by the include above.

With this configuration, the following is now an useful addition to your .Xresources:

xterm*metaSendsEscape: true
xterm*altIsNotMeta: true
xterm*altSendsEscape: false

That way, Alt can be used to generate “Alternate keys” and ♦Meta works for key movement.

(X)Emacs on the other hand wants all kinds of “Meta” to be on one modifier, and (optionally) all kinds of “Alt” on the same, or another. My previous setup was causing one Meta key and the Alt key mapped to Mod1, and another one to Mod4. With the modifier mappings above, Meta correctly generates M- and Alt — generates A- (Super, aka Win-key, would get interpreted as S- in XEmacs.)

I suspect since I have not bound any <Super> keys, Gnome-Do is now confused and launches on a simple press of the Space-bar! Makes you unable to types spaces. I don’t know how to fix this. Trying to assign Alt+space as the Summon Key fails — it only displays “space”… since I don’t use Gnome-Do anyway, I removed it for now using gnome-session-properties.

I wanted to add the UNIX layout to the keyboard image display in the Gnome keyboard properties, so I made a new layout in the rules directory:

  1. Added a new model to base.xml:

         <description>Sun Type USB UNIX Layout</description>
         <vendor>Sun Microsystems</vendor>
  2. Do the same for base.lst

    ! model sun_unix Sun Type USB UNIX Layout

  3. Add rules to base that set the desired options, on the way also fixing the missing geometry for the type6 and euro keyboard:

    ! model = keycodes sun_unix = sun(type6_usb)

    ! model = geometry sun6 = sun(type6) sun_unix = sun(type6unix) sun6euro = sun(type6tuv)

    ! model layout = symbols sun_unix us = sun_vndr/us(type6) sun_unix * = sun_vndr/us(type6)+%l%(v)

Fix a bug in the rules that manifests when you use more than keyboard layout — because of the missing rules, the “pc” symbols are added, causing havok in the modifier mappings

! model      layout[1]       =   symbols
  sun6      *           =   sun_vndr/us(type6)+%l[1]%(v[1])
  sun_unix  *           =   sun_vndr/us(type6)+%l[1]%(v[1])
  sun6euro  *           =   sun_vndr/us(type6)+%l[1]%(v[1])

Modify the ctrl:nocaps rule to make CapsLock an additional right Control (the default key for example in VirtualBox) with this patch: (optional)

--- a/usr/share/X11/xkb/symbols/ctrl 2010-06-16 20:39:59.922548680 +0200
+++ b/usr/share/X11/xkb/symbols/ctrl    2010-06-14 22:21:41.482666941 +0200
@@ -5,7 +5,8 @@
 // eliminate the caps lock key completely (replace with control)
 partial modifier_keys 
 xkb_symbols "nocaps" {
-    replace key <CAPS>   {  [ Control_L, Control_L ] };
+//  replace key <CAPS>   {  [ Control_L, Control_L ] };
+    replace key <CAPS>   {  [ Control_R ] };
     modifier_map  Control { <CAPS>, <LCTL> };

Fix the geometry (caps and control are swapped):

--- a/usr/share/X11/xkb/geometry/sun 2010-06-16 20:39:59.910515296 +0200
+++ b/usr/share/X11/xkb/geometry/sun    2010-06-14 22:29:08.208691859 +0200
@@ -2885,7 +2885,7 @@ xkb_geometry "t6unix" {
    row {
        top= 39;
-       keys { <FRNT>, <COPY>, { <CAPS>, 9, shape="CAPS" },
+       keys { <FRNT>, <COPY>, { <LCTL>, 9, shape="LCTL" },
           <AC01>, <AC02>, <AC03>, <AC04>, <AC05>, 
           <AC06>, <AC07>, <AC08>, <AC09>, <AC10>, 
@@ -2902,7 +2902,7 @@ xkb_geometry "t6unix" {
    row {
        top= 77;
-       keys { <FIND>, <CUT>, { <LCTL>, 9, shape="LCTL" },
+       keys { <FIND>, <CUT>, { <CAPS>, 9, shape="CAPS" },
           <LALT>, {<LMTA>, "LMTA"},
         { <SPCE>, "SPCE" },
           {<RMTA>, "RMTA"}, <COMP>, <ALGR>

Other problems

Unfortunately, I cannot get the Compose LED to light up.

Gnome doesn’t accept the SunFront keybinding to bring windows to the front — what’s up with that?? It works when I just assign it, but stops working on next login. As a workaround, I could get it to work by setting /apps/metacity/window_keybindings/raise_or_lower to the magical value 0x8c in gconf-editor

It is not neccessary to choose any options in the gnome-keyboard-properties.

Following was my first attempt, it has the problem that it confuses Emacs about which modifier bits are Alt, and which are Meta.

  1. Added a new model to base.xml:

         <description>Sun Type USB PC Symbols UNIX Layout</description>
         <vendor>Sun Microsystems</vendor>
  2. Do the same for base.lst

    ! model sun_pcusb_unix Sun Type USB PC Symbols UNIX Layout

  3. Add rules to base that set the desired options:

    ! model = keycodes sun_pcusb_unix = sun(type6_usb)

    ! model = geometry sun_pcusb_unix = sun(type6unix)

    ! model = symbols sun_pcusb_unix = +sun_vndr/usb(sun_usb)+sun_vndr/solaris(xf86keynames)

I chose to add the section xf86keynames there, as this renames some Sun-Keys to XF86-Keys, like SunCopy —> XF86Copy (don’t know if this of any use) and SunAudioLowerVolume —> XF86AudioLowerVolume (which happens to match a Gnome default keybinding)

I should add that these keys worked before (plug&play, with the generic “pc105” keycodes) but stop doing so if I load the sun(type6_usb) ones.

One outstanding issue is that the ♦ (Diamond-)keys generate Alt+Mod4+ in Gnome (or <Alt><Super>), and M-S- in Emacs. I suspect it’s the lines

    key <LMTA> { [ Meta_L      ]   };
    key <RMTA> { [    Meta_R      ]   };

in the sun_usb symbols definition that cause this.

Another one is, that I don’t know if/how the Cut/Copy/Paste can be made use of.

And finally, the original sun6 layout maps ♦ (Diamond-)keys to Meta, but Meta shows up as “Alt” in Gnome. So I wonder what to do with this binding. Traditionally, the bindings should be on the Meta ♦ keys, also because they are larger. But because Gnome now writes Alt everywhere, this is getting misleading (other persons using the computer “why is Alt written on this key when it does not do Alt?”)

Alt is, by the sun6 layout, mapped to <Super>, i.e. the Windows-Keys on Windows-keyboards.

The final tweaks I chose directly from the gnome-keyboard-properties: “Adding €-sign to 4 key” (as printed on the keyboard) and “Key to choose 3rd level: Right Alt” — that makes AltGraph work as I think it should.