#!/bin/bash # I, Ian Kelling, follow the GNU license recommendations at # https://www.gnu.org/licenses/license-recommendations.en.html. They # recommend that small programs, < 300 lines, be licensed under the # Apache License 2.0. This file contains or is part of one or more small # programs. If a small program grows beyond 300 lines, I plan to change # to a recommended GPL license. # Copyright 2024 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -e; . /usr/local/lib/bash-bear; set +e script_name="${0##*/}" usage() { cat <$xf m() { printf "$script_name: %s\n" "$*"; "$@"; } if $dry_run; then m() { printf "$script_name: %s\n" "$*"; } fi for mon_suffix in LEFT RIGHT; do if xrandr --listmonitors | awk '$2 == "BIG-'$mon_suffix\" |grep . >/dev/null; then m xrandr --delmonitor BIG-$mon_suffix fi done secondary_out=$(awk '$2 == "connected" && $3 != "primary" {print $1}' $xf) primary_info=$(awk '$2 == "connected" && $3 == "primary" {print $1,$4}' $xf) # res_info eg: 3840x2160+1920+0 read -r primary_out primary_res_info <<<"$primary_info" primary_res=${primary_res_info%%+*} primary_x=${primary_res%x*} primary_y=${primary_res#*x} if [[ $secondary_out ]]; then # some monitors need off then on to become active if $restart; then m xrandr --output $secondary_out --off m sleep 2 fi x_offset=$primary_x left_right_arg=--right-of if [[ $secondary_out == HDMI2 && $(edid card0-HDMI-A-2) == 192efbdcef ]] || \ [[ $secondary_out == HDMI-1 && $(edid card1-HDMI-A-1 ) == 7c58f9ac1e ]] || \ [[ $secondary_out == DP-1 && $(edid card1-DP-1 ) == f3364bc6c1 ]]; then left_right_arg=--left-of x_offset=0 fi left_right_arg="$left_right_arg $primary_out" target_out=$secondary_out target_res=$(grep -A1 -E "^$secondary_out " $xf | tail -n1 | awk '{print $1}') target_x=${target_res%x*} target_y=${target_res#*x} else # disables any leftover secondary. xrandr --auto target_out=$primary_out x_offset=0 target_res=$primary_res target_x=$primary_x target_y=$primary_y fi if $stream && (( target_x > 1280 )); then if (( target_x > 2560 )); then target_x=2560 target_y=1440 target_res=${target_x}x$target_y fi if [[ $secondary_out || $primary_res != "$target_res" ]]; then m xrandr --output $target_out $left_right_arg --mode $target_res fi half_x=$(( target_x / 2 )) # 298 & 336 are millimeters. I took them from a monitor I was using. I # don't know if they are important, I assume not important enough to # change for different monitors. m xrandr --setmonitor BIG-LEFT $half_x/298x$target_y/336+$x_offset+0 $target_out m xrandr --setmonitor BIG-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none move-ws BIG-LEFT 2 move-ws BIG-RIGHT 3 4 5 6 7 8 9 10 else m xrandr --output $target_out $left_right_arg --mode $target_res move-ws $target_out 2 3 5 6 7 8 9 10 fi m /a/bin/ds/i3-sway/gen m /a/exe/input-setup echo -n "myx end: " date "+%A, %B %d, %r, %S seconds"