UPDATE : Refer here for a newer solution for this issue.
A simple python 3 script and systemd service file to check if waybar is connected to org.kde.StatusNotifierWatcher. Refer #3468 issue for more background information.
This script is highly experimental and may be unstable or unreliable. Before using this script, ensure you have taken appropriate measures to safeguard your data and systems, such as creating backups and testing in a controlled environment. Proceed with caution and use at your own discretion.
-
check_waybar_tray.py
: Python script which first checks if waybar is running. If waybar is running, then it check for the owner/connected process oforg.kde.StatusNotifierWatcher
D-bus service. If the process is notwaybar
, then it kills the process owning (or connected to)org.kde.StatusNotifierWatcher
. -
check_waybar_tray_v2.py
: Same python script, except it logs locally to a logs.txt file and also to the systemd-journal. This will be used withswayidle
. With theafter-resume
option we can execute the script. It is much more cleaner and simpler that using the systemd services. -
[email protected]
: Template service file that acts a proxy to run the user service file after suspend resume. We need this as we are usingsuspend.target
, which further callssleep.target
which is specific to system services [Ref 1]. Ifcheck_waybar_tray.py
is directly called from this service, its runs with root privilege which causes an issue with getting the SessionBus [Ref 4]. To circumvent this, we can either run the python script as root and then usesetuid
to target user UID and then calldbus.bus.BusConnection
with the socket address for the target user, or we can create a proxy template service file which furthers calls a user service file [Ref 4]. The latter approach has been used here. -
check_waybar_tray.service
: User service that runs thecheck_waybar_tray.py
.
- Clone the git repository anywhere you want. Lets assume it is /home/USER/Documents, where USER is your username.
cd ~/Documents/
git clone https://github.com/ShikharArvind/check_waybar_tray.git
- Install the required python3 packages :
systemd-python
,dbus-python
,psutils
. For Arch users, all are available in the repo, install them from there and not pip. - Update the
check_waybar_tray_v2.py
logs file path in the following section :
# Configure logging
logging.basicConfig(
filename='/home/shikhar/Documents/check_waybar_tray/logs.txt', # UPDATE THE PATH ACCORDINGLY, Need to use full path or else when calling from swayidle, it will log elsewhere.
)
- Test run the python file to see if everything is working fine.
cd ~/Documents/check_waybar_tray
python3 check_waybar_tray_v2.py
- Append the python script to swayidle options. For me, it's in my sway config as follows :
exec swayidle -w \
timeout 1200 'hyprlock --quiet --immediate' \
before-sleep 'hyprlock --quiet --immediate' \
after-resume 'exec python3 ~/Documents/check_waybar_tray/check_waybar_tray_v2.py'
- Supend, resume and check the
logs.txt
in the local directory and/or journalctl to make sure the script is working as intended. - Might be also possible on other Idle daemons like
hypridle
, but have not personally tested it.
- Clone the git repository anywhere you want. Lets assume it is /home/USER/Documents, where USER is your username.
cd ~/Documents/
git clone https://github.com/ShikharArvind/check_waybar_tray.git
- Install the required python3 packages :
dbus-python
,psutils
. For Arch users, all are available in the repo, install them from there and not pip. - Test run the python file to see if everything is working fine.
cd ~/Documents/check_waybar_tray
python3 check_waybar_tray.py
- Edit the following line in
check_waybar_tray.service
to add the right path for thecheck_waybar_tray.py
file.
ExecStart=python3 %h/Documents/check_waybar_tray/check_waybar_tray.py
- Copy the
[email protected]
to/etc/systemd/system/
sudo cp [email protected] /etc/systemd/system/
- Reload systemd daemon
sudo systemctl daemon-reload
- Enable the
[email protected]
.
sudo systemctl enable [email protected] # Replace USER with username
- Copy the
check_waybar_tray.service
to~/.config/systemd/user/
cp check_waybar_tray.service ~/.config/systemd/user/
- Suspend. resume and check logs using :
systemctl --user status check_waybar_tray.service
- https://unix.stackexchange.com/questions/152039/how-to-run-a-user-script-after-systemd-wakeup
- https://unix.stackexchange.com/questions/379810/find-out-the-owner-of-a-dbus-service-name
- ChatGPT and Google Gemini to help me get started.
- https://stackoverflow.com/questions/71425861/connecting-to-user-dbus-as-root