You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.7 KiB
101 lines
1.7 KiB
5 years ago
|
#!/bin/sh
|
||
|
|
||
|
help() {
|
||
|
B=$(tput bold)
|
||
|
U=$(tput smul)
|
||
|
N=$(tput sgr0)
|
||
|
|
||
|
cat << EOF
|
||
|
${B}NAME${N}
|
||
4 years ago
|
monctl - monitor manager
|
||
5 years ago
|
|
||
|
${B}SYNOPSIS${N}
|
||
4 years ago
|
${B}monctl${N} [${U}OPTION${N}] [${U}ARG(S)${N}]
|
||
5 years ago
|
|
||
|
${B}OPTIONS${N}
|
||
|
${B}a*${N} ${U}width${N} ${U}height${N} ${U}hertz${N} ${U}name${N}
|
||
5 years ago
|
Setup single monitor with new mode.
|
||
|
|
||
|
${B}p*${N} ${U}name${N} ${U}mode${N}
|
||
|
Setup single primary monitor.
|
||
5 years ago
|
|
||
|
${B}ARGS${N}
|
||
|
width
|
||
|
Pixel width of the monitor.
|
||
|
|
||
|
height
|
||
|
Pixel height of the monitor.
|
||
|
|
||
|
hertz
|
||
|
Refresh rate of the monitor.
|
||
|
|
||
|
name
|
||
|
Xrandr name of the monitor.
|
||
|
EOF
|
||
|
}
|
||
|
|
||
5 years ago
|
# Exit if no option is provided
|
||
5 years ago
|
[ "$#" -eq 0 ] && help && exit 1
|
||
|
|
||
5 years ago
|
# Set required X variables
|
||
|
export DISPLAY=:0
|
||
|
export XAUTHORITY="$XDG_DATA_HOME/xorg/Xauthority"
|
||
|
|
||
5 years ago
|
update() {
|
||
|
sleep 4
|
||
|
|
||
|
# Reconfigure desktops
|
||
4 years ago
|
"$HOME/.local/bin/wm/desktops.sh"
|
||
5 years ago
|
sleep 1
|
||
|
|
||
|
# Restart panel
|
||
4 years ago
|
"$HOME/.local/bin/panel/polybar.sh" &
|
||
5 years ago
|
|
||
|
# Reload wallpaper
|
||
4 years ago
|
"$HOME/.local/bin/wm/wallpaper.sh" &
|
||
5 years ago
|
}
|
||
|
|
||
|
auto() {
|
||
5 years ago
|
[ "$#" != "4" ] && return 1
|
||
5 years ago
|
|
||
5 years ago
|
# Add mode to primary monitor
|
||
5 years ago
|
OUTPUT="$(xrandr -q)"
|
||
|
if ! echo "$OUTPUT" | grep -Fq "$1x$2_$3.00"; then
|
||
|
eval xrandr --newmode $(cvt "$1" "$2" "$3" | awk '/Modeline/{ $1=""; print $0 }')
|
||
|
xrandr --addmode "$4" "$1x$2_$3.00"
|
||
|
fi
|
||
|
|
||
5 years ago
|
primary "$4" "--mode $1x$2_$3.00"
|
||
|
}
|
||
|
|
||
|
primary() {
|
||
|
[ "$#" != "1" ] && [ "$#" != "2" ] && return 1
|
||
|
MODE=${2:-"--auto"}
|
||
|
|
||
5 years ago
|
# Get all connected monitors
|
||
5 years ago
|
CONNECTED="$(xrandr -q | awk '/ connected/{ print $1 }')"
|
||
5 years ago
|
|
||
5 years ago
|
# Disable all other monitors
|
||
5 years ago
|
eval xrandr --output "$1" "$MODE" --primary \
|
||
|
"$(echo "$CONNECTED" | grep -vx "$1" | awk '{ print "--output", $1, "--off" }' | tr '\n' ' ')"
|
||
5 years ago
|
|
||
|
# Post monitor change
|
||
|
update
|
||
|
}
|
||
|
|
||
5 years ago
|
[ $OPTIND -ge 2 ] && shift $((OPTIND - 2))
|
||
5 years ago
|
case "$1" in
|
||
|
a*)
|
||
5 years ago
|
shift 1
|
||
5 years ago
|
auto "$@"
|
||
|
;;
|
||
5 years ago
|
p*)
|
||
|
shift 1
|
||
|
primary "$@"
|
||
|
;;
|
||
5 years ago
|
*)
|
||
|
help
|
||
5 years ago
|
exit 1
|
||
5 years ago
|
;;
|
||
|
esac
|