Instead of running swaylock, maybe you instead want to signal swayidle which you may have running in the background already (check pgrep swayidle to find out) that you now want to perform the “idle” action. You can check whether this works by running:
pkill -SIGUSR1 swayidle
If this locks your system (as configured in your sway config) then you might want to run that command instead.
To add a new button to waybar, read the manual page of waybar-custom. For example I have the following custom button in my waybar:
I’m not running swayidle but that’s maybe besides the point.
Adding a custom-module to waybar would work in order to have a button right in the bar, yes. But I was talking about the three-dots menu that also contains the “reboot” and “shutdown” commands. I’d like to add something there, doesn’t really matter if it’s my locking command or something else.
You might mean the menu that gets generated by /usr/libexec/reform-tools/reform-tray.py? To change the items, I guess you’d have to copy the script to some other place, then edit the Python code and then edit your sway or wayfire config to call your script instead of the version in /usr/libexec.
It does lock the screen as expected but I encountered something strange:
After locking and unlocking once, the entire waybar triggers the lock command, even if I click on another module or empty space on the bar and this only stops after a reboot (probably logging out is enough but I can’t since the tray menu now also triggers the lock.