polybar: Add variable DPI support

This commit adds full variable DPI support to polybar. This means that
it is possible to use the same polybar setup on both a traditional and
HiDPI display.

Additionally, font size has been slightly adjusted since polybar does
not support decimal font sizes. Some other numbers have also been
changed.
This commit is contained in:
Donovan Glover 2018-11-28 15:26:18 -05:00
parent 287e1211de
commit 361abf7c98
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
2 changed files with 18 additions and 12 deletions

View File

@ -25,11 +25,11 @@ foreground = ${color.text}
background = ${color.background}
border-color = ${color.text}
font-0 = "Fira Mono:style=Bold:size=19"
font-1 = "Noto Sans CJK JP:size=19"
font-2 = "Font Awesome 5 Free:style=Solid:size=19"
font-3 = "Font Awesome 5 Free:style=Regular:size=19"
font-4 = "Font Awesome 5 Brands:style=Regular:size=19"
font-0 = "Fira Mono:style=Bold:size=10"
font-1 = "Noto Sans CJK JP:size=10"
font-2 = "Font Awesome 5 Free:style=Solid:size=10"
font-3 = "Font Awesome 5 Free:style=Regular:size=10"
font-4 = "Font Awesome 5 Brands:style=Regular:size=10"
padding = 2
module-margin = 1

View File

@ -2,6 +2,9 @@
# New Start: A modern Arch workflow built with an emphasis on functionality.
# Copyright (C) 2017-2018 Donovan Glover
POLYBAR_DPI=$(xrdb -query | grep Xft.dpi | cut -f 2)
POLYBAR_SCALE=$(($POLYBAR_DPI / 96))
# Terminate any previous instances of polybar
killall -q polybar
@ -12,23 +15,25 @@ bspc_config() {
}
# If no bar was specified, we're done here.
if [ -z "$1" ]; then bspc_config 0 4 0; exit; fi
if [ -z "$1" ]; then bspc_config 0 $((2 * $POLYBAR_SCALE)) 0; exit; fi
# Set defaults
POLYBAR_HEIGHT=80
POLYBAR_HEIGHT=$((40 * $POLYBAR_SCALE))
HOST_WIDTH=$(bspc query -T -m | jq '.rectangle.width')
# 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_BORDER_SIZE=$((2 * $POLYBAR_SCALE)) # Later set to bspwm's border_width
POLYBAR_OFFSET_XY=$((30 * $POLYBAR_SCALE)) # Later set to bspwm's window_gap
POLYBAR_WIDTH=$(($HOST_WIDTH - $POLYBAR_OFFSET_XY * 2))
else
POLYBAR_WIDTH=$HOST_WIDTH
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}
BSPWM_BORDER_WIDTH=${POLYBAR_BORDER_SIZE:-$((4 * $POLYBAR_SCALE))}
BSPWM_WINDOW_GAP=${POLYBAR_OFFSET_XY:-$((20 * $POLYBAR_SCALE))}
bspc_config $BSPWM_TOP_PADDING $BSPWM_BORDER_WIDTH $BSPWM_WINDOW_GAP
@ -36,11 +41,12 @@ bspc_config $BSPWM_TOP_PADDING $BSPWM_BORDER_WIDTH $BSPWM_WINDOW_GAP
mkdir -p $HOME/.cache/polybar
cat >$HOME/.cache/polybar/config <<EOL
width = ${POLYBAR_WIDTH:-3840}
width = $POLYBAR_WIDTH
height = $POLYBAR_HEIGHT
offset-x = ${POLYBAR_OFFSET_XY:-0}
offset-y = ${POLYBAR_OFFSET_XY:-0}
border-size = ${POLYBAR_BORDER_SIZE:-0}
dpi = $POLYBAR_DPI
EOL
# Save the top_padding amount for use by other scripts