Clean first_output_mode management

This commit is contained in:
gardouille 2024-03-27 08:01:45 +01:00
parent fa598cb48d
commit fc144471a7
Signed by: gardouille
GPG Key ID: E759BAA22501AF32

25
ecran
View File

@ -20,6 +20,7 @@ readonly COLOR_DEBUG="${PURPLE}"
## It can be forced here or the script will try to discover it's name
#readonly SECOND_OUTPUT_NAME
readonly PRIMARY_OUTPUT_MODE="--auto"
readonly SECOND_OUTPUT_MODE="--auto"
# }}}
@ -59,6 +60,14 @@ The second output is: ${SECOND_OUTPUT_NAME}."
fi
## }}}
## Primary output mode {{{
### If primary_output_mode wasn't defined (~/.config/xrandr.conf file, var env…)
### Use default value
### Then use ${primary_output_mode} variable without "" to be able to use it as xrandr's option
if [ -z "${primary_output_mode}" ]; then
primary_output_mode=${PRIMARY_OUTPUT_MODE}
fi
## }}}
## Second output mode {{{
### If second_output_mode wasn't defined (~/.config/xrandr.conf file, var env…)
### Use default value
@ -147,9 +156,9 @@ case "${1}" in
primary | off )
## TODO: One command to enable primary screen and a loop to disable all other connected output
if [ -n "${PRIMARY_OUTPUT_MODE}" ]; then
xrandr --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode "${PRIMARY_OUTPUT_MODE}"
xrandr --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
else
xrandr --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --auto
xrandr --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
fi
if [ -n "${SECOND_OUTPUT_NAME}" ]; then xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off ; fi
printf "%b\n" 'Enable only primary output'
@ -157,25 +166,25 @@ case "${1}" in
leftof | left-of | ds | dock | dockstation | work )
#xrandr --output VGA-1 --mode 1024x768 --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode 1366x768
if [ -n "${PRIMARY_OUTPUT_MODE}" ]; then
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode "${PRIMARY_OUTPUT_MODE}"
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
else
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --auto
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
fi
printf "%b\n" 'Xrandr for second output left-of primary screen'
;;
rightof | right-of | home )
if [ -n "${PRIMARY_OUTPUT_MODE}" ]; then
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --right-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode "${PRIMARY_OUTPUT_MODE}"
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --right-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
else
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --right-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --auto
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --right-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
fi
printf "%b\n" 'Xrandr for second output left-of primary screen'
;;
above )
if [ -n "${PRIMARY_OUTPUT_MODE}" ]; then
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --above "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode "${PRIMARY_OUTPUT_MODE}"
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --above "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
else
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --above "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --auto
xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" ${second_output_mode} --above "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" ${primary_output_mode}
fi
printf "%b\n" 'Xrandr for second output above primary screen'
;;