I have a Dell Precision M4300 with a Dell Dock PRO1X running Ubuntu Natty.
When I have the laptop docked the lcd display is off and I use two external monitors however when I undock the laptop it does not switch to the laptop screen. The same happens when I dock the laptop, it does not switch to the external monitors.
If I reboot the laptop it will choose the correct setup but it will not automatically change monitors with Ubuntu running.
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
I have finally put together a complete script setup that will detect my dock status and switch the monitors automatically.
The first thing I did was to get rid of my Xorg.conf as it caused more issues that it solved. Since I am using an nvdia card I eventually found that using disper was the best way to go. I had discounted it before as its standard commands could not achieve my dualview setup but then I found I could create a custom metamode to use with disper.
To create the custom metamode I used the values stored in Xorg.conf along with previous testing with nv-control-dpy and xrandr as a guide. This metamode and other twinview values were added to a file that can be passed to disper through stdin.
Below is a complete breakdown of the scripts and files with their contents.
Create XCreateMouseVoid script:
#!/bin/bash echo "Mouse Void" /opt/XCreateMouseVoid/XCreateMouseVoid 0 1112 1280 88 & /opt/XCreateMouseVoid/XCreateMouseVoid 0 0 1280 88 &
chmod +x ~/.mousevoid
Create Disper settings file:
backend: nvidia associated displays: CRT-0, DFP-0, DFP-1 metamode: CRT-0: 1280x1024_60 @1280x1024 +0+88, DFP-1: 1920x1200 @1920x1200 +1280+0 scaling: default, default, stretched xinerama info order: DFP-1, CRT-0, DFP-0
Create the export dbus session script:
#!/bin/bash # Export the dbus session address on startup so it can be used by any other environment sleep 5 touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
Set to user executable only:
chmod 700 ~/.export_x_info
Then put it in Startup Applications:
Name: X Environment Variables Command: /home/your_user/.export_x_info
Unless you restart you need to run ~/.export_x_info to create the .Xdbus file
Create the udev rule that will run with upon a dock event:
KERNEL=="dock.0", ACTION=="change", RUN+="/usr/local/sbin/dell-dock"
chmod +x /etc/udev/rules.d/81-dell-dock.rules
Create the script that is associated with the udev rule:
#!/bin/sh # wait for the dock state to change sleep 0.5 DOCKED=$(cat /sys/devices/platform/dock.0/docked) case "$DOCKED" in "0") echo "Run UnDocking Script..." /usr/local/sbin/undock ;; "1") echo "Run Docking Script..." /usr/local/sbin/dock ;; esac exit 0
chmod +x /usr/local/sbin/dell-dock
Create the undock script (change your_user to match your user name):
#!/bin/bash USER=your_user export HOME=/home/$USER source $HOME/.Xdbus export DISPLAY=:0 echo "UnDocking Script" echo "Switch primary monitor" sudo -u $USER disper -s echo "Killall XCreateMouseVoid" pkill XCreate echo "Restart conky" pkill conky sudo -u $USER conky &
chmod +x /usr/local/sbin/undock
Create the dock script (change your_user to match your user name):
#!/bin/bash USER=your_user export HOME=/home/$USER source $HOME/.Xdbus export DISPLAY=:0 echo "Docking Script" echo "Switch to Dualview" sudo -u $USER disper -i < $HOME/.disperDocked echo "Start XCreateMouseVoid" pkill XCreate sudo -u $USER $HOME/.mousevoid echo "Restart conky" pkill conky sudo -u $USER conky &
chmod +x /usr/local/sbin/dock
To debug the dock scripts you have to enable udev debug logging:
udevadm control --log-priority=debug
Then open syslog in Log File Viewer
You can use autorandr.
Auto-detect the connect display hardware and load the appropiate X11 setup using xrandr or disper
Automatically select a display configuration based on connected devices
- Using Autorandr for Undocking Goodness in Linux
- A tool for automatically applying RandR configuration when external display is plugged in
- How do I perform easy switching to external monitor
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