diff options
author | Yuchen Pei <id@ypei.org> | 2024-11-03 17:30:10 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2024-11-03 17:30:10 +1100 |
commit | b14f5dbd299ff45a8a569f7c13c41629e384f4f0 (patch) | |
tree | 8bff70a1b79a15e39ea907869b20ef6104bf0d3e /misc/bin | |
parent | 3755a65776e7f2bd921152dafb289365b31f8b9c (diff) |
[xrandr] update display_toggle to handle one monitor situation
So when a laptop is unplugged we don't get stuck with a black screen.
Diffstat (limited to 'misc/bin')
-rwxr-xr-x | misc/bin/display_toggle.sh | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/misc/bin/display_toggle.sh b/misc/bin/display_toggle.sh index b2c7e5c..e7dfcf5 100755 --- a/misc/bin/display_toggle.sh +++ b/misc/bin/display_toggle.sh @@ -1,11 +1,14 @@ #!/bin/bash -# Assuming there are two displays. A small one (e.g. laptop) and a big -# one (e.g. monitor). Identify the displays, and toggle between 3 -# states: small one only -> both with the big one to the left of the -# small one -> big one only -# small one: <20 inch -# big one: >20 inch +# toggle display arrangements. + +# If there is only one monitor, then run xrandr --auto + +# Otherwise assume there are two displays. A small one (e.g. laptop) +# and a big one (e.g. monitor). Identify the displays, and toggle +# between 3 states: small one only -> both with the big one to the +# left of the small one -> big one only small one: <20 inch big one: +# >20 inch # Make sure the variables from pipe can be assigned # https://stackoverflow.com/questions/42963395/bash-assign-variable-from-pipe @@ -21,9 +24,10 @@ xrandr | grep " connected " | while IFS=$'\n' read -r line; do fi done +# Only one monitor: run xrandr --auto if (( i == 1 )); then - echo "Only one connected display" - exit 1 + xrandr --auto + exit 0 fi regex="^.*/([0-9]+)x.*/([0-9]+).* ([^ ]+)$" |