From 1dee42191baf12b68bb5e098c6b8cb02c5f976bf Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:49:13 +0200 Subject: [PATCH 1/7] Add general script documentation --- monitor_layout.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitor_layout.sh b/monitor_layout.sh index e51b3bb..66d5c05 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -1,4 +1,6 @@ #!/bin/bash +# +# Allows to manage screens with rofi using implicitly xrandr. XRANDR=$(which xrandr) From 48b4adcacace2474e5354f2256b4057d14261694 Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:50:27 +0200 Subject: [PATCH 2/7] Delete useless global alias --- monitor_layout.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index 66d5c05..d22cc21 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -9,8 +9,7 @@ MONITORS=( $( ${XRANDR} | awk '( $2 == "connected" ){ print $1 }' ) ) NUM_MONITORS=${#MONITORS[@]} -TITLES=() -COMMANDS=() + function gen_xrandr_only() From 8915bca6cce64b0ff1a967748e39ace0d87d433b Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:51:47 +0200 Subject: [PATCH 3/7] Add better display for monitors layout --- monitor_layout.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index d22cc21..b618da2 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -89,7 +89,7 @@ function gen_entries() { for a in $(seq 0 $(( ${#TILES[@]} -1 ))) do - echo $a ${TILES[a]} + echo "$a: ${TILES[a]}" done } @@ -97,4 +97,4 @@ function gen_entries() SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -a 0 -no-custom | awk '{print $1}' ) # Call xrandr -$( ${COMMANDS[$SEL]} ) +$( ${COMMANDS[${SEL::-1}]} ) From dc614ac441177d28cb3b6fa2ffe4eaf0818d8e46 Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:52:36 +0200 Subject: [PATCH 4/7] Delete useless rofi dmenu option --- monitor_layout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index b618da2..aa68218 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -94,7 +94,7 @@ function gen_entries() } # Call menu -SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -a 0 -no-custom | awk '{print $1}' ) +SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -no-custom | awk '{print $1}' ) # Call xrandr $( ${COMMANDS[${SEL::-1}]} ) From 3942075d1bee8bba7dce57afeeaec240f7610a9c Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:54:48 +0200 Subject: [PATCH 5/7] Fix display issue with dual screen --- monitor_layout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index aa68218..0a10f9d 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -55,7 +55,7 @@ do then TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ - --output ${MONITORS[$entry_b]} --auto --left-of ${MONITORS[$entry_a]}" + --output ${MONITORS[$entry_b]} --auto --right-of ${MONITORS[$entry_a]}" index+=1 fi From 8348b4a5e3df1e52d840bc19cbce608fd249e3cb Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:55:44 +0200 Subject: [PATCH 6/7] Refactoring monitor_layout --- monitor_layout.sh | 130 +++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 77 deletions(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index 0a10f9d..9e78355 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -2,99 +2,75 @@ # # Allows to manage screens with rofi using implicitly xrandr. -XRANDR=$(which xrandr) - -MONITORS=( $( ${XRANDR} | awk '( $2 == "connected" ){ print $1 }' ) ) - - +MONITORS=($($(which xrandr) | awk '($2 == "connected"){print $1}')) NUM_MONITORS=${#MONITORS[@]} - - - -function gen_xrandr_only() -{ - selected=$1 - - cmd="xrandr --output ${MONITORS[$selected]} --auto " - - for entry in $(seq 0 $((${NUM_MONITORS}-1))) - do - if [ $selected != $entry ] - then - cmd="$cmd --output ${MONITORS[$entry]} --off" - fi - done - - echo $cmd -} - - - declare -i index=0 TILES[$index]="Cancel" -COMMANDS[$index]="true" index+=1 +# Turn off monitors except a specified one. +function disable_monitors_except() { + cmd="xrandr --output ${MONITORS[$1]} --auto" -for entry in $(seq 0 $((${NUM_MONITORS}-1))) -do - TILES[$index]="Only ${MONITORS[$entry]}" - COMMANDS[$index]=$(gen_xrandr_only $entry) - index+=1 -done - -## -# Dual screen options -## -for entry_a in $(seq 0 $((${NUM_MONITORS}-1))) -do - for entry_b in $(seq 0 $((${NUM_MONITORS}-1))) + for i in $(seq 0 $((${NUM_MONITORS} - 1))) do - if [ $entry_a != $entry_b ] - then - TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" - COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ - --output ${MONITORS[$entry_b]} --auto --right-of ${MONITORS[$entry_a]}" - - index+=1 - fi + if [ $1 != $i ]; then + echo "$cmd --output ${MONITORS[$i]} --off" + return + fi done -done + echo $cmd +} -## -# Clone monitors -## -for entry_a in $(seq 0 $((${NUM_MONITORS}-1))) -do - for entry_b in $(seq 0 $((${NUM_MONITORS}-1))) +# Generate entries. +function gen_entries() { + for i in $(seq 0 $((${#TILES[@]} - 1))) do - if [ $entry_a != $entry_b ] - then - TILES[$index]="Clone Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" - COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ - --output ${MONITORS[$entry_b]} --auto --same-as ${MONITORS[$entry_a]}" - - index+=1 - fi + echo "$i: ${TILES[i]}" done -done - +} -## -# Generate entries, where first is key. -## -function gen_entries() -{ - for a in $(seq 0 $(( ${#TILES[@]} -1 ))) - do - echo "$a: ${TILES[a]}" - done +# Generate monitor options according to a valid mode. +# Available modes are: "only", "clone" and "dual". +function gen_options() { + if [ "$1" == "only" ]; then + for i in $(seq 0 $((${NUM_MONITORS} - 1))) + do + TILES[$index]="Only ${MONITORS[$i]}" + COMMANDS[$index]=$(disable_monitors_except $i) + index+=1 + done + else + for i in $(seq 0 $((${NUM_MONITORS} - 1))) + do + for j in $(seq 0 $((${NUM_MONITORS} - 1))) + do + if [ $i != $j ]; then + if [ "$1" == "clone" ]; then + TILES[$index]="Clone Screen ${MONITORS[$i]} -> ${MONITORS[$j]}" + COMMANDS[$index]="xrandr --output ${MONITORS[$i]} --auto \ + --output ${MONITORS[$j]} --auto --same-as ${MONITORS[$i]}" + elif [ "$1" == "dual" ]; then + TILES[$index]="Dual Screen ${MONITORS[$i]} -> ${MONITORS[$j]}" + COMMANDS[$index]="xrandr --output ${MONITORS[$i]} --auto \ + --output ${MONITORS[$j]} --auto \ + --right-of ${MONITORS[$i]}" + fi + index+=1 + fi + done + done + fi } +gen_options 'only' +gen_options 'dual' +gen_options 'clone' + # Call menu -SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -no-custom | awk '{print $1}' ) +SEL=$(gen_entries | rofi -dmenu -p "Monitor Setup" -no-custom | awk '{print $1}') # Call xrandr -$( ${COMMANDS[${SEL::-1}]} ) +$(${COMMANDS[${SEL::-1}]}) From 14aacd0c3e3394e24e84aeb1c626a5069f93bb3e Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 12 May 2018 06:56:25 +0200 Subject: [PATCH 7/7] Add fontawesome5 arrow --- monitor_layout.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor_layout.sh b/monitor_layout.sh index 9e78355..7eb8d44 100755 --- a/monitor_layout.sh +++ b/monitor_layout.sh @@ -49,11 +49,11 @@ function gen_options() { do if [ $i != $j ]; then if [ "$1" == "clone" ]; then - TILES[$index]="Clone Screen ${MONITORS[$i]} -> ${MONITORS[$j]}" + TILES[$index]="Clone Screen ${MONITORS[$i]}  ${MONITORS[$j]}" COMMANDS[$index]="xrandr --output ${MONITORS[$i]} --auto \ --output ${MONITORS[$j]} --auto --same-as ${MONITORS[$i]}" elif [ "$1" == "dual" ]; then - TILES[$index]="Dual Screen ${MONITORS[$i]} -> ${MONITORS[$j]}" + TILES[$index]="Dual Screen ${MONITORS[$i]}  ${MONITORS[$j]}" COMMANDS[$index]="xrandr --output ${MONITORS[$i]} --auto \ --output ${MONITORS[$j]} --auto \ --right-of ${MONITORS[$i]}"