SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-11-11 14:24:51

jmbarnes
#! Junkie
Registered: 2009-05-04
Posts: 250

Cycle Display Setups using xrandr

I've never had much luck getting Fn-key combos working in cycling through display setups (i.e. switch screen between external and internal) so I wrote this little work around that some other might find useful.

I use it to cycle between setups when I dock my laptop at home with my main monitor. It cycles through three options: internal monitor, both monitors, external monitor (and then repeats.) For convince I use it via an openbox hotkey.

It works by checking what monitors are currently connected, and then moving to the next setup. The end runs xmodmap -- this is simply because I use it when I dock the computer and I want to make sure any external keyboards are setup correctly.

Obviously to get this to work right for your setup you'll need to edit the appropriate outputs (LVDS is the internal, external might be VGA-0 instead of DVI-0 etc.) and modes (i.e. resolution). "man xrandr" is your friend here. 


#!/bin/bash
#
#A script to cycle through various display options
#
#

#Check whether internal or external monitors
#are connected and on.
INTERNAL=`xrandr | grep -c "LVDS connected 1400x1050"`
EXTERNAL=`xrandr | grep -c "DVI-0 connected 1680x1050"`

#Some math to make things unique
if [ $EXTERNAL = 1 ]; then
    EXTERNAL=3
fi

STATUS=$(($EXTERNAL+$INTERNAL))
#Possible status values:
#'1' -- indicates internal is on
#'3' -- indicates external is on
#'4' -- indicates both are on
echo "$STATUS"
case $STATUS in
#Current rotation: internal, both, external, repeat

    1 ) #Internal on, switch to both
    xrandr --output DVI-0 --mode 1680x1050 --right-of LVDS
    ;;

    3 ) #External on, switch to laptop
    xrandr --output LVDS --mode 1400x1050
    xrandr --output DVI-0 --off
    ;;

    4 ) #Both on, switch to external
    xrandr --output LVDS --off
    xrandr --output DVI-0 --mode 1680x1050
    ;;

esac

#In case used as part of docking -- rerun xmodmap
xmodmap ~/.Xmodmap

exit 0

IRC: PizzaAndWine     Script bits: Incremental Backup | Sleep Timer

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo