disp to support arandr

This commit is contained in:
2018-08-09 11:06:01 +03:00
parent 4fd7599e3d
commit 1864c8acb9

View File

@@ -1,16 +1,19 @@
#!/bin/bash #!/bin/bash
[[ -z "$DISPLAY" ]] && export DISPLAY=:0 [[ -z "$DISPLAY" ]] && export DISPLAY=:0
CONFIGFOLDER=$HOME/.config/q-tools-disp/ CONFIGFOLDER=$HOME/.config/q-tools-disp/
CONFIG=${CONFIGFOLDER}disp CONFIG=${CONFIGFOLDER}disp.conf
ARANDR_FOLDER="$HOME/.screenlayout"
TEMPLATE='# configure the display names with "xrandr" TEMPLATE='# configure the display names with "xrandr"
MAIN=eDP-1 MAIN=eDP-1
ANALOG=VGA-1 ANALOG=VGA-1
DIGITAL=DP-1 DIGITAL=DP-1
# You hay have to change ANALOG/DIGITAL in the outputs, # You hay have to change ANALOG/DIGITAL in the outputs,
# especially for Workstation choices # especially for Workstation choices
# If you want a single display as your workstation setup, # If you want a single display as your workstation setup,
# leave WORKSTATIONRIGHT empty # leave WORKSTATIONRIGHT empty
WORKSTATIONLEFT=$MAIN WORKSTATIONLEFT=$MAIN
WORKSTATIONRIGHT=$DIGITAL WORKSTATIONRIGHT=$DIGITAL
@@ -29,7 +32,7 @@ _display_main() {
xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$MAIN" | while read display; do xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$MAIN" | while read display; do
_xrandr --output $display --off _xrandr --output $display --off
done done
} }
_display_presentation() { _display_presentation() {
@@ -38,7 +41,7 @@ _display_presentation() {
_allon _allon
} }
xrandr | grep " connected" | awk '{ print $1 }' | while read display; do xrandr | grep " connected" | awk '{ print $1 }' | while read display; do
_xrandr --output $display --mode 1024x768 --pos 0x0 --gamma $g:$g:$g _xrandr --output $display --mode 1024x768 --pos 0x0 --gamma $g:$g:$g
done done
} }
_display_workstation() { _display_workstation() {
@@ -46,7 +49,7 @@ _display_workstation() {
echo "ERROR: You do not have configuration yet" echo "ERROR: You do not have configuration yet"
_help _help
} }
if [ -z "$WORKSTATIONLEFT" ];then if [ -z "$WORKSTATIONLEFT" ];then
echo "WORKSTATIONLEFT not defined, turning everything on" echo "WORKSTATIONLEFT not defined, turning everything on"
_allon _allon
fi fi
@@ -54,7 +57,7 @@ _display_workstation() {
echo "WORKSTATIONLEFT=$WORKSTATIONLEFT is not connected, turning everything on" echo "WORKSTATIONLEFT=$WORKSTATIONLEFT is not connected, turning everything on"
_allon _allon
} }
if [ -z "$WORKSTATIONRIGHT" ];then if [ -z "$WORKSTATIONRIGHT" ];then
# Single display setup # Single display setup
_xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g _xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g
xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | while read display; do xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | while read display; do
@@ -71,7 +74,7 @@ _display_workstation() {
xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do
_xrandr --output $display --off _xrandr --output $display --off
done done
} }
_isconnected() { _isconnected() {
xrandr | grep -q "${1} connected" xrandr | grep -q "${1} connected"
@@ -87,7 +90,11 @@ _setup() {
# config # config
mkdir -p "$CONFIGFOLDER" mkdir -p "$CONFIGFOLDER"
[[ -f "$CONFIG" ]] || { [[ -f "$CONFIG" ]] || {
echo "$TEMPLATE" > "$CONFIG" {
echo '#Displays seen by the system:'
xrandr | grep connected | awk '{ print "#"$1": "$2 }'
echo "$TEMPLATE"
} > "$CONFIG"
FIRST=$( xrandr | grep connected | head -n1 | awk '{ print $1 }' ) FIRST=$( xrandr | grep connected | head -n1 | awk '{ print $1 }' )
sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG" sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG"
} }
@@ -107,29 +114,45 @@ _xrandr() {
echo xrandr "$@" echo xrandr "$@"
xrandr "$@" xrandr "$@"
} }
_list_arandr() {
test -d "$ARANDR_FOLDER" || return
ls "$ARANDR_FOLDER" | head -n 6 | awk '{printf(" %d %s\n", NR+3, $0) }'
}
_run_arandr_script() {
script_name=$( ls "$ARANDR_FOLDER"| awk 'NR=='$1'-3 {print $0}' )
[[ -f "$ARANDR_FOLDER/$script_name" ]] && {
echo Running script: $script_name
sh -x "$ARANDR_FOLDER/$script_name"
}
}
_help() { _help() {
echo 'SBL-DISP echo 'DISPtool
Running without arguments shows display configuration choices Running without arguments shows display configuration choices
help Get this help message help Get this help message
setup Setup display names setup Setup display names
all Try to turn all displays on all Try to turn all displays on
Following arguments require "setup" Display configurations:
0 Run "arandr" to setup manually 0 Run "arandr" to setup manually
1 Main display only 1 Main display only
2 Presentation: Main and external screen clones 2 Presentation: Main and external screen clones
3 Workstation: Run your workstation mode, setup in the configuration file 3 Workstation: Run your workstation mode, setup in the configuration file
Second argument to any previous sets the gamma correction value Second argument to any previous sets the gamma correction value
Configuration file: '$CONFIG' Configuration file: '$CONFIG'
Display settings saved with arandr are displayed last:
' '
_list_arandr
exit exit
} }
[[ -f "$CONFIG" ]] && . "$CONFIG" [[ -f "$CONFIG" ]] && . "$CONFIG"
[[ -f "$CONFIG" ]] || CONFIGURED="(You do not have a configuration!)"
# Sub functions exit on their own # Sub functions exit on their own
[[ "$1" = "help" ]] && _help [[ "$1" = "help" ]] && _help
@@ -142,23 +165,28 @@ if [ -z "$1" ]; then
echo "Currently connected displays:" echo "Currently connected displays:"
xrandr | grep --color=always -e ".* connected" -e '.*\*' | awk '{ print $1,$2,$3} ' xrandr | grep --color=always -e ".* connected" -e '.*\*' | awk '{ print $1,$2,$3} '
echo 'Menu choices: echo 'Menu choices:
0 Run "arandr" to setup manually 0 Run "arandr" to setup manually
1 Main display only ('$MAIN') 1 Main display only ('$MAIN')
2 Presentation: Main and all external screen clones (1024x768) 2 Presentation: Main and all external screen clones (1024x768)
3 Workstation: Your personal configration ('$WORKSTATIONLEFT + $WORKSTATIONRIGHT', panel on '$PANEL') 3 Workstation: Your personal configration ('$WORKSTATIONLEFT + $WORKSTATIONRIGHT', panel on '$PANEL')
a All displays on
s Create and edit configuration '$CONFIGURED'
See further help by running with argument: -h See further help by running with argument: -h
Settings from arandr:
' '
_list_arandr
read -N 1 i read -N 1 i
echo "" echo ""
fi fi
case $i in case $i in
all) _allon; ;; "a"*) _allon; ;;
setup) _setup; ;; "s"*) _setup; ;;
0) arandr; ;; 0) ( arandr & ); ;;
1) _display_main; ;; 1) _display_main; ;;
2) _display_presentation; ;; 2) _display_presentation; ;;
3) _display_workstation; ;; 3) _display_workstation; ;;
[4-9]) _run_arandr_script $i; ;;
esac esac