-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect-screen
executable file
·76 lines (64 loc) · 2.01 KB
/
connect-screen
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
menu_cmd="$HOME/.config/i3/bin/make-menu"
singleFlag=0
conkyFlag=0
wallpaperFlag=0
pos='--left-of'
while getopts 'swalrb' OPTION
do
case $OPTION in
s) singleFlag=1;;
w) wallpaperFlag=1;;
a) pos='--above';;
l) pos='--left-of';;
r) pos='--right-of';;
b) pos='--below';;
?) echo "Usage: $0 [-swalrb]";;
esac
done
function get_resolution () {
xrandr | grep "$1" --after-context=1 | tail -1 | awk '{print $1}'
}
declare -a active_displays
declare -a inactive_displays
while read display
do
dname="$(echo "$display" | awk '{print $1}')"
if echo "$display" | grep 'connected \(primary\)\? \?[0-9]' >/dev/null 2>&1
then
active_displays=("${active_displays[@]}" $dname)
else
inactive_displays=("${inactive_displays[@]}" $dname)
fi
done < <(xrandr | grep ' connected ')
if [[ ${#inactive_displays[@]} -eq 0 ]]
then
$menu_cmd -e "No extra displays to connect"
exit
fi
echo ${inactive_displays[@]} | tr ' ' '\n'
echo ${active_displays}
display="$(echo ${inactive_displays[@]} | tr ' ' '\n' | $menu_cmd -p "Select display")"
action="$(echo "solo left right above below" | tr ' ' '\n' | $menu_cmd -p "Action for $display")"
if [[ "$action" == "solo" ]]
then
xrandr --output "$display" --mode "$(get_resolution "$display")" --primary
for active in ${active_displays[@]}
do
xrandr --output "$active" --off
done
else
if [[ "$action" == "left" ]] || [[ "$action" == "right" ]]
then
target="$(echo ${active_displays[@]} | tr ' ' '\n' | $menu_cmd -p "Put $display $action of:")"
xrandr --output "$display" --mode "$(get_resolution "$display")" --${action}-of "$target"
else
target="$(echo ${active_displays[@]} | tr ' ' '\n' | $menu_cmd -p "Put $display $action:")"
xrandr --output "$display" --mode "$(get_resolution "$display")" --${action} "$target"
fi
fi
if [ $wallpaperFlag -eq 1 ]
then
echo "Running wallpaper script"
$HOME/.config/i3/bin/wallpaper
fi