XFCE display switching (dual & single monitor)

It’s been a long time since I don’t write neither in English nor about computer related stuff. It’s not that I stopped doing things but was a bit lazy about posting them here.

Anyway, a few days ago I bout a new monitor tired of working in a 12” screen. I connected it and nothing happened, i mean, there was no signal output so, as usual, I prompted out a terminal and used that wonderful tool called xrandr. Perfect! I worked like a charm until I disconnected it and realized I have no output trough my laptop screen, dammit! and as my key-combination wasn’t working I had to restart it.

I found that xfce4-settins-manager -> keyboard -> application shortcuts were supposed to launch xfce4-display-settings –minimal which did nothing so, instead of that, based on a script I found in the web (see below) I coded a small script, gave it execution permissions and asigned it to my preferred shortcut (XF86Display – Fn+F7 in my Thinkpad X61s).

Keyboard shortcuts

Keyboard shortcuts

Here is the script, working perfectly:

# Based on the script from
# http://quepagina.es/ubuntarium/vamos-a-personalizar-la-tecla-switch-display-de-portatil.html

# Will do a cycling output from state 0 to 2 and use a sound as feedback
# State VGA LVDS Beeps
#   0    0   1      1
#   1    1   0      2   
#   2    1   1      3
#   (back to state 0)   

#For identifying our monitors use xrandr tool and view output
LVDS=LVDS1      # could be another one like: LVDS, LVDS-1, etc
VGA=VGA1        # could be another one like: VGA, VGA-1, etc
EXTRA="--right-of $LVDS" # addtional info while dual display

# Lets check both LVDS and VGA state from the string "$display connected (" 
xrandr | grep -q "$LVDS connected (" && LVDS_IS_ON=0 || LVDS_IS_ON=1
xrandr | grep -q "$VGA connected (" && VGA_IS_ON=0 || VGA_IS_ON=1

# Output switch cycle
if [ $LVDS_IS_ON -eq 1 ] && [ $VGA_IS_ON -eq 1 ]; then
    #Go to state 0 -> just LVDS
    xrandr --output $LVDS --auto 
    xrandr --output $VGA --off
elif [ $LVDS_IS_ON -eq 1 ]; then
    #Go to state 1 -> just VGA
    xrandr --output $LVDS --off
    xrandr --output $VGA --auto 
    beep && beep
elif [ $VGA_IS_ON -eq 1 ]; then
    #Go to state 2 -> both outputs
    xrandr --output $LVDS --auto
    xrandr --output $VGA --auto $EXTRA
    beep && beep && beep
    #This should never be reached but just in case..
    xrandr --output $LVDS --auto 
    beep && beep && beep && beep

As you might already guessed, that script will only work as long as you are logged in a Desktop System (XFCE, Gnome, KDE…) and running the daemon listening to your shortcuts. But there’s no problem, you could also use it from a terminal if you assign it to your acpi event (see this) if you previously know which event is being launched on your combination (use acpid_listen).

Hope it helps!


9 comentarios to “XFCE display switching (dual & single monitor)”

  1. NaN Says:

    Great trick! In my case xfce4-display-settings just keeps waiting an user input to choose the output monitor… something unusable when your main screen does not work properly or It’s broken. Thnks!

    • Jaime Says:

      What version of xfce4-display-settings are you using? That seems nice. Also, I’ve corrected some mistakes from the scripts where the ampersand where substituted by & so now should work perfectly!

  2. NaN Says:

    Hi Jaime, I’m currently using 4.8.3 version. I hope this issue is not related to my ATI video card… the linux driver is a pain in the neck.

    • Jaime Says:

      Hi Nan!

      xfce4-display-settings 4.6.5 (Xfce 4.6.2) here <- Not a man in the edge myself…

      Used to be Debian unstable but moved to stable after some crashes… and definetly hated gnome 3 so moved to something ligther like Xfce which I used to have long time ago and loved.

      • NaN Says:

        When I upgraded to ubuntu 11.10, I had no option to keep using my old Gnome2 so I began to look for something similar (FluxBox, Lxde…). I’m very happy with the look and feel of Xfce and configuration options: simpler & clever. I really hate Unity and Gnome-Shell notebook style. I prefer Synapse to do the quick-launch&search stuff 😀

      • Jaime Says:

        I really like OpenBox as a really lightweigth alternative, combined with Tint2 it’s so beautiful! 🙂

  3. computer table Says:

    It’s a pity you don’t have a donate button! I’d without a doubt donate to this fantastic blog! I suppose for now i’ll settle for bookmarking
    and adding your RSS feed to my Google account. I look
    forward to new updates and will talk about this website with my Facebook group.
    Talk soon!

  4. Aleksandar Says:

    Perfect! Thank you man.

  5. Installing Debian 7 + Xfce 4.8 on ThinkPad X60 | Meteor Monkey Says:

    […] Shortcuts, and associate xrandr –auto to Fn+F7. There is an excellent workaround as suggested here: just create the following sh file, place it somewhere (e.g. /etc/acpi/video-switch.sh) and make it […]


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s