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 # status_command i3blocks
# position top # position top
# } # }
exec_always --no-startup-id ~/.config/polybar/launch.sh & exec_always --no-startup-id ~/.config/i3/monitor-setup.sh &
# Touchpad configuration # Touchpad configuration
set $touchpad DLL082A:01 06CB:76AF Touchpad 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-center = datetime
modules-right = vpn wlan bluetooth powermenu modules-right = vpn wlan bluetooth powermenu
tray-position = right tray-position = ${env:TRAY_POS:right}
tray-detached = false tray-detached = false
tray-scale = 1.0 tray-scale = 1.0
@@ -36,10 +36,13 @@ foreground = ${colors.foreground}
line-size = 3 line-size = 3
line-color = ${colors.primary} line-color = ${colors.primary}
enable-ipc = true
;################################################# ;#################################################
[module/i3] [module/i3]
type = internal/i3 type = internal/i3
pin-workspaces = true
format = <label-state> <label-mode> format = <label-state> <label-mode>
index-sort = true index-sort = true
wrapping-scroll = false wrapping-scroll = false

View File

@@ -3,10 +3,16 @@
# if there is no running instance # if there is no running instance
if ! pgrep -ax polybar >/dev/null 2>&1; then if ! pgrep -ax polybar >/dev/null 2>&1; then
# launch Polybar on every monitor # 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 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 done
echo "Polybar launched..." echo "Polybar launched..."
else
polybar-msg cmd restart
fi fi