2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
23 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
28 # eg eDP-1 connected primary
29 laptop_out
=$
(awk '$3 == "primary" {print $1}' $xf)
30 output
=$
(grep -E "^(HDMI|DP)[^ ]* connected [0-9]" $xf|
awk '{print $1}' ||
:)
34 sha256sum
</sys
/class
/drm
/$card/edid |
grep -oE '^.{10}'
38 left_right_arg
=--right-of
39 if [[ $output ]]; then
41 mode
=$
(grep -A1 -E "^$output" $xf |
tail -n1 |
awk '{print $1}')
43 primary_res
=$
(awk '$2 == "connected" && $3 == "primary" { print $4 }' $xf |
sed 's/+.*//')
44 primary_x
=${primary_res%x*}
53 # identify monitors that are always on the left.
54 if [[ $output == HDMI2
&& $
(edid card0-HDMI-A-2
) == 192efbdcef
]] || \
55 [[ $output == HDMI-1
&& $
(edid card1-HDMI-A-1
) == 7c58f9ac1e
]]; then
56 left_right_arg
=--left-of
60 # some monitors need off then on to become active
62 xrandr
--output $output --off
69 xrandr
--output $output $left_right_arg $laptop_out --mode $mode
72 # This splits a monitor into 2 virtual screens, which makes it split
73 # into 2 workspaces in i3, which is a much more convenient setup for
75 # todo: add an option to turn this off
76 # todo: do this on systems with just 1 monitor.
78 # /298 & 336 are millimeters. I took them from a monitor I was using. I
79 # don't know if they are important, I assume not important enough to
80 # change for different monitors.
82 for x
in LEFT RIGHT
; do
83 if xrandr
--listmonitors |
awk '$2 == BIG-'$x |
grep .
>/dev
/null
; then
84 xrandr
--delmonitor BIG-
$x
87 xrandr
--setmonitor BIG-LEFT
$half_x/298x
$y/336+0+$x_offset $output
88 xrandr
--setmonitor BIG-RIGHT
$half_x/298x
$y/336+$
(( x_offset
+ half_x
))+0 none
91 for i
in 2 3 4 5 6 7 8 9 10; do
92 # if the workspace is already there, this will fail.
93 # if the workspace doesn't exist yet, it fails with:
94 # ERROR: No output matched
95 i3-msg
'[workspace="'$i'"]' move workspace to output
$output ||
: