this post was submitted on 08 Jun 2024
5 points (85.7% liked)

Arch Linux

7721 readers
2 users here now

The beloved lightweight distro

founded 4 years ago
MODERATORS
 

Solution at the end of the post

Hello guys. I've recently started experiencing an odd issue with my bspwm setup where on a reboot or upon restarting bspwm in-place I either don't get the top polybar (fixed this by explicitly killing all polybar processes from my bspwm script if they exist and then on a separate line running my launch script), or the gap between the bottom of the windows on my top (secondary) monitor and the bottom edge of the monitor is far too wide. Here is a screenshot of what I mean:

Out of the 20 times give or take that I will restart bspwm either from the terminal or through the sxhkd keybind I set, only once will it actually size itself correctly with the proper gap. The next time I restart it will revert back to this large gap. Here is also my bspwmrc file

#! /bin/sh
# pgrep -x sxhkd > /dev/null || sxhkd -s &
# pgrep -io "sxhkd" || { killall sxhkd; sxhkd > /dev/null 2>&1 & }
pgrep -io "sxhkd" | xargs kill
sxhkd -s &
pgrep -x copyq > /dev/null || copyq &
pgrep -x xfce4-power-manager > /dev/null || xfce4-power-manager &
pgrep -x dunst > /dev/null || dunst &
pgrep -x nm-applet > /dev/null || nm-applet &
pgrep -x picom > /dev/null || picom -b
pgrep -x polybar > /dev/null || $HOME/.config/polybar/launch.sh
if [[ $(xrandr -q | grep "HDMI-A-1 connected") ]];
then
	xrandr --output HDMI-A-0 --primary --mode 1920x1080 --pos 0x0 --rotate normal
	xrandr --output HDMI-A-1 --mode 1920x1080 --rotate inverted --above HDMI-A-0
	bspc monitor HDMI-A-0 -d 1 2 3 4 5
	bspc monitor HDMI-A-1 -d 6 7 8 9 0
	
	# Fix gap appearing above windows on first monitor after restarting bspwm
	bspc config -m HDMI-A-0 top_padding 3
	bspc config -m HDMI-A-0 bottom_padding 40
	
	# Fix top/bottom margins for secondary monitor
	bspc config -m HDMI-A-1 bottom_padding 3
	bspc config -m HDMI-A-1 top_padding 40
	bspc wm -O HDMI-A-0 HDMI-A-1
else
	# bspc monitor -d I II III IV V VI VII VIII IX X
	bspc monitor HDMI-A-0 -d 1 2 3 4
fi
$HOME/.fehbg &
setxkbmap us
$HOME/.bin/remap-caps-esc
bspc config border_width         2
bspc config window_gap           10
# bspc config 
bspc config split_ratio          0.52
bspc config borderless_monocle   true
bspc config gapless_monocle      true
# Dracula theme
bspc config normal_border_color "#44475a"
bspc config active_border_color "#6272a4"
bspc config focused_border_color "#8be9fd"
bspc config presel_feedback_color "#6272a4"
# Make sure theme cursor is shown when mouse is not over a window, instead of the standard default one
xsetroot -cursor_name left_ptr
bspc rule -a Gimp desktop='^8' state=floating follow=on
bspc rule -a Chromium desktop='^2'
bspc rule -a mplayer2 state=floating
bspc rule -a Kupfer.py focus=on
bspc rule -a Screenkey manage=off
bspc rule -a Zathura state=tiled
bspc rule -a Passy state=tiled

bspc rule -a scpad sticky=on state=floating rectangle=1896x400+10+50

betterlockscreen -u $HOME/Pictures/wallpapers/ --fx dim --dim 50

The lines where I set bottom_padding for the secondary monitor and top padding for the primary monitor I just commented out but they did not have any effect.

I would really appreciate any help for this. Thanks in advance!

Solution for polybar not launching both bars is to change the single polybar line that checks for any existing instances and runs the launch script if none are found, to 2 lines that will explicitly kill all polybar processes and then run the launch script. I also moved this a bit further down in the file.

pgrep -x polybar > /dev/null | xargs kill
$HOME/.config/polybar/launch.sh

The solution for the gap on the bottom of the second monitor was to move the if check further down in the file, hopefully giving bspwm enough time to set its defaults and then have my values set. It now looks like this:

#! /bin/sh

# pgrep -x sxhkd > /dev/null || sxhkd -s &
# pgrep -io "sxhkd" || { killall sxhkd; sxhkd > /dev/null 2>&1 & }
pgrep -io "sxhkd" | xargs kill
sxhkd -s &

