scripts/ecran

92 lines
2.8 KiB
Plaintext
Raw Normal View History

2014-09-25 23:37:13 +02:00
#! /bin/sh
# Description: Manage video output (size, orientation, ...)
# And reload wm configuration
2020-08-21 19:58:25 +02:00
2020-08-21 20:02:03 +02:00
# Vars {{{
## First and main screen (laptop screen,…)
readonly MAIN_OUTPUT_NAME="LVDS-1"
2014-09-25 23:37:13 +02:00
2020-08-21 20:02:03 +02:00
[ -z "${DEBUG}" ] && readonly DEBUG=0
## Colors
readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
readonly COLOR_DEBUG="${PURPLE}"
# }}}
debug_message() { # {{{
local_message="${1}"
## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
return 0
}
# }}}
2020-08-21 21:09:00 +02:00
define_vars() { # {{{
2020-08-21 20:02:03 +02:00
2020-08-21 21:09:00 +02:00
return_second_output_name="0"
SECOND_OUTPUT_NAME=$(xrandr | grep " connected" | grep -v "${MAIN_OUTPUT_NAME}" | awk 'NR==1{ print $1 }')
2020-08-21 21:09:00 +02:00
debug_message "define_vars \
The second connected output is: ${SECOND_OUTPUT_NAME}."
2020-08-21 21:09:00 +02:00
return "${return_second_output_name}"
}
2020-08-21 20:02:03 +02:00
# }}}
2020-08-21 21:09:00 +02:00
main() { # {{{
2014-09-25 23:37:13 +02:00
2020-08-21 21:09:00 +02:00
## Define all vars
define_vars
}
# }}}
main
# Manage arguments # {{{
# This code can't be in a function due to arguments
2014-09-25 23:37:13 +02:00
case "${1}" in
off )
## TODO: One command to enable main screen and a loop to disable all other connected output
xrandr --output "${MAIN_OUTPUT_NAME:=/dev/null}" --auto --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off --output VGA-1 --off --output HDMI-3 --off --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off
xrandr --output VGA --off
printf 'Desactivate all video output'
;;
leftof | left-of | ds | dockstation | work )
#xrandr --output VGA-1 --mode 1024x768 --left-of "${MAIN_OUTPUT_NAME:=/dev/null}" --output "${MAIN_OUTPUT_NAME:=/dev/null}" --mode 1366x768
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --auto --left-of "${MAIN_OUTPUT_NAME:=/dev/null}" --output "${MAIN_OUTPUT_NAME:=/dev/null}" --auto
printf 'Xrandr for second output left-of main screen'
;;
rightof | right-of | home )
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --auto --right-of "${MAIN_OUTPUT_NAME:=/dev/null}" --output "${MAIN_OUTPUT_NAME:=/dev/null}" --auto
printf 'Xrandr for second output left-of main screen'
;;
above )
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --auto --above "${MAIN_OUTPUT_NAME:=/dev/null}" --output "${MAIN_OUTPUT_NAME:=/dev/null}" --auto
printf 'Xrandr for dual screen with DisplayPort'
;;
out | game )
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --auto --output "${MAIN_OUTPUT_NAME:=/dev/null}" --off
2020-08-21 19:58:25 +02:00
;;
first_off | main_off | laptop_off )
xrandr --output "${MAIN_OUTPUT_NAME:=/dev/null}" --off
;;
* )
printf 'Bad argument, please use [vga|hdmi|ds|work|off]'
2020-08-21 21:09:00 +02:00
exit 1
;;
2014-09-25 23:37:13 +02:00
esac
2020-08-21 21:09:00 +02:00
# }}}
# Update herbstluftWM configuration
2014-09-25 23:37:13 +02:00
herbstclient detect_monitors
herbstclient reload
exit 0