Ubuntu Pastebin

Paste from yeeve at Thu, 10 Aug 2017 14:20:03 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash

# Reset our keyboards back to GB to start with ...
setxkbmap -layout us && setxkbmap -layout gb

# The remote control device (USB keyboard)
# has keys that overlap with standard keyboards.
# Therefore we map the offending keys here.

kbd_id() {
  keyboard="$1"
  xinput list |
  sed -n "s/.*$keyboard.*id=\([0-9]*\).*keyboard.*/\1/p" |
  head -n1
}

# In our case the USB:ID was shown in the `xinput list` output,
# but this is unusual and you may have to match
# on names or even correlate with /dev/input/by-id/*
remote_id=$(kbd_id 'HID 04d9:1203')
[ "$remote_id" ] || exit

# re-execute this script as "$xuser" if that's not root, in case the root user is not permitted to access the X session.
xuser=$(ps -C Xorg -C X -ouser=)
[ $(id -un) = root ] && [ "$xuser" != root ] && exec su -c $0 "$xuser"
export DISPLAY=:0

# Write out the XKB config to remap just
# the keys we're interested in
mkdir -p /tmp/xkb/symbols
cat >/tmp/xkb/symbols/custom <<\EOF
xkb_keycodes {
    <NMLK> = 230;
    <KPDV> = 231;
    <KPMU> = 232;
};
EOF

# Amend the current keyboard map with
# the above key mappings, and apply to the particular device.
# Note xkbcomp >= 1.2.1 is needed to support this
setxkbmap -device $remote_id -print |
sed 's/\(xkb_keycodes.*\)"/\1+custom"/' |
xkbcomp -I/tmp/xkb -i $remote_id -synch - $DISPLAY 2>/dev/null
Download as text