Unverified Commit 48729ed5 authored by David Beniamine's avatar David Beniamine
Browse files

Fix #67

+ Fix detection of no screens plugged
+ Fix detection of identical commands
+ Add quick option to log refreshVP.sh
parent 40eed035
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -17,6 +17,14 @@
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Get rights to access display
DEBUG=false
log(){
    if $DEBUG
    then
        echo "$@" >> /var/log/vp.log
    fi
}
log  "starting VP $(date)"
user=$(who | grep -v "root" | head -n 1 | cut -d ' ' -f 1)
if [ ! -z "$user" ]
then
@@ -52,12 +60,15 @@ then
	# No main screen : use the first connected
	MAIN_SCREEN=$(xrandr | grep " connected" | head -n 1 | cut -d ' ' -f 1)
fi
log  "MAIN_SCREEN '$MAIN_SCREEN'"

screens=$(xrandr | grep " connected" | cut -f 1 -d ' ' \
    | sed -e 's/ /\n/g' | grep -v $MAIN_SCREEN)

if [ "$(echo -e "$screens\n$MAIN_SCREEN" | wc -l)" -eq 0 ]
log  "SCREENS '$screens'"
if [ -z "$screens$MAIN_SCREEN" ]
then
    log  "noscreens exiting on $(date)"
    exit
fi

@@ -103,6 +114,7 @@ done

# Primary screen
cmd="xrandr --output $MAIN_SCREEN --auto --mode $mode --rotate normal --primary"
log  "command $cmd"

# Add all connected as copy
prev_s=$MAIN_SCREEN
@@ -111,6 +123,7 @@ do
    cmd="$cmd --output $s --auto --mode $mode --same-as $prev_s --rotate normal"
    prev_s="$s"
done
log  "command after all outputs $cmd"

# Disable all disconnected screens
screens=$(xrandr | grep " disconnected" | cut -f 1 -d ' ' )
@@ -118,13 +131,17 @@ for s in $(echo -e $screens)
do
	cmd="$cmd --output $s --off"
done
log  "command after all offs $cmd"

# Debug
# date >> /var/log/vp.log
# echo $cmd >>  /var/log/vp.log
[ "$cmd" == "$(cat /tmp/vp)" ] && exit
log  "old cmd '$(cat /tmp/vp)'"
log  "new cmd '$cmd'"
if [ "$cmd" == "$(cat /tmp/vp)" ]
then
	log  "No cmd change, exiting on $(date)"
	exit
fi
echo $cmd > /tmp/vp
# echo $cmd

# Actually do stuff
$cmd
log  "Runned $cmd, exiting on $(date)"