commit ea40b928a936e70e1db17036e68180ad81511a84 from: the xhr date: Thu May 29 17:30:39 2014 UTC Add new -t option for toggeling This options switches between all available options(int, ext, mirror, extend) and saves the state in ~/.dtoggle. commit - 0b2693ea5b37862e2b02c5e1313ec82d5b197298 commit + ea40b928a936e70e1db17036e68180ad81511a84 blob - fd77c0fdc772ae2f210854afc8b3872ccf9ae103 blob + 07059db5cfc036b7a7520dfbfcbd7913d4686e42 --- README.md +++ README.md @@ -1,13 +1,13 @@ dtoggle ======= -Small bash script that uses xrandr to configure internal/external displays. I use it here with Arch Linux and i3 whenever I connect one or more external displays2 +Small bash script that uses xrandr to configure internal/external displays. I use it here with Arch Linux and i3 whenever I connect one or more external displays. Command Line Options -------------------- ``` -dtoogle.sh [-ceix] [-hmnv] [-lr] -p profile +dtoogle [-ceix] [-hmntv] [-lr] -p profile Display Options: -c Clone screen on all displays @@ -16,9 +16,10 @@ Display Options: -x Extend screen to all displays [default] General Options: - -h Show this help + -h Show this help -m Show all available modes -n Dry run. Do not run xrand. Implies -v + -t Toggle different options" -v Be more verbose Position: blob - a9e1b249b00101c566c0d775643ad49c68720dfa blob + de4bc0b27945ecc5ac650a55ede8546d1a871e20 --- dtoogle +++ dtoogle @@ -2,10 +2,28 @@ # Quick-n-dirty script to turn external/internal displays on/off with xrandr # -# 2013 by Matthias Schmidt +# 2013-14 by Matthias Schmidt # # License GNU GPL +function get_last_option() +{ + # Check if dtoggle saved the last state + if [ -f ${DTCONF} ]; then + . ${DTCONF} + fi +} + +function write_last_option() +{ + echo "STATE=${STATE}" > ${DTCONF} +} + +function toggle_option() +{ + STATE=$(((${STATE} + 1) % 4)) +} + function choose_profile() { local PROFILE=$1 @@ -43,6 +61,28 @@ function choose_profile() exit 1 ;; esac + + # 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 @@ -103,7 +143,7 @@ function run_xrandr() function usage() { - echo "`basename $0` [-ceix] [-hmnv] [-lr] -p profile" + echo "`basename $0` [-ceix] [-hmntv] [-lr] -p profile" echo echo "Display Options:" echo " -c Mirror screen on all displays" @@ -116,6 +156,7 @@ function usage() 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:" @@ -158,14 +199,20 @@ CFLAG=0 EFLAG=0 # Enable only the internal display IFLAG=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 +DTCONF=$HOME/.dtoogle +# Default status +STATE=0 -while getopts "ciehmnrlp:vx" opt; do +while getopts "ciehmnrlp:vxt" opt; do case $opt in c) CFLAG=1 @@ -176,6 +223,9 @@ while getopts "ciehmnrlp:vx" opt; do e) EFLAG=1 ;; + t) + TFLAG=1 + ;; v) VERBOSE=1 ;; @@ -223,6 +273,12 @@ if [ $((CFLAG + $IFLAG + $EFLAG)) -gt 1 ]; then exit 1 fi +if [ ${TFLAG} -eq 1 ]; then + get_last_option + toggle_option + write_last_option +fi + choose_profile $PROFILE run_xrandr