chiark / gitweb /
move src/extras subdirectories to src/
[elogind.git] / src / keymap / findkeyboards
1 #!/bin/sh -e
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 # returns OK if $1 contains $2
18 strstr() {
19         [ "${1#*$2*}" != "$1" ]
20 }
21
22 # returns OK if $1 contains $2 at the beginning
23 str_starts() {
24         [ "${1#$2*}" != "$1" ]
25 }
26
27 str_line_starts() {
28         while read a; do str_starts "$a" "$1" && return 0;done
29         return 1;
30 }
31
32 # print a list of input devices which are keyboard-like
33 keyboard_devices() {
34         # standard AT keyboard
35         for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
36                 walk=`udevadm info --attribute-walk --path=$dev`
37                 env=`udevadm info --query=env --path=$dev`
38                 # filter out non-event devices, such as the parent input devices which have no devnode
39                 if ! echo "$env" | str_line_starts 'DEVNAME='; then
40                         continue
41                 fi
42                 if strstr "$walk" 'DRIVERS=="atkbd"'; then
43                         echo -n 'AT keyboard: '
44                 elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
45                         echo -n 'USB keyboard: '
46                 else
47                         echo -n 'Unknown type: '
48                fi
49                        udevadm info --query=name --path=$dev
50         done
51
52         # modules
53         module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
54         module="$module
55         $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
56         module="$module
57         $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
58         for m in $module; do
59                 for evdev in $m/event*/dev; do
60                         if [ -e "$evdev" ]; then
61                                 echo -n 'module: '
62                                 udevadm info --query=name --path=${evdev%%/dev}
63                         fi
64                 done
65         done
66 }
67
68 keyboard_devices