Script to Auto-Enable External Display + FGLRX + Linux

Posted On // 2 comments
I noticed a cool feature of MacOS that automatically enables an external monitor whenever it is connected, and expands the desktop to it. I figured that this had to be possible to do with Linux as well.

I'm running Fedora Core 6 on my work laptop, and I built the following brain-dead script from some stuff I found online. This script is very specific to the FGLRX driver and requires the aticonfig utility. This should be able to be adapted pretty easily to other chipsets or video utilities.

It currently only works as a script running as the user, but I'm trying to make this work as a startup service as well. Hopefully someone will find this useful:


# is a braindead script to autoenable and disable
# the external display and properly set the resolution for an
# expanded desktop.
# This script is currently tied to aticonfig, but should be able
# to be modified to work with other methods to query/(dis|en)able
# the external monitor

# CHECK_INTERVAL is the number of seconds between state checks for the
# monitor

# LCD_MODE is the xrandr screen setting when only the LCD is connected

# CRT_MODE is the xrandr screen setting when both the LCD and CRT
# are connected

export DISPLAY=:0
# Loop Forever...
while true;
# Get the current and connected monitor state
connected=`aticonfig --query-monitor | head -1 | awk -F: '{print $2}' | cut -c2-`
current=`aticonfig --query-monitor | tail -1 | awk -F: '{print $2}' | cut -c2-`

# If there is a mismatch between connected monitors and current config,
# switch to the config for the connected montiors
if [ "$connected" != "$current" ];
case $connected in
"crt1, lvds")
echo Switching to both LCD and CRT
aticonfig --enable-monitor=crt1,lvds
xrandr -s $CRT_MODE
echo Switching to LCD
aticonfig --enable-monitor=lvds
xrandr -s $LCD_MODE
# Unexpected current monitor, change to internal LCD
echo Unknown current mode, switching to LCD
aticonfig --enable-monitor=lvds


Logan Browne said...

This is exactly what I was looking for. I'll let you know if I make any changes or get it working as a service.

GrOG said...

One thing I'm a bit unhappy with for this script is that something it's doing (not sure if it is aticonfig or something else) takes up more CPU that I'd like to see it use. I've tried to collect similar info from /proc/acpi, but that doesn't work very well as it flashes the screen everytime I check it.