From 9da307d105e216e954ffecf1a96ddeaeb7883f90 Mon Sep 17 00:00:00 2001 From: Fabian Thomas Date: Sun, 25 Sep 2022 19:47:56 +0200 Subject: [PATCH 1/5] feature: center monitors on extend --- mons.sh | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/mons.sh b/mons.sh index b86ce5c..30a37d8 100755 --- a/mons.sh +++ b/mons.sh @@ -98,15 +98,6 @@ disable_mons() { for mon in $@; do "$XRANDR" --output "$mon" --off ; done } -arg2xrandr() { - case $1 in - left) echo '--left-of' ;; - right) echo '--right-of' ;; - bottom) echo '--below' ;; - top) echo '--above' ;; - esac -} - whichmode() { if [ "$(list_size "${disp_mons}")" -eq 1 ]; then if echo "${enabled_out}" | grep prima > /dev/null 2>&1; then @@ -477,8 +468,37 @@ main() { fi if $eFlag ; then - "$XRANDR" --output "$(list_get 1 "$plug_mons")" \ - "$(arg2xrandr "$eArg")" "$(list_front "$plug_mons")" + primary="$(list_front "$plug_mons")" + size_primary="$(echo "$xrandr_out" | grep "$primary" | grep -oE '[0-9]+x[0-9]+')" + x_primary="$(echo "$size_primary" | cut -d'x' -f1)" + y_primary="$(echo "$size_primary" | cut -d'x' -f2)" + + secondary="$(list_get 1 "$plug_mons")" + size_secondary="$(echo "$xrandr_out" | grep "$secondary" | grep -oE '[0-9]+x[0-9]+')" + x_secondary="$(echo "$size_secondary" | cut -d'x' -f1)" + y_secondary="$(echo "$size_secondary" | cut -d'x' -f2)" + + case "$eArg" in + top) + pos_primary="0x$y_secondary" + pos_secondary="$(($((x_primary-x_secondary))/2))x0" + ;; + bottom) + pos_primary="$(($((x_secondary-x_primary))/2))x0" + pos_secondary="0x$y_primary" + ;; + left) + pos_primary="${x_secondary}x0" + pos_secondary="0x$(($((y_primary-y_secondary))/2))" + ;; + right) + pos_primary="0x$(($((y_secondary-y_primary))/2))" + pos_secondary="${x_primary}x0" + ;; + esac + + "$XRANDR" --output "$primary" --pos "$pos_primary"\ + --output "$secondary" --pos "$pos_secondary" exit $? fi else From 63c546f25f0f9bbd30a4cabaf3d8158f42756d8f Mon Sep 17 00:00:00 2001 From: Fabian Thomas Date: Sun, 19 Feb 2023 01:55:40 +0100 Subject: [PATCH 2/5] centering: fix randr parsing --- mons.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mons.sh b/mons.sh index 30a37d8..64ac4e2 100755 --- a/mons.sh +++ b/mons.sh @@ -469,12 +469,12 @@ main() { if $eFlag ; then primary="$(list_front "$plug_mons")" - size_primary="$(echo "$xrandr_out" | grep "$primary" | grep -oE '[0-9]+x[0-9]+')" + size_primary="$(echo "$xrandr_out" | grep "$primary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" x_primary="$(echo "$size_primary" | cut -d'x' -f1)" y_primary="$(echo "$size_primary" | cut -d'x' -f2)" secondary="$(list_get 1 "$plug_mons")" - size_secondary="$(echo "$xrandr_out" | grep "$secondary" | grep -oE '[0-9]+x[0-9]+')" + size_secondary="$(echo "$xrandr_out" | grep "$secondary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" x_secondary="$(echo "$size_secondary" | cut -d'x' -f1)" y_secondary="$(echo "$size_secondary" | cut -d'x' -f2)" From 65864052216cda92f29e79006b0ef1c6cf8bc1f9 Mon Sep 17 00:00:00 2001 From: Fabian Thomas Date: Fri, 14 Apr 2023 14:56:25 +0200 Subject: [PATCH 3/5] fix similiarly named monitors --- mons.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mons.sh b/mons.sh index 64ac4e2..9a494bf 100755 --- a/mons.sh +++ b/mons.sh @@ -469,12 +469,12 @@ main() { if $eFlag ; then primary="$(list_front "$plug_mons")" - size_primary="$(echo "$xrandr_out" | grep "$primary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" + size_primary="$(echo "$xrandr_out" | grep "^$primary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" x_primary="$(echo "$size_primary" | cut -d'x' -f1)" y_primary="$(echo "$size_primary" | cut -d'x' -f2)" secondary="$(list_get 1 "$plug_mons")" - size_secondary="$(echo "$xrandr_out" | grep "$secondary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" + size_secondary="$(echo "$xrandr_out" | grep "^$secondary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" x_secondary="$(echo "$size_secondary" | cut -d'x' -f1)" y_secondary="$(echo "$size_secondary" | cut -d'x' -f2)" From 26623e7371c7910c5f2183addd7cd92e5037648c Mon Sep 17 00:00:00 2001 From: Fabian Thomas Date: Thu, 27 Apr 2023 19:01:41 +0200 Subject: [PATCH 4/5] fix parsing --- mons.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mons.sh b/mons.sh index 9a494bf..3b223f7 100755 --- a/mons.sh +++ b/mons.sh @@ -469,12 +469,12 @@ main() { if $eFlag ; then primary="$(list_front "$plug_mons")" - size_primary="$(echo "$xrandr_out" | grep "^$primary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" + size_primary="$(echo "$xrandr_out" | grep "^$primary " -A99 | tail -n +2 | grep '\*' -m 1 | awk '{print $1}')" x_primary="$(echo "$size_primary" | cut -d'x' -f1)" y_primary="$(echo "$size_primary" | cut -d'x' -f2)" secondary="$(list_get 1 "$plug_mons")" - size_secondary="$(echo "$xrandr_out" | grep "^$secondary" -A99 | tail -n +2 | grep + -m 1 | awk '{print $1}')" + size_secondary="$(echo "$xrandr_out" | grep "^$secondary " -A99 | tail -n +2 | grep '\*' -m 1 | awk '{print $1}')" x_secondary="$(echo "$size_secondary" | cut -d'x' -f1)" y_secondary="$(echo "$size_secondary" | cut -d'x' -f2)" From ecfd379ae29072c4aa74c0ebcdaf8a1903e2e340 Mon Sep 17 00:00:00 2001 From: Fabian Thomas Date: Sat, 16 Mar 2024 12:20:09 +0100 Subject: [PATCH 5/5] experimental fix mons non-active & secondary only --- mons.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mons.sh b/mons.sh index 3b223f7..df41318 100755 --- a/mons.sh +++ b/mons.sh @@ -469,12 +469,22 @@ main() { if $eFlag ; then primary="$(list_front "$plug_mons")" - size_primary="$(echo "$xrandr_out" | grep "^$primary " -A99 | tail -n +2 | grep '\*' -m 1 | awk '{print $1}')" + # NOTE: specifying both + and * here might introduce issues + # last time we did because * was not there when on secondary only + size_primary="$(echo "$xrandr_out" | grep "^$primary " -A99 | tail -n +2 | grep '[\*\+]' -m 1 | awk '{print $1}')" + # NOTE: this is for when the monitor is not active (just take the highest resolution) + if [ -z "$size_primary" ]; then + size_primary="$(echo "$xrandr_out" | grep "^$primary " -A99 | head -n 2 | tail -1 | awk '{print $1}')" + fi x_primary="$(echo "$size_primary" | cut -d'x' -f1)" y_primary="$(echo "$size_primary" | cut -d'x' -f2)" secondary="$(list_get 1 "$plug_mons")" - size_secondary="$(echo "$xrandr_out" | grep "^$secondary " -A99 | tail -n +2 | grep '\*' -m 1 | awk '{print $1}')" + size_secondary="$(echo "$xrandr_out" | grep "^$secondary " -A99 | tail -n +2 | grep '[\*\+]' -m 1 | awk '{print $1}')" + # NOTE: this is for when the monitor is not active (just take the highest resolution) + if [ -z "$size_secondary" ]; then + size_secondary="$(echo "$xrandr_out" | grep "^$secondary " -A99 | head -n 2 | tail -1 | awk '{print $1}')" + fi x_secondary="$(echo "$size_secondary" | cut -d'x' -f1)" y_secondary="$(echo "$size_secondary" | cut -d'x' -f2)"