1
0
forked from extern/nix-config

polybar: Handle dynamic settings through launch.sh

Since polybar supports include files, we can generate part of the bar
config with launch.sh and store it in $HOME/.cache. Since launch.sh is
a shell script, and since bspc is an interface to bspwm, we can also
change the necessary window manager settings required for different
bars, or even configure the settings for no bar at all.

A future implementation of launch.sh may allow us to change polybar
dimensions based on current resolution and whether the screen is HiDPI
or not, although it probably won't be *too* fancy since I don't need to
support every potential DPI a user may have.

Alternatively, someone could submit a patch for polybar to make it
DPI-aware. This is the ideal solution since the bar would be scaled
naturally based on dpi, instead of having to manually halve things
ourselves.
This commit is contained in:
Donovan Glover 2018-10-20 20:24:21 -04:00
parent b6f1aeb619
commit 41f46f38f2
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
2 changed files with 45 additions and 25 deletions

View File

@ -13,45 +13,27 @@ text = ${xrdb:color7}
background-alt = ${xrdb:color8} background-alt = ${xrdb:color8}
[bar/main] [bar/main]
inherit = bar/secondary
# Make the bar float
# offset-x = offset-y = window_gap in bspwmrc
# width = screen resolution - offset-x * 2
# border-size = border_width in bspwmrc
# border-bottom-size = border-size / 2
# line-size = border-size / 2
offset-x = 30
offset-y = 30
width = 3780
border-size = 8
border-bottom-size = 4
line-size = 4
[bar/secondary]
modules-left = bspwm modules-left = bspwm
modules-center = mpd modules-center = mpd
modules-right = cpu ram volume date time modules-right = cpu ram volume date time
monitor = VGA-1 monitor = VGA-1
wm-restack = bspwm
include-file = $HOME/.cache/polybar/config
foreground = ${color.text} foreground = ${color.text}
background = ${color.background} background = ${color.background}
border-color = ${color.text}
font-0 = "Fira Mono:style=Bold:size=19" font-0 = "Fira Mono:style=Bold:size=19"
font-1 = "Noto Sans CJK JP:size=19" font-1 = "Noto Sans CJK JP:size=19"
font-2 = "Font Awesome 5 Free:style=Solid:size=19" font-2 = "Font Awesome 5 Free:style=Solid:size=19"
font-3 = "Font Awesome 5 Free:style=Regular:size=19" font-3 = "Font Awesome 5 Free:style=Regular:size=19"
font-4 = "Font Awesome 5 Brands:style=Regular:size=19" font-4 = "Font Awesome 5 Brands:style=Regular:size=19"
height = 80
padding-left = 2 padding-left = 2
padding-right = 2 padding-right = 2
module-margin = 1 module-margin = 1
border-color = ${color.background-alt}
border-bottom-size = 4
# line-size = 4
# Make fullscreen programs show above polybar
wm-restack = bspwm
[module/bspwm] [module/bspwm]
type = internal/bspwm type = internal/bspwm

View File

@ -1,12 +1,50 @@
#!/bin/sh #!/bin/sh
# New Start: A modern Arch workflow built with an emphasis on functionality. # New Start: A modern Arch workflow built with an emphasis on functionality.
# Copyright (C) 2017 Donovan Glover # Copyright (C) 2017-2018 Donovan Glover
# Terminate any previous instances of polybar # Terminate any previous instances of polybar
killall -q polybar killall -q polybar
bspc_config() {
bspc config top_padding $1 &
bspc config border_width $2 &
bspc config window_gap $3 &
}
# If no bar was specified, we're done here.
if [ -z "$1" ]; then bspc_config 0 4 0; exit; fi
# Set defaults
POLYBAR_HEIGHT=80
HOST_WIDTH=3840
# Make the bar float
if [ "$1" == "float" ]; then
POLYBAR_BORDER_SIZE=8 # Later set to bspwm's border_width
POLYBAR_OFFSET_XY=30 # Later set to bspwm's window_gap
POLYBAR_WIDTH=$(($HOST_WIDTH - $POLYBAR_OFFSET_XY * 2))
fi
# Set the bspwm variables
BSPWM_TOP_PADDING=$(($POLYBAR_HEIGHT + ${POLYBAR_OFFSET_XY:-0} + ${POLYBAR_BORDER_SIZE:-0} * 2))
BSPWM_BORDER_WIDTH=${POLYBAR_BORDER_SIZE:-8}
BSPWM_WINDOW_GAP=${POLYBAR_OFFSET_XY:-20}
bspc_config $BSPWM_TOP_PADDING $BSPWM_BORDER_WIDTH $BSPWM_WINDOW_GAP
# Make the polybar config
mkdir -p $HOME/.cache/polybar
cat >$HOME/.cache/polybar/config <<EOL
width = ${POLYBAR_WIDTH:-3840}
height = $POLYBAR_HEIGHT
offset-x = ${POLYBAR_OFFSET_XY:-0}
offset-y = ${POLYBAR_OFFSET_XY:-0}
border-size = ${POLYBAR_BORDER_SIZE:-0}
EOL
# Wait until there are no more polybar instances running # Wait until there are no more polybar instances running
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
# Start polybar # Start polybar
launch polybar secondary launch polybar main