You are not logged in.
Pages: 1
Hello,
I've been struggling with this issue for couple of days now. I just can't seem to get my polybar to reload when I hotplug my monitor
First of all to enable hotplugging I've created a 98-monitor-hotplug udev rule in /etc/udev/rules.d:
KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/bozanicjosip/.Xauthority", ENV{HOME}="/home/bozanicjosip", RUN+="/usr/local/bin/monitor-hotplug --notify"my monitor-hotplug script:
#!/bin/bash
if [ -r /home/bozanicjosip/.dbus/Xdbus ]; then
source /home/bozanicjosip/.dbus/Xdbus
fi
hdmi_status=$(/usr/bin/xrandr | grep HDMI | awk '{print$2}')
main_output=$(/usr/bin/xrandr | grep eDP | awk '{print$1}')
hdmi_output=$(/usr/bin/xrandr | grep HDMI | awk '{print$1}')
function connect(){
/usr/bin/xrandr --output "$2" --mode 2560x1440
/usr/bin/xrandr --output "$2" --auto --right-of "$1"
notification="HDMI plugged in"
}
function disconnect(){
/usr/bin/xrandr --output "$1" --off
notification="HDMI plugged out"
}
function default(){
/usr/bin/xrandr --auto
}
if [ "${hdmi_status}" = connected ]; then
connect "$main_output" "$hdmi_output"
elif [ "${hdmi_status}" = disconnected ]; then
disconnect "$hdmi_output"
else default
fi
if [ "$1" == "--notify" ] && [ -v notification ]; then
su bozanicjosip -c "/usr/bin/notify-send --urgency low -t 5000 'Graphics Update' '$notification'"
fi
/home/bozanicjosip/.bin/refresh-wallpaper
/home/bozanicjosip/.config/polybar/launch.sh &my polybar launch script:
#!/usr/bin/env bash
config_file=/home/bozanicjosip/.config/polybar/config
# Terminate already running bar instances
killall -q polybar
# If all your bars have ipc enabled, you can also use
# polybar-msg cmd quit
# Launch bar1 and bar2
if type "xrandr"; then
IFS=';' read -ra connected_outputs <<<"$(/home/bozanicjosip/.bin/connected-outputs)"
for outputs in "${connected_outputs[@]}"; do
IFS=',' read -ra output_pair <<<"$outputs"
standard_output="${output_pair[0]}"
monitor_output="${output_pair[1]}"
echo "$monitor_output" | systemd-cat -p emerg
echo polybar -m | systemd-cat -p emerg
MONITOR=$monitor_output polybar -c "$config_file" --reload main-"$standard_output" &
done
else
MONITOR=eDP polybar -c "$config_file" --reload main-eDP &
fiI've already tested this part and connected outputs script is returning the correct outputs. When I run monitor-hotplug with sudo everything works normally, however when I run it on udev the screens are arranged correctly, but polybar is not.
Any ideas on this one?
Last edited by BozanicJosip (2020-11-25 11:22:30)
Offline
You don't seem to switch the user for launch.sh? (or monitor-hotplug)
Online
Should I be switching the user? I'm running the command from root and it also works
I thought that might be a good indication that the things work correctly
Offline
You want to run polybar for the X11 session of bozanicjosip, right?
Run it as that user (and ensure to export $DISPLAY, $XAUTHORITY and maybe $DBUS_SESSION_BUS_ADDRESS
Even if you gain access to the X11 server (either through xhost or the XAUTHORITY export) you don't want to run your desktop as root and polybar might or not bail on that condition.
Online
Something I've noticed is that
if type "xrandr"; thendoesn't get executed in udev. Is there anything I should do with this part to work? I think this might be the issue as I get no output from then on. I've basically picked that if conditional somewhere so am not sure if that might be the issue. All of the env variables you've stated above are set correctly
Offline
You don't need the quotes, but the check is ok.
What do you mean by "doesn't get executed in udev"?
That the test isn't performed or returns false?
I'd throw a bunch of "touch /tmp/test1", "touch /tmp/test2" … into the script to track the execution from the udev rule.
Online
Yeah I've basically put touch /tmp/xrandrb before and /tmp/xrandra just after the if statement and the xrandra file is not created :scratching_my_head:
Offline
Bad $PATH?
Online
This is crazy now, I'm outputting the type xrandr command into xrandrb tmp file and the output is
xrandr is /usr/bin/xrandrOffline
What's the exit code of "type xrandr"? ("$?")
Online
I think this had to do with the fact that I was moving the launc-polybar script to the background. When I've removed the & the script would proceed. Actually I'm coming quite close. I just have this weird issue now where polybar is working for 5 seconds then it disappers :S
I can update my scripts here again if needed since I was changing quite some things
Offline
You cannot run long-term processes via udev, https://wiki.archlinux.org/index.php/Ud … _processes
Online
That definitely could be an issue. Cleanest solution in the end might be to create my own service that would be responsible for that. I'll look into that since this setup is giving me headaches. Thank you ![]()
Offline
Pages: 1