blob: e8376aa6313fc18ddc5eb729ab54a7ee7b4aae4b (
plain)
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
|
#!/bin/bash
# What action to take on closing the laptop lid,
# depending on whether a screen is attached or not.
# This implies setting HandleLidSwitch=ignore in /etc/systemd/logind.conf
# Call this script from /etc/acpi/handler.sh (or other properly set up script
# for handling button/lid acpi event) with parameter 0 and 1 for close and open respectively
export DISPLAY=:0
export XAUTHORITY=/home/dave/.Xauthority
# Check whether first parameter is a number
re='^[0-9]+$'
if ! [[ $1 =~ $re ]]; then
echo "error: Not a number" >&2; exit 1
fi
# function for checking if array contains given string
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
# Get info from xrandr
IFS=$'\r\n' connectedOutputs=($(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/"))
# TODO: Add checks for other ports
#Check for HDMI1 connection
HDMI=$(containsElement "HDMI1" "${connectedOutputs}")
# Suspend or switch screen setup, depending on how many screens are connected
# If the lid was closed
if [ $1 = 0 ];then
# Check if more than one screen or HDMI1 is connected
if [[ ${#connectedOutputs[@]} -gt 1 || $HDMI ]];then
echo "More than one screen connected, or HDMI1 connected"
echo "Not suspending, disabling eDP1, making HDMI1 primary screen."
autorandr -l external-docked
else
echo "Only one screen connected"
echo "Suspending."
systemctl suspend
fi
# If the lid was opened
elif [ $1 = 1 ];then
# Check if more than one screen or HDMI1 is connected
if [[ ${#connectedOutputs[@]} -gt 1 || $HDMI ]];then
echo "More than one screen connected, or HDMI1 connected"
echo "Setting up all connected screens."
autorandr -l multi-docked
fi
fi
|