Add postrandr script as autorandr hook

This commit is contained in:
ItsDrike 2022-08-25 11:56:32 +02:00
parent 88977fbde0
commit 5741d663f9
No known key found for this signature in database
GPG key ID: B014E761034AF742
4 changed files with 47 additions and 6 deletions

View file

@ -0,0 +1,3 @@
#!/bin/sh
postrandr

View file

@ -0,0 +1,3 @@
#!/bin/sh
postrandr

View file

@ -3,8 +3,6 @@
# This file runs when a DM logs you into a graphical session
# if you use startx/xinit this file should also be soruced.
# Set monitor order
xrandr --output HDMI-1 --auto --output eDP-1 --right-of HDMI-1 --auto &
# Start xsecurelock lockscreen with xss-lock
~/.local/bin/scripts/lockscreen start &
@ -24,10 +22,6 @@ dunst &
# Run network manager applet to show connectivity
nm-applet &
# Run trayer-srg for systemtray bar
# if installed normally, command will be `trayer`, not `trayer-srg` command
trayer --monitor 0 --edge top --align right --widthtype request --padding 0 --transparent true --tint 0x282c34 --alpha 0 --height 23 &
# Start flameshot in background
flameshot &

View file

@ -0,0 +1,41 @@
#!/bin/sh
# Script handling monitor connecting/disconnecting with BSPWM
# This is generally meant to be ran after xrandr call, or as a postswitch hook
# in autorandr tool.
DISPLAYS="1 2 3 4 5 6 7 8 9 0"
DISPLAYS_AMT="$(echo "$DISPLAYS" | tr " " "\n" | wc -l)"
MONITORS="$(bspc query -M --names)"
MONITOR_AMT="$(echo "$MONITORS" | wc -l)"
DISPLAYS_PER_MONITOR="$((DISPLAYS_AMT / MONITOR_AMT))"
# TODO: Run xrandr query too, to check which displays are actually connected
# if this isn't in sync with monitors tracked by BSPWM, move all displays from
# the disconnected monitor into the still connected monitors, and leave a temporary
# display on the disconnected monitor, since BSPWM require at least 1 display per mon
# Split displays evenly across all monitors
i=1
for monitor in $(echo "$MONITORS" | tr "\n" " ") ; do
start="$((1 + DISPLAYS_PER_MONITOR * (i - 1)))"
end="$((start + DISPLAYS_PER_MONITOR - 1))"
monitor_displays="$(echo "$DISPLAYS" | cut -d' ' -f$start-$end)"
bspc monitor $monitor -d $monitor_displays
((i++))
done
# In case some displays were left out due to integer division error
((end++))
for display in $(echo "$DISPLAYS" | cut -d' ' -f$end-); do
bspc monitor "$monitor" -a "$display"
done
# (Re)start trayer
killall trayer
until ! pgrep trayer; do sleep 0.1; done
trayer --monitor primary --edge top --align right --widthtype request --padding 0 --transparent true --tint 0x282c34 --alpha 0 --height 28 --SetDockType true & disown
xdo above -t "$(xdo id -N Bspwm -n root | sort | head -n 1)" "$(xdo id -N trayer)" # Keep trayer above bspwm root window, but below everything else
# Start lemonbar
launchlemon