autorandr icon indicating copy to clipboard operation
autorandr copied to clipboard

Cant reload polybar with postswitch

Open chillje opened this issue 4 years ago • 4 comments

Hello, I tried to reload my polybar config with "~/.config/autorandr/postswitch" if I connect a HDMI display.

My simple ~/.config/autorandr/postswitch:

#!/usr/bin/bash
killall -q polybar

sleep 2
/usr/local/bin/polybar --reload main &

This will kill my polybar Setup if I connect/disconnect my HDMI display. Also I can see an output in "journalctl -f" with root for the polybar startup. But polybar does not start and I cant find a process running via "ps -ef | grep -i polybar".

If I run the script by hand my polybar starts..

Any idea on this point?

chillje avatar Jul 12 '20 13:07 chillje

I have a launch script I can run anywhere anytime. postswitch runs this script also.

#!/usr/bin/env sh

# Terminate already running bar instances
killall -q polybar

# Wait until the processes have been shut down
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done

# Launch bars
polybar main &
polybar secondary &

echo "Bars launched..."

gavsiu avatar Aug 26 '20 05:08 gavsiu

@chillje I had the same problem until yesterday. I noticed that the postswitch-script was not running (or not running correctly). After updating from the apt-version (1.4) to a pip-installed version (1.10.1), I did not have that problem anymore.

Which version of autorandr are you using? (autorandr --version came with version 1.5)

kronn avatar Sep 09 '20 10:09 kronn

I have the same problem with the current apt installed version 1.11

midick avatar Feb 13 '23 07:02 midick

Same problem on version 1.15 with two external monitors each with a different bar. All works fine when force loading profiles (e.g. autorandr --load profile). Semi works when plugging/unplugging video cables. In the later case, bar(s) do not show. Have to manually launch polybar script to display bars. Polybar script is being launched from postswitch scripts in profile folders. The scripts were verified to run in both force loaded profile and cable connect/disconnect cases. KillMode=process is in autorandr.service relative to a previous claimed solution. Not sure why the hardware triggered case is not working.

Solved: Removed line "autorandr --current" from my polybar launch script. Long story short, udev did triggered autorandr.service and postswitch as expected. However, autorandr did not like being called again (recursively) under "autorandr --batch" mode (via udev service trigger). Yes, a bit convoluted. Anyway, polybars now auto reload and show on all monitors after hot plugging without having to manually launch the polybar launch script.

FYI - Distro: ArchLinux. "autorandr --current" was being called (in polybar launch script) to detect the monitor connections in order to determine which polybars on what monitors to load. Not a good idea to call autorandr (again) from script called by postswitch. The solution was to add "~/polybar/launch profile_name &" to postswitch passing profile via argument ($1) to the polybar launch script. Not a conventional approach, but is solved the problem. hyprland starting to look good at the moment.

tbattist avatar Apr 09 '24 06:04 tbattist