|
#!/bin/bash |
|
|
|
function get_port_edid_map { |
|
xrandr --props | awk '/DP.* connected/{PORT=$1} /EDID/{EDID=1; next} //{if (EDID==1) printf "%s\t%s\n", PORT, $1; EDID=0}' |
|
} |
|
|
|
function get_outputs { |
|
echo "$(get_port_edid_map)" | cut -f 1 |
|
} |
|
|
|
function get_edids { |
|
echo "$(get_port_edid_map)" | cut -f 2 |
|
} |
|
|
|
function edid_to_port { |
|
port=$1 |
|
echo "$(get_port_edid_map)" | grep $port | cut -f 1 |
|
} |
|
|
|
function replace_edid_with_port { |
|
string=$1 |
|
#echo "$string" |
|
for edid in $(get_edids); do |
|
port=$(edid_to_port $edid) |
|
#echo "Replace: $edid > $port" |
|
string=$(echo "$string" | sed s/$edid/$port/g) |
|
#echo "$string" |
|
done |
|
echo $string |
|
} |
|
|
|
function off { |
|
|
|
MAIN_SCREEN=${1:-eDP-1} |
|
MAIN_MODE=${2:-0x61} |
|
|
|
for o in $(get_outputs); do |
|
echo $o |
|
xrandr --output $o --off |
|
done |
|
} |
|
|
|
function main { |
|
MAIN_SCREEN=${1:-eDP-1} |
|
MAIN_MODE=${2:-0x61} |
|
xrandr --output $MAIN_SCREEN --mode $MAIN_MODE |
|
} |
|
|
|
function reset { |
|
off |
|
sleep 5 |
|
main ${@} |
|
} |
|
|
|
|
|
# print modes: xrandr --verbose | grep MHz | sort --key 3 --numeric-sort --reverse | uniq |
|
# seach modes: xrandr --verbose | egrep '^[^[:space:]]|241.500MHz' |
|
|
|
function set_screens { |
|
|
|
config=$(cat screens.ini) |
|
|
|
echo "Checking whether EDIDs in config exist:" |
|
echo "---------------------------" |
|
while read line; do |
|
echo "$line" |
|
edid=$(echo "$line" | cut -d " " -f 1) |
|
port=$(edid_to_port $edid) |
|
if [[ "$port" == "" ]]; then |
|
echo -e "ERROR: Invalid config. Unknown EDID: $edid" |
|
return |
|
fi |
|
done <<< "${config}" |
|
echo "---------------------------" |
|
|
|
echo "Turning off all screens" |
|
sleep 1 |
|
off |
|
sleep 3 |
|
|
|
echo "" |
|
echo "Turning screens back on:" |
|
echo "---------------------------" |
|
while read line; do |
|
replaced=$(replace_edid_with_port "$line") |
|
cmd="xrandr --output $replaced" |
|
echo "$cmd" |
|
$cmd |
|
sleep 3 |
|
done <<< "${config}" |
|
echo "---------------------------" |
|
} |
|
|
|
if [[ "$1" == "reset" ]]; then |
|
reset ${@:2} |
|
elif [[ "$1" == "set" ]]; then |
|
set_screens |
|
elif [[ "$1" == "map" ]]; then |
|
get_port_edid_map |
|
else |
|
echo "Unknown command: $1" |
|
fi |