Thanks to lunatico for the clue:
Originally Posted by
lunatico
I haven't tried this with 11.04 and I don't think I ever will because I just don't like it and find it very buggy. To debug this run the command below and undock to see what you get:
Code:
udevadm monitor --environment
And see if the event you get when pressing the undock button matches your rule..
I'm running a Dell Latitude E6400 with Ubuntu 11 and the earlier pieces helped but udev wasn't firing into my log file. Monitoring udevadm monitor --environment by running
sudo udevadm monitor --environment >> device_event.log
found I didn't have those events. So I followed the examples and rewrote the rules. The end result is a reconfiguration of the display when I dock or undock. It merges the technique from http://morgancollett.wordpress.com/2...ew-and-xrandr/ to setup the xorg.conf with multiple modes. Then I use the event to change the modes.
================================================== ==================
Configuration of docking to change the Nvidia Twinview settings
1. First configure the system for dual monitors (usually
Code:
sudo nvidia-settings
), then use sudo gedit /etc/X11/xorg.conf go to the Screen section it will appear like the example
Code:
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "TwinView" "1"
Option "TwinViewXineramaInfoOrder" "DFP-1"
Option "metamodes" "DFP-0: nvidia-auto-select +1920+0, DFP-1: nvidia-auto-select +0+0
SubSection "Display"
Depth 24
EndSubSection
EndSection
2. Modify the line for the metamodes by adding a deliminator ; and duplicating the settings for the primary (laptop monitor). The secondary monitor will be set to null as below.
Code:
Option "metamodes" "DFP-0: nvidia-auto-select +1920+0, DFP-1: nvidia-auto-select +0+0;DFP-0: nvidia-auto-select +0+0, DFP-1: null"
3. Next open a terminal and test the alternate monitor settings.
a) In a command prompt type
and press enter to change to single monitor.
The system will change to a single monitor without restarting the X environment.
b) Type to change back to dual monitors
With this configured we just need to capture the change of the docking status using the techniques in this thread.
Capture Docking Event
1) Hardware environments vary so you will need to determine the events to monitor
a) type sudo udevadm monitor –environment >> ~/device_eventlog.log at a command prompt. I prefer the file becasue it's easier to parse.
b) Change the hardware you wish to monitor (undock, unplug, depower..)
c) In the terminal press CTRL+c to terminate the udevadm monitor –environment command.
2) Examine the ~/device_eventlog.log it will display all the add, change and removes with details for each device.
KERNEL[1318277278.266250] add /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4.2/1-4.2:1.0/0003:413C:2101.0017/hidraw/hidraw2 (hidraw)
UDEV_LOG=3
ACTION=add
SUBSYSTEM=block
DEVNAME= hidraw2
DEVTYPE=disk
SEQNUM=2585
MAJOR=8
MINOR=16
3) Hook the docking event by writing a rule in the /lib/udev/rules.d folder as such as
/lib/udev/rules.d/85-Latitude-E6400.rules with a content of:
Code:
KERNEL=="hidraw2", DEVNAME=="hidraw2",ACTION=="add", RUN+="/etc/dell/dock.sh 1"
KERNEL=="hidraw2", DEVNAME=="hidraw2",ACTION=="remove", RUN+="/etc/dell/dock.sh 0"
4) Finally create the event to handle docking and undocking /etc/dell/dock.sh script
Code:
#!/bin/sh
# wait for the dock state to change
sleep 1
# Get the actual logged in user (TESTED). If there is a chance that more
# than one user(name) is logged in, you have to sorround the
# rest of the code with
# for user in "${THEUSER}"; do [... the rest of code ...]; done
# and change all accurrences of ${THEUSER} with ${user}
# The latter is NOT TESTED
THEUSER="$(last | head | grep -v ":0.0" | grep -v pts | grep -v system | grep -m1 still | cut -d" " -f1 | uniq)"
#This runs so that root can run the following command under the user's environment
source /home/${THEUSER}/.Xdbus
case "$1" in
"0")
#undocked event
DISPLAY=:0.0 su ${THEUSER} -c "xrandr -s 1"
# Removed echo 'undocked event' >> /etc/dell/docking.log
logger 'undocked event'
;;
"1")
#docked event
DISPLAY=:0.0 su ${THEUSER} -c "xrandr -s 0"
# removed echo 'docked event' >> /etc/dell/docking.log
logger 'docked event'
;;
esac
exit 0
Again thanks to lunatico and everyone for this information
Bookmarks