-
Notifications
You must be signed in to change notification settings - Fork 0
/
display-source-x
executable file
·60 lines (51 loc) · 1.16 KB
/
display-source-x
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
#!/usr/bin/env bash
GREEN='\033[0;32m';
stateDir=~/.local/state/my-display-source-x
fail() {
echo -e "\033[0;31m$1"
exit 1
}
getCurrentReal() {
echo "Getting value from kscreen-doctor." >&2
if kscreen-doctor -o | grep 'DisplayPort-0' | grep -q enabled; then
echo 'main'
else
echo 'tv'
fi
}
getCurrent() {
if [ ! -d $stateDir ]; then
echo "Creating $stateDir" >&2
mkdir $stateDir
fi
if [ ! -f $stateDir/current ]; then
echo "Falling back to kscreen-doctor." >&2
echo $(getCurrentReal)
else
echo "Getting saved value." >&2
cat $stateDir/current
fi
}
setMain() {
xrandr --output DisplayPort-0 --mode 3440x1440 --rate 100
xrandr --output HDMI-A-0 --off
echo 'main' > $stateDir/current
}
setTv() {
xrandr --output HDMI-A-0 --mode 3840x2160 --rate 60 --scale 0.5
xrandr --output DisplayPort-0 --off
echo 'tv' > $stateDir/current
}
current=$(getCurrent)
echo "Current is \"$current\"."
if [[ $1 == '' && $current == 'main' ]]; then
setTv
elif [[ $1 == '' && $current == 'tv' ]]; then
setMain
elif [[ $1 == 'main' ]]; then
setMain
elif [[ $1 == 'tv' ]]; then
setTv
else
fail "Unknown display source \"$1\"."
fi