I have currently installed Ubuntu 16.04 LTS on my Lenovo Yoga2 Pro laptop. This is my main work computer so I need two external monitors to work off of. Now setting the displays in Ubuntu works but dont stick 100% of the time. I also seem to have some issues with the external displays screen position overlaps some times. Using xrandr you can fix this issue really quick in the terminal. This gets old, so I wrote a bash script to help setup everything and run on session startup. Ubuntu will not allow you to run .sh files from the desktop anymore so one work around is to make a .desktop icon and point it to your shell script. Well I didn't like this approach so I found a shell script compiler called SHC (Generic Shell Script Compiler) by a guy names Jahidul Hamid
After converting the shell script to a binary I was able to setup the script in my startup and everything worked well. Below is a copy of the Bash shell script I have written. I have adapted a ini file that is created in the users home directory under .config named dplink.ini. This ini file allows you to edit the way the script works. The ini file is created after the first launch of the application if one doesn't exists.
~/.config/dplink.ini
[settings]
LAPTOPMODE=off
MNTR1_RES=1920x1080
MNTR2_RES=1920x1080
MNTR_PRIMARY=1
DISPLAY1=DVI-I-1
DISPLAY2=DVI-I-2
LAPTOPDISPLAY=eDP1
MNTRrightofMTR=1
How do I configure the ini file?
- LAPTOPMODE:
switches are off/on, this will turn off or on the laptop screen (default is off)
- MNTR1_RES:
set the resolution of your external monitor 1 (default is 1920x1080)
- MNTR2_RES:
set the resolution of your external monitor 2 (default is 1920x1080)
- MNTR_PRIMARY:
switch is 1 or 2, this sets the primary external display
- DISPLAY1:
Set monitor 1 name from the output of xrandr -q (default is DVI-I-1)
-DISPLAY2:
Set monitor 2 name from the output of xrandr -q (default is DVI-I-2)
- LAPTOPDISPLAY:
Set laptop display name from the output of xrandr -q (default is eDP1)
-MNTRrightofMTR:
Switch is 1 or 2, this will place monitor 1 to the right of monitor 2 or vi verses. (default is 1)
DisplayLink_Setup.sh
#!/bin/bash
# Created by Derrick Rose
# digitalexpl0it.com
# Setup Color Outputs
RED='\033[1;31m'
CYAN='\033[1;36m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get Linux Distrubution
Dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'`
# MOTD I guess you can call it :)
printf "${YELLOW}[DisplayLink Dock Multiple Monitor Setup]${NC}\n"
printf "This tool is design to be used with Ubuntu 16.04 and higher\n"
printf "and with a USB DisplayLink Dock and laptop\n"
printf "\n"
printf "Tested with the following:\n"
printf "LAPTOP: Lenovo yoga 2 pro\n"
printf "DOCK: StarTech USB 3 Dock\n\n"
#check for ubuntu distrobution
if [ "$Dist" == "Ubuntu" ]; then
printf "Ubuntu detected...\n"
else
printf "${RED}You must be using Ubuntu 16 or higher${NC} \nScript will now end.\n"
notify-send -i "Error" \
"You must be using Ubuntu 16 or higher" \
"Script will now end"
exit;
fi
# Check for settings file
if [ ! -f "$HOME/.config/dplink.ini" ]; then
printf "creating config file in $HOME/.config/dplink.ini\n"
touch "$HOME/.config/dplink.ini"
echo "[settings]" >> "$HOME/.config/dplink.ini"
echo "LAPTOPMODE=off" >> "$HOME/.config/dplink.ini"
echo "MNTR1_RES=1920x1080" >> "$HOME/.config/dplink.ini"
echo "MNTR2_RES=1920x1080" >> "$HOME/.config/dplink.ini"
echo "MNTR_PRIMARY=1" >> "$HOME/.config/dplink.ini"
echo "DISPLAY1=DVI-I-1" >> "$HOME/.config/dplink.ini"
echo "DISPLAY2=DVI-I-2" >> "$HOME/.config/dplink.ini"
echo "LAPTOPDISPLAY=eDP1" >> "$HOME/.config/dplink.ini"
echo "MNTRrightofMTR=1" >> "$HOME/.config/dplink.ini"
fi
# Get ini variables
LAPTOPMODE=$(awk -F "=" '/LAPTOPMODE/ {print $2}' $HOME/.config/dplink.ini)
MNTR1_RES=$(awk -F "=" '/MNTR1_RES/ {print $2}' $HOME/.config/dplink.ini)
MNTR2_RES=$(awk -F "=" '/MNTR2_RES/ {print $2}' $HOME/.config/dplink.ini)
MNTR_PRIMARY=$(awk -F "=" '/MNTR1_PRIMARY/ {print $2}' $HOME/.config/dplink.ini)
DISPLAY1=$(awk -F "=" '/DISPLAY1/ {print $2}' $HOME/.config/dplink.ini)
DISPLAY2=$(awk -F "=" '/DISPLAY2/ {print $2}' $HOME/.config/dplink.ini)
LAPTOPDISPLAY=$(awk -F "=" '/LAPTOPDISPLAY/ {print $2}' $HOME/.config/dplink.ini)
MNTRrightofMTR=$(awk -F "=" '/MNTRrightofMTR/ {print $2}' $HOME/.config/dplink.ini)
# Check for DisplayLInk Device is connected
Get_DLINK=$(lsusb | grep DisplayLink | awk '{ print $7 }')
if [ "$Get_DLINK" != "DisplayLink" ]; then
printf "${RED}DisplayLink Device Not Connected!${NC}\n"
printf "If the DisplayLink dock is connected\n"
printf "Please install the DisplayLink Drivers from\n"
printf "${CYAN}http://www.displaylink.com/downloads/ubuntu/${NC}\n"
printf "and try this script again.\n"
notify-send -i "Error" \
"DisplayLink Device Not Connected! If the DisplayLink dock is connected please install the DisplayLink Drivers from" \
"http://www.displaylink.com/downloads/ubuntu/"
exit
else
printf "DisplayLink Device Found!\n"
printf "Setting up Displays...\n"
# Sleep for 10 seconds
sleep 10
# Turn off laptop Screen
if [ $LAPTOPMODE = "off" ]; then
printf "[${GREEN}*${NC}] Turning off Laptop Display $LAPTOPDISPLAY\n"
xrandr --output $LAPTOPDISPLAY --off
fi
# Setup Resolution for 2 screens
printf "[${GREEN}*${NC}] Setting $DISPLAY1 to resolution $MNTR1_RES\n"
xrandr --output $DISPLAY1 --mode $MNTR1_RES
printf "[${GREEN}*${NC}] Setting $DISPLAY2 to resolution $MNTR2_RES\n"
xrandr --output $DISPLAY2 --mode $MNTR2_RES
# Set primary monitor
if [ "$MNTR_PRIMARY" = "1" ]; then
printf "[${GREEN}*${NC}] Setting Primary Monitor on $DISPLAY1\n"
xrandr --output $DISPLAY1 --primary
else
printf "[${GREEN}*${NC}] Setting Primary Monitor on $DISPLAY2\n"
xrandr --output $DISPLAY2 --primary
fi
# Set right screen
if [ "$MNTRrightofMTR" = "1" ]; then
printf "[${GREEN}*${NC}] Setting monitor $DISPLAY2 right of $DISPLAY1\n"
xrandr --output $DISPLAY2 --right-of $DISPLAY1
else
printf "[${GREEN}*${NC}] Setting monitor $DISPLAY1 right of $DISPLAY2\n"
xrandr --output $DISPLAY1 --right-of $DISPLAY2
fi
printf "\nDisplayLink Device has been setup\n"
printf "Monitors should now be working\n\n"
notify-send -i "Success" \
"DisplayLink Device has been setup" \
"Monitors should now be working"
printf "${CYAN}To configure this script please open${NC}\n"
printf "$HOME/.config/dplink.ini\n"
exit
fi
To download the binary version please click here