commit - e0985cf2f8f9adc3d009d90c8b186a922823bf27
commit + 0aa694e51e7b089570199fd8b90a5c5ab54123ab
blob - 3d90a3e6fda842d90247965426d1c04a0d85081f (mode 755)
blob + /dev/null
--- dtoogle
+++ /dev/null
-#!/bin/bash
-
-# Quick-n-dirty script to turn external/internal displays on/off with xrandr
-#
-# 2013-14 by Matthias Schmidt <xhr giessen.ccc.de>
-#
-# License GNU GPL
-
-function choose_profile()
-{
- local PROFILE=$1
-
- # Use classic profile mode with -p
- if [ ${NFLAG} -eq 0 ]; then
- case "$PROFILE" in
- # Home profile: Internal on, external extended
- home)
- INTERN="LVDS1"
- EXTERN[0]="HDMI1"
- ;;
- # Work profile: Internal off, both external displays on
- work)
- INTERN="LVDS1"
- EXTERN[1]="HDMI3"
- EXTERN[0]="HDMI2"
- ;;
- # Projector profile: Internal on, external VGA extended
- vga)
- INTERN="LVDS1"
- EXTERN[0]="VGA1"
- ;;
- # -----------------------------------------------------------------------
- # Add your own profiles here.
- # -----------------------------------------------------------------------
- # name)
- # INTERN="LVDS1"
- # EXTERN[0]="VGA1"
- # ...
- # EXTERN[n]="VGAn"
- # ;;
- # -----------------------------------------------------------------------
- *)
- usage
- pr "Profile $PROFILE not found"
- exit 1
- ;;
- esac
- # No profiles, use the connected displays instead
- else
- # Convert string with connected displays to array
- local DARRAY=( ${CONNDIS} )
- # Assume that the first display is the internal one
- INTERN=${DARRAY[0]}
- i=0
- for d in "${DARRAY[@]:1}"; do
- EXTERN[$i]=$d
- i=$(($i + 1))
- done
-
- [ $VERBOSE -eq 1 ] && {
- echo "Internal Display"
- echo -n " "
- pg "${INTERN}"
- echo "External Display(s)"
- echo -n " "
- pg ${EXTERN[@]}
- }
- fi
-
- # Set options deliberatly if toogle mode is on
- if [ ${TFLAG} -eq 1 ]; then
- # 0 = extend
- # 1 = mirror
- # 2 = internal only
- # 3 = external only
- case "${STATE}" in
- 0)
- # Do nothing here
- ;;
- 1)
- CFLAG=1
- ;;
- 2)
- IFLAG=1
- ;;
- 3)
- EFLAG=1
- ;;
- esac
- fi
-
- # Only enable the internal display
- if [ $IFLAG -eq 1 ]; then
- build_xrandr_string "--auto" "--off"
- # Clone screen on all displays
- elif [ $CFLAG -eq 1 ]; then
- RES=`xrandr -q | egrep "^ *[0-9]*x[0-9]*" | awk {'print $1'} | sort | uniq -d | head -1`
- build_xrandr_string "--mode $RES" "--same-as $INTERN"
- # Turn internal display off
- elif [ $EFLAG -eq 1 ]; then
- if [ $RIGHTOF -eq 1 ]; then
- build_xrandr_string "--off" "--auto" "--right-of"
- else
- build_xrandr_string "--off" "--auto" "--left-of"
- fi
- # Internal on and extend screen on all displays by default
- else
- build_xrandr_string "--auto" "--auto" "--right-of"
- fi
-}
-
-function build_xrandr_string()
-{
- local DOINTERN=$1
- local DOEXTERN=$2
- local POSITION=$3
-
- CMD="xrandr --output $INTERN $DOINTERN "
-
- CMDEXT=
- i=0
- for d in ${EXTERN[*]}; do
- if [ $CFLAG -eq 1 ]; then
- CMDEXT="${CMDEXT} --output $d ${DOEXTERN} --mode ${RES}"
- elif [ ! -z $POSITION ]; then
- if [ $i -eq 0 ]; then
- CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION} $INTERN"
- else
- CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION} ${EXTERN[i-1]}"
- fi
- else
- CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION}"
- fi
- i=$(($i + 1))
- done
-
- CMD="$CMD $CMDEXT"
- [ $VERBOSE -eq 1 ] && {
- echo "I'll run the following command:"
- pg "$CMD"
- }
-}
-
-function run_xrandr()
-{
- echo "$CMD $XRANDROPTS" | sh
-}
-
-function read_config()
-{
- if [ -f ${DTCONF} ]; then
- . ${DTCONF}
- fi
-}
-
-function get_last_option()
-{
- # Check if dtoggle saved the last state
- if [ -f ${DTSTATE} ]; then
- . ${DTSTATE}
- fi
-}
-
-function write_last_option()
-{
- echo "STATE=${STATE}" > ${DTSTATE}
-}
-
-function toggle_option()
-{
- STATE=$(((${STATE} + 1) % 4))
-}
-
-function usage()
-{
- echo "`basename $0` [-ceix] [-hmntv] [-lr] -p profile"
- echo
- echo "Display Options:"
- echo " -c Mirror screen on all displays"
- echo " -e Enable external display(s) and disable internal"
- echo " -i Enable only the internal display"
- echo " -N Do not use any profiles. Work with connected displays"
- echo -n " -x Extend screen to all displays "
- pg "[default]"
- echo
- echo "General Options:"
- echo " -h Show this help"
- echo " -m Show all available modes"
- echo " -n Dry run. Do not run xrand. Implies -v"
- echo " -t Toggle different options"
- echo " -v Be more verbose"
- echo
- echo "Position:"
- echo " -l Display n is left of display (n+1)"
- echo -n " -r Display n is right of display (n+1) "
- pg "[default]"
- echo
- echo "Profile:"
- echo " -p profile Enable the specified profile"
- echo
-}
-
-RED='\e[0;31m'
-GREEN='\e[0;32m'
-BLUE='\e[0;34m'
-NC="\e[0;37;40m"
-
-function pg()
-{
- echo -e "${GREEN}${1}${NC}"
-}
-
-function pr()
-{
- echo -e "${RED}${1}${NC}"
-}
-
-CMD=
-PROFILE=
-INTERN=
-RES=
-EXTERN[0]=
-EXTERN[1]=
-EXTERN[2]=
-EXTERN[3]=
-
-# Clone screen on all displays
-CFLAG=0
-# Enable only external displays
-EFLAG=0
-# Enable only the internal display
-IFLAG=0
-# Do not use profiles
-NFLAG=0
-# Toggle different modes
-TFLAG=0
-# Verbosity
-VERBOSE=0
-# Display n is right of display (n+1) [default]
-RIGHTOF=1
-# Additional options for xrandr
-XRANDROPTS=""
-# dtoggle state file
-DTSTATE=$HOME/.dtoogle
-# dtoggle state file
-DTCONF=$HOME/.dtoogle.conf
-# Default status
-STATE=0
-# Connected displays. Stolen from ArchLinux wiki
-CONNDIS=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
-
-while getopts "ciehmnNrlp:vxt" opt; do
- case $opt in
- c)
- CFLAG=1
- ;;
- i)
- IFLAG=1
- ;;
- e)
- EFLAG=1
- ;;
- N)
- NFLAG=1
- ;;
- t)
- TFLAG=1
- ;;
- v)
- VERBOSE=1
- ;;
- n)
- XRANDROPTS="--dryrun"
- VERBOSE=1
- ;;
- r)
- RIGHTOF=1
- ;;
- l)
- RIGHTOF=0
- ;;
- m)
- pg "Connected Displays"
- echo -n " "
- echo $CONNDIS
- pg "Available Modes"
- echo -n " "
- exec xrandr -q
- ;;
- x)
- # Do nothing here since its the default
- ;;
- p)
- [ ! -z "$OPTARG" ] && PROFILE=$OPTARG
- ;;
- h)
- usage
- exit 1
- ;;
- *)
- usage
- pr "Option not found"
- exit 1
- ;;
- esac
-done
-
-if [ $((CFLAG + $IFLAG + $EFLAG)) -gt 1 ]; then
- usage
- pr "Please specify either -c or -e or -i"
- exit 1
-fi
-
-read_config
-
-if [ ${TFLAG} -eq 1 ]; then
- get_last_option
- toggle_option
- write_last_option
-fi
-
-choose_profile $PROFILE
-run_xrandr
-
-exit $?
blob - /dev/null
blob + 3d90a3e6fda842d90247965426d1c04a0d85081f (mode 755)
--- /dev/null
+++ dtoggle
+#!/bin/bash
+
+# Quick-n-dirty script to turn external/internal displays on/off with xrandr
+#
+# 2013-14 by Matthias Schmidt <xhr giessen.ccc.de>
+#
+# License GNU GPL
+
+function choose_profile()
+{
+ local PROFILE=$1
+
+ # Use classic profile mode with -p
+ if [ ${NFLAG} -eq 0 ]; then
+ case "$PROFILE" in
+ # Home profile: Internal on, external extended
+ home)
+ INTERN="LVDS1"
+ EXTERN[0]="HDMI1"
+ ;;
+ # Work profile: Internal off, both external displays on
+ work)
+ INTERN="LVDS1"
+ EXTERN[1]="HDMI3"
+ EXTERN[0]="HDMI2"
+ ;;
+ # Projector profile: Internal on, external VGA extended
+ vga)
+ INTERN="LVDS1"
+ EXTERN[0]="VGA1"
+ ;;
+ # -----------------------------------------------------------------------
+ # Add your own profiles here.
+ # -----------------------------------------------------------------------
+ # name)
+ # INTERN="LVDS1"
+ # EXTERN[0]="VGA1"
+ # ...
+ # EXTERN[n]="VGAn"
+ # ;;
+ # -----------------------------------------------------------------------
+ *)
+ usage
+ pr "Profile $PROFILE not found"
+ exit 1
+ ;;
+ esac
+ # No profiles, use the connected displays instead
+ else
+ # Convert string with connected displays to array
+ local DARRAY=( ${CONNDIS} )
+ # Assume that the first display is the internal one
+ INTERN=${DARRAY[0]}
+ i=0
+ for d in "${DARRAY[@]:1}"; do
+ EXTERN[$i]=$d
+ i=$(($i + 1))
+ done
+
+ [ $VERBOSE -eq 1 ] && {
+ echo "Internal Display"
+ echo -n " "
+ pg "${INTERN}"
+ echo "External Display(s)"
+ echo -n " "
+ pg ${EXTERN[@]}
+ }
+ fi
+
+ # Set options deliberatly if toogle mode is on
+ if [ ${TFLAG} -eq 1 ]; then
+ # 0 = extend
+ # 1 = mirror
+ # 2 = internal only
+ # 3 = external only
+ case "${STATE}" in
+ 0)
+ # Do nothing here
+ ;;
+ 1)
+ CFLAG=1
+ ;;
+ 2)
+ IFLAG=1
+ ;;
+ 3)
+ EFLAG=1
+ ;;
+ esac
+ fi
+
+ # Only enable the internal display
+ if [ $IFLAG -eq 1 ]; then
+ build_xrandr_string "--auto" "--off"
+ # Clone screen on all displays
+ elif [ $CFLAG -eq 1 ]; then
+ RES=`xrandr -q | egrep "^ *[0-9]*x[0-9]*" | awk {'print $1'} | sort | uniq -d | head -1`
+ build_xrandr_string "--mode $RES" "--same-as $INTERN"
+ # Turn internal display off
+ elif [ $EFLAG -eq 1 ]; then
+ if [ $RIGHTOF -eq 1 ]; then
+ build_xrandr_string "--off" "--auto" "--right-of"
+ else
+ build_xrandr_string "--off" "--auto" "--left-of"
+ fi
+ # Internal on and extend screen on all displays by default
+ else
+ build_xrandr_string "--auto" "--auto" "--right-of"
+ fi
+}
+
+function build_xrandr_string()
+{
+ local DOINTERN=$1
+ local DOEXTERN=$2
+ local POSITION=$3
+
+ CMD="xrandr --output $INTERN $DOINTERN "
+
+ CMDEXT=
+ i=0
+ for d in ${EXTERN[*]}; do
+ if [ $CFLAG -eq 1 ]; then
+ CMDEXT="${CMDEXT} --output $d ${DOEXTERN} --mode ${RES}"
+ elif [ ! -z $POSITION ]; then
+ if [ $i -eq 0 ]; then
+ CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION} $INTERN"
+ else
+ CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION} ${EXTERN[i-1]}"
+ fi
+ else
+ CMDEXT="${CMDEXT} --output $d ${DOEXTERN} ${POSITION}"
+ fi
+ i=$(($i + 1))
+ done
+
+ CMD="$CMD $CMDEXT"
+ [ $VERBOSE -eq 1 ] && {
+ echo "I'll run the following command:"
+ pg "$CMD"
+ }
+}
+
+function run_xrandr()
+{
+ echo "$CMD $XRANDROPTS" | sh
+}
+
+function read_config()
+{
+ if [ -f ${DTCONF} ]; then
+ . ${DTCONF}
+ fi
+}
+
+function get_last_option()
+{
+ # Check if dtoggle saved the last state
+ if [ -f ${DTSTATE} ]; then
+ . ${DTSTATE}
+ fi
+}
+
+function write_last_option()
+{
+ echo "STATE=${STATE}" > ${DTSTATE}
+}
+
+function toggle_option()
+{
+ STATE=$(((${STATE} + 1) % 4))
+}
+
+function usage()
+{
+ echo "`basename $0` [-ceix] [-hmntv] [-lr] -p profile"
+ echo
+ echo "Display Options:"
+ echo " -c Mirror screen on all displays"
+ echo " -e Enable external display(s) and disable internal"
+ echo " -i Enable only the internal display"
+ echo " -N Do not use any profiles. Work with connected displays"
+ echo -n " -x Extend screen to all displays "
+ pg "[default]"
+ echo
+ echo "General Options:"
+ echo " -h Show this help"
+ echo " -m Show all available modes"
+ echo " -n Dry run. Do not run xrand. Implies -v"
+ echo " -t Toggle different options"
+ echo " -v Be more verbose"
+ echo
+ echo "Position:"
+ echo " -l Display n is left of display (n+1)"
+ echo -n " -r Display n is right of display (n+1) "
+ pg "[default]"
+ echo
+ echo "Profile:"
+ echo " -p profile Enable the specified profile"
+ echo
+}
+
+RED='\e[0;31m'
+GREEN='\e[0;32m'
+BLUE='\e[0;34m'
+NC="\e[0;37;40m"
+
+function pg()
+{
+ echo -e "${GREEN}${1}${NC}"
+}
+
+function pr()
+{
+ echo -e "${RED}${1}${NC}"
+}
+
+CMD=
+PROFILE=
+INTERN=
+RES=
+EXTERN[0]=
+EXTERN[1]=
+EXTERN[2]=
+EXTERN[3]=
+
+# Clone screen on all displays
+CFLAG=0
+# Enable only external displays
+EFLAG=0
+# Enable only the internal display
+IFLAG=0
+# Do not use profiles
+NFLAG=0
+# Toggle different modes
+TFLAG=0
+# Verbosity
+VERBOSE=0
+# Display n is right of display (n+1) [default]
+RIGHTOF=1
+# Additional options for xrandr
+XRANDROPTS=""
+# dtoggle state file
+DTSTATE=$HOME/.dtoogle
+# dtoggle state file
+DTCONF=$HOME/.dtoogle.conf
+# Default status
+STATE=0
+# Connected displays. Stolen from ArchLinux wiki
+CONNDIS=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
+
+while getopts "ciehmnNrlp:vxt" opt; do
+ case $opt in
+ c)
+ CFLAG=1
+ ;;
+ i)
+ IFLAG=1
+ ;;
+ e)
+ EFLAG=1
+ ;;
+ N)
+ NFLAG=1
+ ;;
+ t)
+ TFLAG=1
+ ;;
+ v)
+ VERBOSE=1
+ ;;
+ n)
+ XRANDROPTS="--dryrun"
+ VERBOSE=1
+ ;;
+ r)
+ RIGHTOF=1
+ ;;
+ l)
+ RIGHTOF=0
+ ;;
+ m)
+ pg "Connected Displays"
+ echo -n " "
+ echo $CONNDIS
+ pg "Available Modes"
+ echo -n " "
+ exec xrandr -q
+ ;;
+ x)
+ # Do nothing here since its the default
+ ;;
+ p)
+ [ ! -z "$OPTARG" ] && PROFILE=$OPTARG
+ ;;
+ h)
+ usage
+ exit 1
+ ;;
+ *)
+ usage
+ pr "Option not found"
+ exit 1
+ ;;
+ esac
+done
+
+if [ $((CFLAG + $IFLAG + $EFLAG)) -gt 1 ]; then
+ usage
+ pr "Please specify either -c or -e or -i"
+ exit 1
+fi
+
+read_config
+
+if [ ${TFLAG} -eq 1 ]; then
+ get_last_option
+ toggle_option
+ write_last_option
+fi
+
+choose_profile $PROFILE
+run_xrandr
+
+exit $?
blob - 785d2e087e7047dd10697a08529a5c7f358c05b4 (mode 644)
blob + /dev/null
--- dtoogle.conf.sample
+++ /dev/null
-# Set your desired profile here
-PROFILE=home
blob - /dev/null
blob + 785d2e087e7047dd10697a08529a5c7f358c05b4 (mode 644)
--- /dev/null
+++ dtoggle.conf.sample
+# Set your desired profile here
+PROFILE=home