phillipberndt / autorandr

Auto-detect the connected display hardware and load the appropriate X11 setup using xrandr
2.48k stars 123 forks source link

Cant reload polybar with postswitch #218

Open chillje opened 4 years ago

chillje commented 4 years ago

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?

gavsiu commented 4 years ago

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..."
kronn commented 4 years ago

@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)

midick commented 1 year ago

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

tbattist commented 5 months ago

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.