-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_monitor.sh
executable file
·94 lines (79 loc) · 2.43 KB
/
switch_monitor.sh
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
#!/bin/bash
DPI=166
INTERNAL=true
TRAY_GEOMETRY="4x1-280+0"
TRAY_ICON_SIZE=24
TRAY_SLOT_SIZE=24
function adjust_xresources () {
echo "Set Xresources dpi $1"
/usr/bin/sed -i "/Xft.dpi/c\Xft.dpi: $1" $HOME/dotfiles/Xresources
/usr/bin/xrdb -merge $HOME/.Xresources
}
function adjust_fontconfig () {
echo "Set fontconfig dpi $1"
/usr/bin/sed -i "/name=\"dpi\"/c\ <edit name=\"dpi\" mode=\"assign\"><double>$1</double></edit>" $HOME/dotfiles/config/fontconfig/fonts.conf
}
function adjust_stalonetray () {
echo "Set stalonetray settings for dpi $DPI"
/usr/bin/sed -i "/geometry/c\geometry $1" $HOME/dotfiles/stalonetrayrc
/usr/bin/sed -i "/icon_size/c\icon_size $2" $HOME/dotfiles/stalonetrayrc
/usr/bin/sed -i "/slot_size/c\slot_size $3" $HOME/dotfiles/stalonetrayrc
# Kill blueman applet
if /usr/bin/pgrep -x "blueman-applet" > /dev/null
then
ps -ef | grep blueman-applet | grep -v grep | awk '{print $2}' | xargs kill
fi
# Kill networkmanager applet
if /usr/bin/pgrep -x "nm-applet" > /dev/null
then
ps -ef | grep nm-applet | grep -v grep | awk '{print $2}' | xargs kill
fi
# Kill stalonetray
if /usr/bin/pgrep -x "stalonetray" > /dev/null
then
ps -ef | grep stalonetray | grep -v grep | awk '{print $2}' | xargs kill
fi
}
if [ $# -eq 0 ]; then
if /usr/bin/xrandr --query | grep --silent '\bDP-1 connected\b'; then
echo "Connected"
DPI=163
INTERNAL=false
TRAY_GEOMETRY="4x1-280+0"
TRAY_ICON_SIZE=24
TRAY_SLOT_SIZE=24
fi
else
if [ $1 == "--internal" ]; then
echo "Switch back to internal monitor"
else
echo "Unknown options: $@"
exit 1
fi
fi
adjust_xresources $DPI
adjust_fontconfig $DPI
adjust_stalonetray $TRAY_GEOMETRY $TRAY_ICON_SIZE $TRAY_SLOT_SIZE
# Run xrandr command
if [ "$INTERNAL" == true ]; then
/usr/bin/xrandr --output eDP-1 --auto --output DP-1 --off
else
/usr/bin/xrandr --output eDP-1 --off --output DP-1 --auto
fi
# Recompile and restart xmonad
xmonad --restart
# Start stalonetray
if ! /usr/bin/pgrep -x "stalonetray" > /dev/null
then
nohup /usr/bin/stalonetray > /dev/null 2>&1 &
fi
# Start networkmanager
if ! /usr/bin/pgrep -x "nm-applet" > /dev/null
then
nohup /usr/bin/nm-applet > /dev/null 2>&1 &
fi
# Start blueman-applet
if ! /usr/bin/pgrep -x "blueman-applet" > /dev/null
then
nohup /usr/bin/blueman-applet > /dev/null 2>&1 &
fi