Automatically set screens

parent b61ad0de
SUBSYSTEM=="drm", ACTION=="change", RUN+="/opt/primtux-eole/refreshVP.sh"
......@@ -23,6 +23,8 @@ then
fi
DIR=`dirname $0`
$DIR/set_screens.sh
sed -i -e 's/lametro.fr/perdu.com/' /etc/conky/conky.conf
echo "Récupération de la clef ssh du serveur"
......
[Desktop Entry]
Exec=gksudo "x-terminal-emulator -e '/opt/primtux-eole/refreshVP.sh'"
Name=Primtux-Eole refresh vp
Terminal=false
#!/bin/bash
# Copyright (C) 2015 Beniamine, David <David.Beniamine@tetras-libre.fr>
# Author: Beniamine, David <David.Beniamine@tetras-libre.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Get rights to access display
user=$(who | grep -v "root" | head -n 1 | cut -d ' ' -f 1)
if [ ! -z "$user" ]
then
export DISPLAY=:0
export XAUTHORITY="/home/$user/.Xauthority"
fi
# Default main screens (external VGA or internal screen)
MAIN_SCREENS="DP-3 VGA-1 LVDS-1 eDP1"
# auto detect main screen
for m in $MAIN_SCREENS
do
if [ ! -z "$(xrandr | grep " connected" | grep $m)" ]
then
MAIN_SCREEN=$m
break
fi
done
if [ -z "$MAIN_SCREEN" ]
then
# No main screen : use the first connected
MAIN_SCREEN=$(xrandr | grep " connected" | head -n 1 | cut -d ' ' -f 1)
fi
screens=$(xrandr | grep " connected" | cut -f 1 -d ' ' \
| sed -e 's/ /\n/g' | grep -v $MAIN_SCREEN)
# Auto detect best resolution
for m in $(xrandr | awk -v pattern="^$MAIN_SCREEN" '/^.* connected/{IN=0} $0 ~ pattern {IN=1} /^ /{if(IN==1){print $1}}')
do
# echo "testing mode $m"
for line in $(xrandr | awk -v pattern="^$MAIN_SCREEN" '/^.* connected/{IN=1} $0 ~ pattern {IN=0} {if(IN==1){print $1}}')
do
# echo "line $line"
if [[ $line =~ [0-9]* ]]
then
# New mode
if [ "$line" == "$m" ]
then
found=1
fi
else
# New screen
if [ $found == 0 ]
then
break
fi
found=0
fi
# echo "Found ? $found"
done
if [ $found == 1 ]
then
mode="--mode $m"
break
fi
done
# echo "mode $mode"
# Primary screen
cmd="xrandr --output $MAIN_SCREEN --auto $mode --rotate normal --primary"
# Add all connected as copy
prev_s=$MAIN_SCREEN
for s in $(echo -e $screens)
do
cmd="$cmd --output $s --auto $mode --same-as $prev_s --rotate normal"
prev_s="$s"
done
# Disable all disconnected screens
screens=$(xrandr | grep " disconnected" | cut -f 1 -d ' ' )
for s in $(echo -e $screens)
do
cmd="$cmd --output $s --off"
done
# Debug
# date >> /var/log/vp.log
# echo $cmd >> /var/log/vp.log
# echo $cmd
# Actually do stuff
$cmd
#!/bin/bash
DIR=`dirname $0`
cp $DIR/40-display.rules /etc/udev/rules.d
systemctl restart udev
echo "Settings lighdm screens"
sed -i -e 's@^#\(display-setup-script=\)@\1 /opt/primtux-eole/refreshVP.sh@' /etc/lightdm/lightdm.conf
......@@ -32,6 +32,7 @@ cp $DIR/session.sh /usr/local/bin/
$DIR/add_session_script.sh
$DIR/create_cifs_mounts.sh
$DIR/set_mime_apps.sh
$DIR/set_screens.sh
if [ $(who | wc -l) -eq 1 ]
then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment