Skip to content

Commit

Permalink
fix: notify; -on; --clone. improve: force workaround is now used in u…
Browse files Browse the repository at this point in the history
…pdate_outputs_all, avoiding unnecessary calls
  • Loading branch information
geyslan committed Jan 15, 2015
1 parent 600bd15 commit 062647d
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions xrasengan
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Or
$0 -p DisplayPort-0"

invalid_argument() {
echo "$@"
notify "$@"
exit 22
}

Expand All @@ -109,16 +109,8 @@ list_contains() {
}

update_outputs_all() {
outputs_all=$($xrandr | $awk '/connected/ {print $1}')
}

update_outputs_all_num() {
outputs_all_num=$(echo $outputs_all | wc -w)
}

update_outputs_connected() {
if ! [[ $force ]]; then
outputs_connected=$($xrandr | $awk '/ connected/ {print $1}')
outputs_all=$($xrandr | $awk '/connected/ {print $1}')
return
fi

Expand All @@ -132,6 +124,14 @@ update_outputs_connected() {
sleep $seconds
let times-=1
done
outputs_all=$($xrandr | $awk '/connected/ {print $1}')
}

update_outputs_all_num() {
outputs_all_num=$(echo $outputs_all | wc -w)
}

update_outputs_connected() {
outputs_connected=$($xrandr | $awk '/ connected/ {print $1}')
}

Expand Down Expand Up @@ -212,9 +212,7 @@ clone() {
invalid_argument "$error_clone"
fi

if ! check_output_active $1; then
invalid_argument "$1 is not an active output"
fi
check_output_active $1

if [ $2 ]; then
check_output_connected $2
Expand All @@ -235,9 +233,7 @@ turn_on() {
invalid_argument "$error_turn_on"
fi

if check_output_active $1; then
invalid_argument "$1 is already an active output"
fi
check_output_active $1

if [ $2 ]; then
if ! is_mode_available $1 $2; then
Expand Down Expand Up @@ -365,6 +361,9 @@ fi

update_outputs_all
update_outputs_all_num
update_outputs_connected
update_outputs_disconnected


if [ $outputs_all_num -eq 1 ]; then
notify "You have only one output! $script can't do nothing for you!
Expand All @@ -377,8 +376,6 @@ do
key="$1"
shift

update_outputs_connected
update_outputs_disconnected
update_outputs_active
update_outputs_active_num

Expand All @@ -396,14 +393,28 @@ do
echo "$outputs_disconnected"
;;
--clone | -c)
clone $1 $2
notify "$2 is clone of $1"
shift 2
if [ $2 ] && ! [[ $2 == -* ]]; then
clone $1 $2
notify "$2 is clone of $1"
shift
else
clone $1
notify "$1 cloned"
fi
shift
;;
--turn-on | -on)
turn_on $1 $2
notify "$1 turned on"
shift 2
echo $1 $2

if [ $2 ] && ! [[ $2 == -* ]]; then
turn_on $1 $2
notify "$1 turned on with mode $2"
shift
else
turn_on $1
notify "$1 turned on"
fi
shift
;;
--turn-off | -off)
turn_off $1
Expand Down

0 comments on commit 062647d

Please sign in to comment.