9

I have a laptop that's normally docked to a large monitor. When docked, I want to use the large monitor as the primary display, with the laptop screen as a secondary display off to the right. When undocked, the laptop screen is the only display.

XFCE doesn't seem to have that kind of multi-monitor support built in. I found ARandR, which let me set up my monitors the way I want. I can use ARandR to save profiles for docked and undocked configurations (which are really just shell scripts that invoke xrandr).

But how do I get those profiles to apply automatically when the laptop is docked and undocked? Should I try to create a udev rule that detects the docking station? Is there a better way?

  • Haven't tested it yet, but x-on-resize was developed by one of the X developers to do exactly this. – Mikel Mar 22 '14 at 16:24
5

One way is to create an udev rule, but as I wanted something more portable, I have this bash script. It relies on inotifywait support, does not have some kind of loops and is considered efficient.

external-lcd.sh

#!/bin/sh
# inspired of:                                                                                            
#   http://unix.stackexchange.com/questions/4489/a-tool-for-automatically-applying-randr-configuration-   when-external-display-is-p                                                                                
#   http://ozlabs.org/~jk/docs/mergefb/                                                                   
#   http://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes/181543#181543  

export MONITOR2=/sys/class/drm/card0-VGA-1/status                                                         

while inotifywait -e modify,create,delete,open,close,close_write,access $MONITOR2;                        

dmode="$(cat $MONITOR2)"                                                                                  

do                                                                                                        
    if [ "${dmode}" = disconnected ]; then                                                                
         /usr/bin/xrandr --auto                                                                           
         echo "${dmode}"                                                                                  
    elif [ "${dmode}" = connected ];then                                                                  
         /usr/bin/xrandr --output VGA1 --auto --right-of LVDS1                                            
         echo "${dmode}"                                                                                  
    else /usr/bin/xrandr --auto                                                                           
         echo "${dmode}"                                                                                  
    fi                                                                                                    
done 

Don't forget to make the file executable (chmod +x external-lcd.sh). Then just start it whenever you launch your DE.

I am using this on archlinux so I think it should work. You can change xrandr parameters or swap it to use arandr configurations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.