disp to support arandr

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

View File

@@ -1,8 +1,11 @@
#!/bin/bash
[[ -z "$DISPLAY" ]] && export DISPLAY=:0
CONFIGFOLDER=$HOME/.config/q-tools-disp/
CONFIG=${CONFIGFOLDER}disp
CONFIG=${CONFIGFOLDER}disp.conf
ARANDR_FOLDER="$HOME/.screenlayout"
TEMPLATE='# configure the display names with "xrandr"
MAIN=eDP-1
ANALOG=VGA-1
@@ -87,7 +90,11 @@ _setup() {
# config
mkdir -p "$CONFIGFOLDER"
[[ -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 }' )
sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG"
}
@@ -107,8 +114,19 @@ _xrandr() {
echo 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() {
echo 'SBL-DISP
echo 'DISPtool
Running without arguments shows display configuration choices
@@ -116,7 +134,7 @@ _help() {
setup Setup display names
all Try to turn all displays on
Following arguments require "setup"
Display configurations:
0 Run "arandr" to setup manually
1 Main display only
@@ -125,11 +143,16 @@ _help() {
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
@@ -147,18 +170,23 @@ if [ -z "$1" ]; then
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'
See further help by running with argument: -h
Settings from arandr:
'
_list_arandr
read -N 1 i
echo ""
fi
case $i in
all) _allon; ;;
setup) _setup; ;;
0) arandr; ;;
"a"*) _allon; ;;
"s"*) _setup; ;;
0) ( arandr & ); ;;
1) _display_main; ;;
2) _display_presentation; ;;
3) _display_workstation; ;;
[4-9]) _run_arandr_script $i; ;;
esac