pgrep -x copyq > /dev/null || copyq &
pgrep -x xfce4-power-manager > /dev/null || xfce4-power-manager &
pgrep -x dunst > /dev/null || dunst &
pgrep -x nm-applet > /dev/null || nm-applet &

pgrep -x picom > /dev/null | xargs kill
picom -b

# THESE ARE THE 2 POLYBAR LINES WHERE THE FIRST KILLS ANY EXISTING PROCESSES AND THE SECOND RUNS THE LAUNCH SCRIPT
pgrep -x polybar > /dev/null | xargs kill
$HOME/.config/polybar/launch.sh

$HOME/.fehbg &

setxkbmap us
$HOME/.bin/remap-caps-esc

bspc config border_width         2
bspc config window_gap           10
# bspc config 

bspc config split_ratio          0.52
bspc config borderless_monocle   true
bspc config gapless_monocle      true

# Dracula theme
bspc config normal_border_color "#44475a"
bspc config active_border_color "#6272a4"
bspc config focused_border_color "#8be9fd"
bspc config presel_feedback_color "#6272a4"


# THIS IS THE CHECK FOR WHETHER THERE ARE 2 MONITORS CONNECTED WHICH I MOVED DOWN IN THE FILE
if [[ $(xrandr -q | grep "HDMI-A-1 connected") ]];
then
	xrandr --output HDMI-A-0 --primary --mode 1920x1080 --pos 0x0 --rotate normal
	xrandr --output HDMI-A-1 --mode 1920x1080 --rotate inverted --above HDMI-A-0
	bspc monitor HDMI-A-0 -d 1 2 3 4 5
	bspc monitor HDMI-A-1 -d 6 7 8 9 0
	
	# pgrep -x polybar > /dev/null || $HOME/.config/polybar/launch.sh

	# Fix gap appearing above windows on first monitor after restarting bspwm
	bspc config -m HDMI-A-0 top_padding 3
	bspc config -m HDMI-A-0 bottom_padding 40
	
	# Fix top/bottom margins for secondary monitor
	bspc config -m HDMI-A-1 bottom_padding 3
	bspc config -m HDMI-A-1 top_padding 40

	bspc wm -O HDMI-A-0 HDMI-A-1
else
	# bspc monitor -d I II III IV V VI VII VIII IX X
	bspc monitor HDMI-A-0 -d 1 2 3 4
	# pgrep -x polybar > /dev/null || $HOME/.config/polybar/launch.sh
fi

# Make sure theme cursor is shown when mouse is not over a window, instead of the standard default one
xsetroot -cursor_name left_ptr

bspc rule -a Gimp desktop='^8' state=floating follow=on
bspc rule -a Chromium desktop='^2'
bspc rule -a mplayer2 state=floating
bspc rule -a Kupfer.py focus=on
bspc rule -a Screenkey manage=off
bspc rule -a Zathura state=tiled
bspc rule -a Passy state=tiled

bspc rule -a scpad sticky=on state=floating rectangle=1896x400+10+50

betterlockscreen -u $HOME/Pictures/wallpapers/ --fx dim --dim 50

Note: On booting into the WM the secondary monitor polybar doesn't launch, but it appears after restarting bspwm.

Im not entirely sure if my way of thinking is correct with regards to how bspwm handles the timing of setting default values and then reading its configuration file, but it seems to at least half work now.

top 3 comments
sorted by: hot top controversial new old
[–] Ashiette@lemmy.world 1 points 4 months ago* (last edited 4 months ago) (2 children)

I'm not versed in bspwm, and this might be absolutely not a good solution (and one which you might have already done)

However from reading your .rc, it might be possible that the bottom padding has a default value (of 40). Have you tried setting it to 20 and see if it makes any difference ?

[–] promitheas@programming.dev 1 points 4 months ago

Ive tried commenting out those lines, but Ill give it a shot again and see what happens

[–] promitheas@programming.dev 1 points 4 months ago

I just tried it by commenting that line out in the config and running in a terminal the following:

bspc config -m HDMI-A-1 bottom_padding XX

where XX are different values I played around with. I tried 20, 1 and 3. They seem to get set correctly. 3 is the value I had in my config. I'm thinking it might be something like a race between bspwm restarting itself and running the command in the config file (config files are basically just commands to the WM). I'll try moving that part of the config further down in the config so hopefully it has a chance to set its default values on restart and after that set my values.