-
Notifications
You must be signed in to change notification settings - Fork 2
/
acpi_event.sh
63 lines (45 loc) · 1.44 KB
/
acpi_event.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# vim: ai et tw=80 syntax=sh
set -euE
# Event type for ThinkPad ACPI events.
EVENT_TYPE="ibm/hotkey"
# The event type codes from the thinkpad_acpi module:
# https://github.com/torvalds/linux/blob/v5.6/drivers/platform/x86/thinkpad_acpi.c#L173-L176
TP_HKEY_EV_HOTPLUG_DOCK=4010
TP_HKEY_EV_HOTPLUG_UNDOCK=4011
# is_event EVENT_CODE INPUT checks if some input represents this even code.
function is_event {
# The event code is left-padded with 0s. Thus, a regular expression is used.
local regexp
regexp="^[0]*${1}$"
[[ $2 =~ $regexp ]]
}
# log MESSAGE to the system log for debugging.
function log {
@logger@ "[ThinkPad Dock ACPI-Event] $@"
}
log "called with $*"
# This script is called with one parameter, which is space separated. E.g.:
# > 'ibm/hotkey LEN0068:00 00000080 00004010'
# > 'ibm/hotkey LEN0068:00 00000080 00004011'
[[ $# -ne 1 ]] && \
log "expected one parameter" && exit 1
args=($1)
[[ ${#args[@]} -ne 4 ]] && \
log "argument is expected to have four fields" && exit 1
event_type="${args[0]}"
event_code="${args[3]}"
[[ "$EVENT_TYPE" != "$event_type" ]] && \
log "invalid event type: $event_type instead of $EVENT_TYPE" && exit 1
@environment@
if is_event $TP_HKEY_EV_HOTPLUG_DOCK "$event_code"; then
log "dock event"
sleep 2
@dockEvent@
elif is_event $TP_HKEY_EV_HOTPLUG_UNDOCK "$event_code"; then
log "undock event"
sleep 2
@undockEvent@
else
log "unsupported event code $event_code"
fi