From 6cdabb78be9aee7fcd4f96a0dda8c310b40a5a3d Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Thu, 25 Jun 2020 23:20:08 +0200 Subject: [PATCH] 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). --- .config/i3/config | 2 +- .config/i3/monitor-setup.sh | 12 ++++++++++++ .config/polybar/config | 5 ++++- .config/polybar/launch.sh | 10 ++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 .config/i3/monitor-setup.sh diff --git a/.config/i3/config b/.config/i3/config index f25ff9c..fceb329 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -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 diff --git a/.config/i3/monitor-setup.sh b/.config/i3/monitor-setup.sh new file mode 100755 index 0000000..77cea89 --- /dev/null +++ b/.config/i3/monitor-setup.sh @@ -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" & diff --git a/.config/polybar/config b/.config/polybar/config index cab4e50..655e7bb 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -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 = index-sort = true wrapping-scroll = false diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index 2aba2c4..6387c51 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -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