import disp from another project
This commit is contained in:
209
skel/disp
209
skel/disp
@@ -1,79 +1,164 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# configure the display names with "xrandr"
|
[[ -z "$DISPLAY" ]] && export DISPLAY=:0
|
||||||
LAPTOP=LVDS1
|
CONFIGFOLDER=$HOME/.config/q-tools-disp/
|
||||||
ANALOG=VGA1
|
CONFIG=${CONFIGFOLDER}disp
|
||||||
DIGITAL=HDMI1
|
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
|
# You hay have to change ANALOG/DIGITAL in the outputs,
|
||||||
# The choices may be the same!
|
# especially for Workstation choices
|
||||||
PRESENTATION=$ANALOG
|
# If you want a single display as your workstation setup,
|
||||||
WORKSTATION=$ANALOG
|
# leave WORKSTATIONRIGHT empty
|
||||||
|
WORKSTATIONLEFT=$MAIN
|
||||||
|
WORKSTATIONRIGHT=$DIGITAL
|
||||||
|
'
|
||||||
|
|
||||||
#Helper functions when using lxpanel (Lubuntu / LXDE)
|
_display_main() {
|
||||||
function reset_lxpanel() {
|
[[ -f "$CONFIG" ]] || {
|
||||||
if lxpanel_running; then
|
echo "ERROR: You do not have configuration yet"
|
||||||
PROFILE=$( lxpanel_profile )
|
_help
|
||||||
sed -i -e 's,edge=.*,edge=bottom,' -e "s,allign=.*,allign=left," -e "s,widthtype=.*,widthtype=percent," -e "s,width=.*,width=100," $HOME/.config/lxpanel/${PROFILE}/panels/panel
|
}
|
||||||
|
_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
|
||||||
|
xrandr | grep " connected" | awk '{ print $1 }' | 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
|
||||||
|
}
|
||||||
|
xrandr | grep " connected" | awk '{ print $1 }' | 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
|
fi
|
||||||
}
|
_isconnected "$WORKSTATIONLEFT" || {
|
||||||
|
echo "WORKSTATIONLEFT=$WORKSTATIONLEFT is not connected, turning everything on"
|
||||||
function side_lxpanel() {
|
_allon
|
||||||
if lxpanel_running; then
|
}
|
||||||
PROFILE=$( lxpanel_profile )
|
if [ -z "$WORKSTATIONRIGHT" ];then
|
||||||
sleep 1
|
# Single display setup
|
||||||
LAPTOPWIDTH=$( xrandr -q | grep $WORKSTATION | cut -d" " -f3 | cut -dx -f1 )
|
_xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g
|
||||||
sed -i -e 's,edge=.*,edge=bottom,' -e "s,allign=.*,allign=$1," -e "s,widthtype=.*,widthtype=pixel," -e "s,width=.*,width=$LAPTOPWIDTH," $HOME/.config/lxpanel/${PROFILE}/panels/panel
|
xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | while read display; do
|
||||||
echo "Warning: if LAPTOP has more pixels in the vertical direction, panel is invisible! change configuration of this script, and/or current setup ( lxpanelctl config )"
|
_xrandr --output $display --off
|
||||||
|
done
|
||||||
|
return
|
||||||
fi
|
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"
|
||||||
|
xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do
|
||||||
|
_xrandr --output $display --off
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
_isconnected() {
|
||||||
|
xrandr | grep -q "${1} connected"
|
||||||
|
}
|
||||||
|
_allon() {
|
||||||
|
xrandr | grep " connected" | awk '{ print $1 }' | while read display; do
|
||||||
|
_xrandr --output $display --auto
|
||||||
|
done
|
||||||
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
function restart_lxpanel() {
|
_setup() {
|
||||||
if lxpanel_running; then
|
# config
|
||||||
LXCMD=$( ps -ocommand= --pid $( pgrep -u $USER -n lxpanel ) )
|
mkdir -p "$CONFIGFOLDER"
|
||||||
lxpanelctl restart
|
[[ -f "$CONFIG" ]] || {
|
||||||
sleep 2
|
echo "$TEMPLATE" > "$CONFIG"
|
||||||
lxpanel_running || {
|
FIRST=$( xrandr | grep connected | head -n1 | awk '{ print $1 }' )
|
||||||
echo "lxpanel segfaulted. restarting..."
|
sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG"
|
||||||
nohup $LXCMD &> /dev/null &
|
}
|
||||||
}
|
echo '# Current configuration:'
|
||||||
fi
|
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 "$@"
|
||||||
|
}
|
||||||
|
_help() {
|
||||||
|
echo 'SBL-DISP
|
||||||
|
|
||||||
|
Running without arguments shows display configuration choices
|
||||||
|
|
||||||
|
help Get this help message
|
||||||
|
setup Setup display names
|
||||||
|
all Try to turn all displays on
|
||||||
|
|
||||||
|
Following arguments require "setup"
|
||||||
|
|
||||||
|
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'
|
||||||
|
'
|
||||||
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
function lxpanel_running() {
|
[[ -f "$CONFIG" ]] && . "$CONFIG"
|
||||||
pgrep -u $USER -n lxpanel &> /dev/null
|
|
||||||
}
|
|
||||||
function lxpanel_profile() {
|
|
||||||
ps -ocommand= --pid $( pgrep -u $USER -n lxpanel ) | sed 's/.*--profile \([^ ]\+\).*/\1/'
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "$1" ]
|
# Sub functions exit on their own
|
||||||
then
|
[[ "$1" = "help" ]] && _help
|
||||||
echo 'Choose display mode:
|
[[ "$1" = "--help" ]] && _help
|
||||||
1) Laptop only
|
[[ "$1" = "-h" ]] && _help
|
||||||
2) Presentation (2nd arg for gamma correction)
|
g=1
|
||||||
3) Workstation: 2nd screen on the right
|
[[ -z "$2" ]] || g=$2
|
||||||
4) Workstation: 2nd screen on the left
|
i=$1
|
||||||
5) Workstation: external display only
|
if [ -z "$1" ]; then
|
||||||
|
echo "Currently connected displays:"
|
||||||
|
xrandr | grep --color=always -e ".* connected" -e '.*\*' | awk '{ print $1,$2,$3} '
|
||||||
|
echo 'Menu choices:
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
See further help by running with argument: -h
|
||||||
'
|
'
|
||||||
read -N 1 i
|
read -N 1 i
|
||||||
echo ""
|
echo ""
|
||||||
else
|
|
||||||
i=$1
|
|
||||||
fi
|
|
||||||
if [ -z "$2" ]
|
|
||||||
then g=1
|
|
||||||
else g=$2
|
|
||||||
fi
|
|
||||||
oppos=left
|
|
||||||
if [ "$2" = "left" ]
|
|
||||||
then oppos=right
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $i in
|
case $i in
|
||||||
1) xrandr --output $LAPTOP --auto --gamma $g:$g:$g --output $PRESENTATION --off --output $WORKSTATION --off; reset_lxpanel; ;;
|
all) _allon; ;;
|
||||||
2) xrandr --output $LAPTOP --mode 1024x768 --pos 0x0 --output $PRESENTATION --mode 1024x768 --pos 0x0 --gamma $g:$g:$g; reset_lxpanel; ;;
|
setup) _setup; ;;
|
||||||
3) xrandr --output $LAPTOP --auto --output $WORKSTATION --auto --right-of $LAPTOP; side_lxpanel right; ;;
|
0) arandr; ;;
|
||||||
4) xrandr --output $LAPTOP --auto --output $WORKSTATION --auto --left-of $LAPTOP; side_lxpanel left; ;;
|
1) _display_main; ;;
|
||||||
5) xrandr --output $LAPTOP --off --output $WORKSTATION --auto; reset_lxpanel; ;;
|
2) _display_presentation; ;;
|
||||||
|
3) _display_workstation; ;;
|
||||||
esac
|
esac
|
||||||
restart_lxpanel
|
|
||||||
|
|||||||
Reference in New Issue
Block a user