+# 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
+
+xf=$(mktemp)
+xrandr >$xf
+
+# eg eDP-1 connected primary
+laptop_out=$(awk '$3 == "primary" {print $1}' $xf)
+output=$(grep -E "^(HDMI|DP)[^ ]* connected [0-9]" $xf| awk '{print $1}' ||:)
+
+edid() {
+ card=$1
+ sha256sum </sys/class/drm/$card/edid | grep -oE '^.{10}'
+}
+
+restart=false
+left_right_arg=--right-of
+if [[ $output ]]; then
+
+ mode=$(grep -A1 -E "^$output" $xf | tail -n1 | awk '{print $1}')
+
+ primary_res=$(awk '$2 == "connected" && $3 == "primary" { print $4 }' $xf | sed 's/+.*//')
+ primary_x=${primary_res%x*}
+
+ x=${mode%x*}
+ y=${mode#*x}
+
+ half_x=$(( x / 2 ))