chiark / gitweb /
autogen.sh: enable git pre-commit
[elogind.git] / src / extras / keymap / findkeyboards
1 #!/usr/bin/env sh
2 # Find "real" keyboard devices and print their device path.
3 # Author: Martin Pitt <martin.pitt@ubuntu.com>
4 #
5 # Copyright (C) 2009, Canonical Ltd.
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16
17 set -e
18
19 # returns OK if $1 contains $2
20 strstr() {
21     [ "${1#*$2*}" != "$1" ]
22 }
23
24 # returns OK if $1 contains $2 at the beginning
25 str_starts() {
26     [ "${1#$2*}" != "$1" ]
27 }
28
29 str_line_starts() {
30     while read a; do str_starts "$a" "$1" && return 0;done
31     return 1;
32 }
33
34 # print a list of input devices which are keyboard-like
35 keyboard_devices() {
36     # standard AT keyboard
37     for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
38         walk=`udevadm info --attribute-walk --path=$dev`
39         env=`udevadm info --query=env --path=$dev`
40         # filter out non-event devices, such as the parent input devices which
41         # have no devnode
42         if ! echo "$env" | str_line_starts 'DEVNAME='; then
43             continue
44         fi
45         if strstr "$walk" 'DRIVERS=="atkbd"'; then
46             echo -n 'AT keyboard: '
47         elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
48             echo -n 'USB keyboard: '
49         else
50             echo -n 'Unknown type: '
51         fi
52         udevadm info --query=name --path=$dev
53     done
54
55     # modules
56     module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
57     module="$module
58 $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
59     module="$module
60 $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
61     for m in $module; do
62         for evdev in $m/event*/dev; do
63             if [ -e "$evdev" ]; then
64                 echo -n 'module: '
65                 udevadm info --query=name --path=${evdev%%/dev}
66             fi
67         done
68     done
69 }
70
71 keyboard_devices