Multi monitor support

When restarting i3 check for connected second monitor: scale it and
restart polybar if there is one.
Put polybar tray on the main monitor.
Do not kill polybar and relaunch it when restarting i3, but restart it
using ipc (much faster).
This commit is contained in:
2020-06-25 23:20:08 +02:00
parent 0ca808f415
commit 6cdabb78be
4 changed files with 25 additions and 4 deletions

View File

@@ -170,7 +170,7 @@ bindsym $mod+r mode "resize"
# status_command i3blocks
# position top
# }
exec_always --no-startup-id ~/.config/polybar/launch.sh &
exec_always --no-startup-id ~/.config/i3/monitor-setup.sh &
# Touchpad configuration
set $touchpad DLL082A:01 06CB:76AF Touchpad

12
.config/i3/monitor-setup.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
if [ 1 -lt "$(xrandr -q | grep " connected" | wc -l)" ]; then
# scale second monitor to 3200x1800 and put to the left
xrandr --output eDP1 --auto --pos 3200x0 --primary --output DP1 --auto --scale-from 3200x1800 --pos 0x0 --fb 6400x1800
killall -q polybar
while pgrep -x polybar >/dev/null; do sleep 1; done
else
xrandr --output eDP1 --auto --output DP1 --off
fi
"${XDG_CONFIG_HOME:-$HOME/.config}/polybar/launch.sh" &

View File

@@ -24,7 +24,7 @@ modules-left = i3 pulseaudio xbacklight battery-custom
modules-center = datetime
modules-right = vpn wlan bluetooth powermenu
tray-position = right
tray-position = ${env:TRAY_POS:right}
tray-detached = false
tray-scale = 1.0
@@ -36,10 +36,13 @@ foreground = ${colors.foreground}
line-size = 3
line-color = ${colors.primary}
enable-ipc = true
;#################################################
[module/i3]
type = internal/i3
pin-workspaces = true
format = <label-state> <label-mode>
index-sort = true
wrapping-scroll = false

View File

@@ -3,10 +3,16 @@
# if there is no running instance
if ! pgrep -ax polybar >/dev/null 2>&1; then
# launch Polybar on every monitor
# https://github.com/polybar/polybar/issues/763#issuecomment-392960721
# https://github.com/polybar/polybar/issues/763
primary="$(xrandr -q | grep primary | cut -d' ' -f1)"
for m in $(polybar --list-monitors | cut -d':' -f1); do
MONITOR=$m polybar --reload -c "$HOME/.config/polybar/config" main &
export TRAY_POS=none
[ "$m" != "$primary" ] || export TRAY_POS=right
export MONITOR="$m"
polybar --reload -c "${XDG_CONFIG_HOME:-$HOME/.config}/polybar/config" main &
done
echo "Polybar launched..."
else
polybar-msg cmd restart
fi