diff options
author | David Runge <david.runge@frqrec.com> | 2014-02-19 19:48:26 +0100 |
---|---|---|
committer | David Runge <david.runge@frqrec.com> | 2014-02-19 19:48:26 +0100 |
commit | d5019b72b1882e9d68e4224208b52c7628e7606a (patch) | |
tree | 302f90653bb8cd0237ce558e1b36d516b1042044 /bin | |
parent | 54f18c52b0d20ad74b1b4b49999e5be4f8656291 (diff) | |
download | dotfiles-d5019b72b1882e9d68e4224208b52c7628e7606a.tar.gz dotfiles-d5019b72b1882e9d68e4224208b52c7628e7606a.tar.bz2 dotfiles-d5019b72b1882e9d68e4224208b52c7628e7606a.tar.xz dotfiles-d5019b72b1882e9d68e4224208b52c7628e7606a.zip |
Adding lid-switch-action script, working in conjunction with acpi event button/lid open/close for setting up screens or suspending on closing of laptop lid
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/lid-switch-action | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/lid-switch-action b/bin/lid-switch-action new file mode 100755 index 0000000..1a22015 --- /dev/null +++ b/bin/lid-switch-action @@ -0,0 +1,47 @@ +#!/bin/bash +# What action to take on closing the laptop lid, +# depending on whether a screen is attached or not + +# 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 + |