-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscreenctl
executable file
·121 lines (113 loc) · 2.86 KB
/
screenctl
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
#
# screenctl
#
# Manage external screens
#
# Author: Emanuel Duss
#
print_usage(){
cat << EOI
Usage:
screenctl OPTION
Options:
modes List available modes
help Show help message
dialog Show graphical menu
internal Use internal display only
external Use extern display only
clone Show same content on internal and external display
extend [POS] Use internal and external screen as one desktop
POS = { left | right }
EOI
}
main(){
INTERNAL="$(xrandr | awk '/ (connected|[0-9]+x[0-9]+\+[0-9]+\+[0-9]+)/{n = 1; if(++i == n){screen = $1; exit}} END{print screen}')"
EXTERNAL="$(xrandr | awk '/ (connected|[0-9]+x[0-9]+\+[0-9]+\+[0-9]+)/{n = 2; if(++i == n){screen = $1; exit}} END{print screen}')"
WAIT="2" # Seconds
case $1 in
"modes")
xrandr -q
;;
"internal")
if [[ -n "$INTERNAL" ]]
then
xrandr --output "$INTERNAL" --auto --output "$EXTERNAL" --off
xrandr --output "$INTERNAL" --auto
fi
;;
"external")
if [[ -n "$EXTERNAL" ]]
then
xrandr --output "$INTERNAL" --off --output "$EXTERNAL" --auto
xrandr --output "$EXTERNAL" --auto
fi
;;
"clone")
if [[ -n "$INTERNAL" && -n "$EXTERNAL" ]]
then
CLONERES="`xrandr --query | awk '/^ *[0-9]*x[0-9]*/{ print $1 }' | sort -n | uniq -d | tail -1`"
xrandr --output "$INTERNAL" --mode "$CLONERES" \
--output "$EXTERNAL" --same-as "$INTERNAL" --mode "$CLONERES"
fi
;;
"extend")
if [[ -n "$INTERNAL" && -n "$EXTERNAL" ]]
then
case $2 in
"left")
xrandr --output "$INTERNAL" --auto \
--output "$EXTERNAL" --auto --left-of "$INTERNAL" --primary
;;
"right")
xrandr --output "$INTERNAL" --auto \
--output "$EXTERNAL" --auto --right-of "$INTERNAL" --primary
;;
"")
xrandr --output "$INTERNAL" --auto --pos 0x400 \
--output "$EXTERNAL" --auto --pos 1280x0 --primary
;;
*)
print_usage
exit 1
;;
esac
fi
;;
"dialog")
MODE=$(zenity --list --text "Select screen mode:" \
--radiolist --column "Mode" --column "Description" \
TRUE "Internal" \
FALSE "External" \
FALSE "Clone" \
FALSE "Extend" \
FALSE "Extend Left" \
FALSE "Extend Right")
if [[ -n "$MODE" ]]
then
$0 ${MODE,,}
fi
;;
"-h")
print_usage
;;
*)
print_usage
exit 1
;;
esac
#xrandr --dpi 80
if [[ -f ~/.fehbg ]]
then
(sleep "$WAIT"
~/.fehbg
) &
fi
if pgrep conky &>/dev/null
then
(sleep "$WAIT"
pkill -HUP conky 2>&1 >/dev/null
) &
fi
}
main "$@"