#!/bin/bash [[ -z "$DISPLAY" ]] && export DISPLAY=:0 CONFIGFOLDER=$HOME/.config/q-tools-disp/ CONFIG=${CONFIGFOLDER}disp.conf ARANDR_FOLDER="$HOME/.screenlayout" TEMPLATE='# configure the display names with "xrandr" MAIN=eDP-1 ANALOG=VGA-1 DIGITAL=DP-1 # You hay have to change ANALOG/DIGITAL in the outputs, # especially for Workstation choices # If you want a single display as your workstation setup, # leave WORKSTATIONRIGHT empty WORKSTATIONLEFT=$MAIN WORKSTATIONRIGHT=$DIGITAL ' _allon() { _list_connected | while read display; do _xrandr --output $display --auto done exit } _display_main() { [[ -f "$CONFIG" ]] || { echo "ERROR: You do not have configuration yet" _help } _isconnected "$MAIN" || { echo "Display MAIN=$MAIN is not connected, trying to turn all on. Please check your setup: $CONFIG" _allon } _xrandr --output "$MAIN" --auto --gamma $g:$g:$g _list_all | grep -v "$MAIN" | while read display; do _xrandr --output $display --off done } _display_presentation() { _isconnected "$MAIN" || { echo "Display MAIN=$MAIN is not connected, trying to turn all on. Please check your setup: $CONFIG" _allon } _list_connected | while read display; do _xrandr --output $display --mode 1024x768 --pos 0x0 --gamma $g:$g:$g done } _display_workstation() { [[ -f "$CONFIG" ]] || { echo "ERROR: You do not have configuration yet" _help } if [ -z "$WORKSTATIONLEFT" ];then echo "WORKSTATIONLEFT not defined, turning everything on" _allon fi _isconnected "$WORKSTATIONLEFT" || { echo "WORKSTATIONLEFT=$WORKSTATIONLEFT is not connected, turning everything on" _allon } if [ -z "$WORKSTATIONRIGHT" ];then # Single display setup _xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g _list_all | grep -v "$WORKSTATIONLEFT" | while read display; do _xrandr --output $display --off done return fi # Two display setup _isconnected "$WORKSTATIONRIGHT" || { echo "WORKSTATIONRIGHT=$WORKSTATIONRIGHT is not connected, turning everything on" _allon } _xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g --output "$WORKSTATIONRIGHT" --auto --gamma $g:$g:$g --right-of "$WORKSTATIONLEFT" _list_all | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do _xrandr --output $display --off done } _isconnected() { xrandr | grep -q "${1} connected" } _list_all() { xrandr | grep -e " connected" -e " disconnected" | awk '{ print $1 }' } _list_connected() { xrandr | grep -e " connected" | awk '{ print $1 }' } _setup() { # config mkdir -p "$CONFIGFOLDER" [[ -f "$CONFIG" ]] || { { echo '#Displays seen by the system:' xrandr | grep connected | awk '{ print "#"$1": "$2 }' echo "$TEMPLATE" } > "$CONFIG" FIRST=$( _list_all | head -n1 ) sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG" } echo '# Current configuration:' echo $CONFIG echo ====================== cat "$CONFIG" echo ====================== . "$CONFIG" echo '# Displays at this computer:' xrandr | grep -e '.*connected' -e '.*\*' --color=always xdg-open "$CONFIG" echo "Add something to your LXPanel to create the configuration (launcher icon etc...)" exit } _xrandr() { echo xrandr "$@" xrandr "$@" } _list_arandr() { [[ -d "$ARANDR_FOLDER" ]] || { _arandr_empty return } [[ $(ls -A "$ARANDR_FOLDER") ]] || { _arandr_empty return } ls -p1 "$ARANDR_FOLDER" | grep -v / | head -n 6 | awk '{printf(" %d %s\n", NR+3, $0) }' } _run_arandr_script() { script_name=$( ls -p1 "$ARANDR_FOLDER" | grep -v / | awk 'NR=='$1'-3 {print $0}' ) [[ -f "$ARANDR_FOLDER/$script_name" ]] && { echo Running script: $script_name sh -x "$ARANDR_FOLDER/$script_name" } } _arandr_empty() { echo " [No arandr scripts]" } _help() { echo 'DISPtool Running without arguments shows display configuration choices help Get this help message setup Setup display names all Try to turn all displays on Display configurations: 0 Run "arandr" to setup manually 1 Main display only 2 Presentation: Main and external screen clones 3 Workstation: Run your workstation mode, setup in the configuration file Second argument to any previous sets the gamma correction value Configuration file: '$CONFIG' Display settings saved with arandr are displayed last ' _list_arandr exit } [[ -f "$CONFIG" ]] && . "$CONFIG" [[ -f "$CONFIG" ]] || CONFIGURED="(You do not have a configuration!)" # Sub functions exit on their own [[ "$1" = "help" ]] && _help [[ "$1" = "--help" ]] && _help [[ "$1" = "-h" ]] && _help g=1 [[ -z "$2" ]] || g=$2 i=$1 if [ -z "$1" ]; then echo "Currently connected displays:" xrandr | grep --color=always -e ".* connected" -e '.*\*' | awk '{ print $1,$2,$3} ' echo 'See further help by running with argument: -h 0 Run "arandr" to setup manually 1 Main display only ('$MAIN') 2 Presentation: Main and all external screen clones (1024x768) 3 Workstation: Your personal configration ('$WORKSTATIONLEFT + $WORKSTATIONRIGHT', panel on '$PANEL') a All displays on s Create and edit configuration '$CONFIGURED' Settings by arandr:' _list_arandr read -N 1 i echo "" fi case $i in "a"*) _allon; ;; "s"*) _setup; ;; 0) ( arandr & ); ;; 1) _display_main; ;; 2) _display_presentation; ;; 3) _display_workstation; ;; [4-9]) _run_arandr_script $i; ;; esac