Secondary monitors for Polybar, yeah!

This commit is contained in:
M1dgard 2018-05-01 15:46:04 +02:00
parent 091de0d831
commit 2655b1b1d8
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 73 additions and 18 deletions

View file

@ -18,13 +18,11 @@ foreground-alt = #777
foreground-caution = #bd2c40 foreground-caution = #bd2c40
foreground-alert = #ff4e4e foreground-alert = #ff4e4e
[bar/midbard] [bardefaults]
;enable-ipc = true ;enable-ipc = true
; I don't use this at the moment ; I don't use this at the moment
enable-ipc = false enable-ipc = false
monitor = ${env:MONITOR:eDP-1}
width = 100%
height = 27 height = 27
fixed-center = true fixed-center = true
@ -53,6 +51,15 @@ font-6 = "Material Wifi Signal strength:pixelsize=14;2"
; MPD song position ; MPD song position
font-7 = "Fira Mono:size=7;-1" font-7 = "Fira Mono:size=7;-1"
cursor-click = pointer
cursor-scroll = ns-resize
[bar/midbard]
inherit = bardefaults
monitor = ${env:MONITOR:eDP-1}
width = 100%
modules-left = i3 volume mpd-online-1 modules-left = i3 volume mpd-online-1
modules-center = date modules-center = date
modules-right = battery cpu memory temperature eth wlan modules-right = battery cpu memory temperature eth wlan
@ -60,8 +67,14 @@ modules-right = battery cpu memory temperature eth wlan
tray-position = right tray-position = right
tray-padding = 2 tray-padding = 2
cursor-click = pointer [bar/secondary]
cursor-scroll = ns-resize inherit = bardefaults
modules-left = i3
monitor = ${env:MONITOR:eDP-1}
width = 100%
[module/xwindow] [module/xwindow]
type = internal/xwindow type = internal/xwindow
@ -116,7 +129,7 @@ index-sort = true
wrapping-scroll = false wrapping-scroll = false
; Only show workspaces on the same output as the bar ; Only show workspaces on the same output as the bar
;pin-workspaces = true pin-workspaces = true
label-mode-padding = 2 label-mode-padding = 2
label-mode-foreground = #000 label-mode-foreground = #000
@ -124,22 +137,22 @@ label-mode-background = #ffb52a
; focused = Active workspace on focused monitor ; focused = Active workspace on focused monitor
label-focused = " %index% " label-focused = " %index% "
label-focused-background = ${module/bspwm.label-focused-background} label-focused-background = ${colors.background-selected}
label-focused-padding = ${module/bspwm.label-focused-padding} label-focused-padding = 2
; unfocused = Inactive workspace on any monitor ; unfocused = Inactive workspace on any monitor
label-unfocused = %index% label-unfocused = %index%
label-unfocused-padding = ${module/bspwm.label-occupied-padding} label-unfocused-padding = 2
; visible = Active workspace on unfocused monitor ; visible = Active workspace on unfocused monitor
label-visible = %index% label-visible = ${self.label-focused}
label-visible-background = ${self.label-focused-background} label-visible-background = ${colors.background-alt}
label-visible-padding = ${self.label-focused-padding} label-visible-padding = ${self.label-focused-padding}
; urgent = Workspace with urgency hint set ; urgent = Workspace with urgency hint set
label-urgent = %index% label-urgent = %index%
label-urgent-background = ${module/bspwm.label-urgent-background} label-urgent-background = ${colors.background-alert}
label-urgent-padding = ${module/bspwm.label-urgent-padding} label-urgent-padding = 2
[mpd-shared] [mpd-shared]
type = internal/mpd type = internal/mpd

View file

@ -2,23 +2,65 @@
echo "Launching polybar" echo "Launching polybar"
LOGDIR="$HOME/.log/my-i3-desktop/polybar-$(date +%Y%m%d_%H%M%S.%N)"
mkdir -p "$LOGDIR"
INIT_LOG="$LOGDIR/launch.log"
exec 1>&- 2>&-
exec 1>"$INIT_LOG" 2>&1
detect_primary_monitor() {
primary="$(xrandr | grep -F " connected primary" | head -n1 | cut -d ' ' -f1)"
[[ -n $primary ]] || primary="$(echo "$monitors" | grep " connected" | head -n1 | cut -d ' ' -f1)"
echo "$primary"
}
echo -e "\nDetermining primary monitor..."
primary=$(detect_primary_monitor)
[[ -n $primary ]] || { echo "WARNING: no primary monitor detected!"; notify-send -a "Polybar launcher" "No primary monitor detected" "Couldn't detect primary monitor. Check $INIT_LOG."; }
echo "Primary monitor: $primary"
echo -e "\nDetermining secondary monitors..."
secondary="$(xrandr --listmonitors | sed -n "1d;/$primary\$/d;"'s/^.* \([^ ][^ ]*\)$/\1/p')"
echo "Secondary monitors:"; echo "$secondary" | sed -r 's/^/* /'
# Terminate already running bar instances # Terminate already running bar instances
echo -e "\nTerminating already running bars..."
echo "Running Polybar processes:"
pgrep -u $UID -x polybar | sed -r 's/^/* /'
killall -q polybar killall -q polybar
# Wait until the processes have been shut down # Wait until the processes have been shut down
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
echo "Terminated."
( (
echo -e "\nReading secrets..."
set -o allexport # Make all assignments exports set -o allexport # Make all assignments exports
source "$(dirname "$0")"/secrets.sh source "$(dirname "$0")"/secrets.sh
set +o allexport set +o allexport
# Get the primary monitor, or else just any active monitor echo
MONITOR="$(xrandr | grep " connected primary" | head -n1 | cut -d ' ' -f1)"
[[ -n $MONITOR ]] || MONITOR="$(xrandr | grep " connected" | head -n1 | cut -d ' ' -f1)"
[[ -n $MONITOR ]] && export MONITOR
polybar --config="$HOME/.config/polybar/config.ini" midbard &>$HOME/.log/my-i3-desktop/polybar-midbard.log start_polybar() {
echo "Starting $1 on $2"
MONITOR="$2" \
polybar --config="$HOME/.config/polybar/config.ini" "$1" \
&>"$LOGDIR/$1-$2.log" & disown
}
start_polybar midbard "$primary"
while read -r monitor; do
start_polybar secondary "$monitor"
done <<< "$secondary"
) )
exec 1>&- 2>&-
echo "Polybar launched." echo "Polybar launched."