Advertisement
Guest User

crouton_target_keyboard.sh

a guest
May 1st, 2014
3,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.24 KB | None | 0 0
  1. #!/bin/sh -e
  2. # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. #
  6. # This adds support for Chromebook keyboard special keys.
  7. #
  8. # For example, we map Search+arrows to Page Up/Down/Home/End. This is
  9. # done at the browser level in Chromium OS (i.e., not at the hardware
  10. # or keymap level).
  11. #
  12. # The mapping of Search+F1-F10 is reversed compared to Chromium OS:
  13. # Pressing the back key still produces F1, Search+F1 is required to
  14. # generate XF86Back.
  15. #
  16. # We do this by adding an overlay, and using Super_L (Search key) as
  17. # the overlay latch.
  18. #
  19. # An additional mapping is needed to make sure that Super_R is not
  20. # sent when the Search key is released (this is a little strange,
  21. # and I'm not sure why this happens).
  22.  
  23. REQUIRES='x11'
  24. DESCRIPTION='Adds support for Chromebook keyboard special keys.'
  25. #. "${TARGETSDIR:="$PWD"}/common"
  26.  
  27. ### Append to prepare.sh:
  28. #if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
  29.     # Make sure we start from a fresh package
  30.     apt-mark unhold xkb-data || true 2>/dev/null
  31.     apt-get -y install --reinstall xkb-data
  32. #fi
  33.  
  34. XKBROOT='/usr/share/X11/xkb'
  35. XKBROOTTMP="`mktemp -d crouton-xkb.XXXXXX --tmpdir=/tmp`"
  36. addtrap "rm -rf --one-file-system '$XKBROOTTMP'"
  37. mkdir -p "$XKBROOTTMP/compat" "$XKBROOTTMP/symbols" "$XKBROOTTMP/rules"
  38.  
  39. cat > "$XKBROOTTMP/compat/chromebook" <<END
  40. // Overlay1_Enable is a latch key for overlay1
  41.  
  42. default partial xkb_compatibility "overlay"  {
  43.     interpret Overlay1_Enable+AnyOfOrNone(all) {
  44.         action= SetControls(controls=Overlay1);
  45.     };
  46. };
  47. END
  48.  
  49. cat > "$XKBROOTTMP/symbols/chromebook" <<END
  50. // This mapping assumes that inet(evdev) will also be sourced
  51. partial
  52. xkb_symbols "overlay" {
  53.     key <LWIN> { [ Overlay1_Enable ], overlay1=<LWIN> };
  54.  
  55.     key <AB09> { overlay1=<INS> };
  56.  
  57.     key <LEFT> { overlay1=<HOME> };
  58.     key <RGHT> { overlay1=<END> };
  59.     key <UP>   { overlay1=<PGUP> };
  60.     key <DOWN> { overlay1=<PGDN> };
  61.  
  62.     key <FK01> { overlay1=<I247> };
  63.     key <I247> { [ XF86Back ] };
  64.     key <FK02> { overlay1=<I248> };
  65.     key <I248> { [ XF86Forward ] };
  66.     key <FK03> { overlay1=<I249> };
  67.     key <I249> { [ XF86Reload ] };
  68.     key <FK04> { overlay1=<I235> }; // XF86Display
  69.     key <FK05> { overlay1=<I250> };
  70.     key <I250> { [ XF86ApplicationRight ] };
  71.     key <FK06> { overlay1=<I232> }; // XF86MonBrightnessDown
  72.     key <FK07> { overlay1=<I233> }; // XF86MonBrightnessUp
  73.     key <FK08> { overlay1=<MUTE> };
  74.     key <FK09> { overlay1=<VOL-> };
  75.     key <FK10> { overlay1=<VOL+> };
  76.  
  77.     key <AE01> { overlay1=<FK01> };
  78.     key <AE02> { overlay1=<FK02> };
  79.     key <AE03> { overlay1=<FK03> };
  80.     key <AE04> { overlay1=<FK04> };
  81.     key <AE05> { overlay1=<FK05> };
  82.     key <AE06> { overlay1=<FK06> };
  83.     key <AE07> { overlay1=<FK07> };
  84.     key <AE08> { overlay1=<FK08> };
  85.     key <AE09> { overlay1=<FK09> };
  86.     key <AE10> { overlay1=<FK10> };
  87.     key <AE11> { overlay1=<FK11> };
  88.     key <AE12> { overlay1=<FK12> };
  89.     key <BKSP> { overlay1=<DELE> };
  90.  
  91.     key <LALT> { overlay1=<CAPS> };
  92.     key <RALT> { overlay1=<CAPS> };
  93.  
  94.     // For some strange reason, some Super_R events are triggered when
  95.     // the Search key is released (i.e. with overlay on).
  96.     // This maps RWIN to a dummy key (<I253>), to make sure we catch it.
  97.     key <RWIN> { [ NoSymbol ], overlay1=<I253> };
  98.  
  99.     // Map dummy key to no symbol
  100.     key <I253> { [ NoSymbol ] };
  101. };
  102. END
  103.  
  104. awk '
  105. # default: print line
  106. 1
  107.  
  108. # rules/base.ml1_c.part
  109. /^! model[ \t]*layout\[1\][ \t]*=[ \t]*compat$/{
  110.    found[1]++;
  111.     print "  chromebook *       =   complete+chromebook"
  112. }
  113.  
  114. # rules/base.ml_c.part
  115. /^! model[ \t]*layout[ \t]*=[ \t]*compat$/{
  116.    found[2]++;
  117.     print "  chromebook *       =   complete+chromebook"
  118. }
  119.  
  120. # rules/evdev.m_s.part
  121. /^! model[ \t]*=[ \t]*symbols$/{
  122.    found[3]++;
  123.     print "  chromebook =   +inet(evdev)+chromebook(overlay)"
  124. }
  125.  
  126. END {
  127.    for (i = 1; i <= 3; i++) {
  128.        if (found[i] != 1) {
  129.            print "Error: " FILENAME ": rule " i ": applied " found[i] " times" > "/dev/stderr"
  130.            exit 1
  131.        }
  132.    }
  133. }
  134. ' "$XKBROOT/rules/evdev" > "$XKBROOTTMP/rules/evdev"
  135.  
  136. # rules/base.xml.in
  137. awk '
  138. # default: print line
  139. 1
  140.  
  141. /^.*<modelList>$/{
  142.    found++;
  143.    print "    <model>";
  144.    print "      <configItem>";
  145.    print "        <name>chromebook</name>";
  146.    print "        <description>Chromebook</description>";
  147.    print "        <vendor>Google</vendor>";
  148.    print "      </configItem>";
  149.    print "    </model>"
  150. }
  151.  
  152. END {
  153.    if (found != 1) {
  154.        print "Error: " FILENAME ": rule applied " found " times" > "/dev/stderr"
  155.        exit 1
  156.    }
  157. }
  158. ' "$XKBROOT/rules/evdev.xml" > "$XKBROOTTMP/rules/evdev.xml"
  159.  
  160. awk '
  161. # default: print line
  162. 1
  163.  
  164. /^! model$/{
  165.    found++;
  166.    print "  chromebook      Chromebook"
  167. }
  168.  
  169. END {
  170.    if (found != 1) {
  171.        print "Error: " FILENAME ": rule applied " found " times" > "/dev/stderr"
  172.        exit 1
  173.    }
  174. }
  175. ' "$XKBROOT/rules/evdev.lst" > "$XKBROOTTMP/rules/evdev.lst"
  176.  
  177. # Apply the modifications
  178. cp -a "$XKBROOTTMP"/* "$XKBROOT"/
  179.  
  180. #if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
  181.     # Hold xkb-data, so that it does not get updated
  182.     apt-mark hold xkb-data
  183. #fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement