Adding swaylock to the waybar menu

I would like to add something like swaylock --color 000000 as a “Lock Device” command to the waybar menu.

I remember there was some Python (?) script somewhere that sets the available entries but I can’t remember where it was.

Or is there some other way to do that?

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:

    "custom/patoggle": {
        "format": "{}",
        "interval": "once",
        "return-type": "json",
        "exec": "patoggle status",
        "on-click": "patoggle",
        "signal": 8
    },

You likely are only interested in the “on-click” property and want to add your own custom icon using “format”.

1 Like

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.

2 Likes

Yes, that’s the one I wad thinking about. Thanks

Ok, I tried the option of adding a custom module first as it’s much easier:

 "custom/lock": {
			"format": "L",
			"tooltip": "Lock",
			"on-click": "swaylock --color 200030"
    }

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.

Any idea why that might be?

2 Likes