Skip to content

Conversation

@Cprakhar
Copy link
Contributor

@Cprakhar Cprakhar commented Feb 9, 2026

Description

This PR fixes a key issue in custom module. tooltip cannot be passed in "tooltip": "{tooltip} some random text" when return-type is json, as {tooltip} is not added in format replacements.

Before:
~/.config/waybar/scripts/pacman-updates.py

#!/usr/bin/env python3

import subprocess
import json
import logging
import sys

logger = logging.getLogger(__name__)

class PacmanUpdates:
    def __init__(self):
        self.updates = 0

    def get_updates(self):
        logger.debug("Checking for updates...")
        try:
            result = subprocess.run(
                ["checkupdates"],
                stdout=subprocess.PIPE,
                stderr=subprocess.DEVNULL,
                text=True,
                check=False,
            )
            lines = result.stdout.strip().splitlines()
            self.updates = len(lines) if lines else 0

        except Exception as e:
            logger.error(f"Error checking for updates: {e}")
            self.updates = 0

    def to_waybar_json(self):
        if self.updates > 0:
            logger.debug(f"{self.updates} updates available.")
            return {
                "text": f" {self.updates}",
                "tooltip": f"{self.updates} updates available",
            }
        else:
            logger.debug("No updates available.")
            return {
                "text": "",
                "tooltip": "System is up to date",
            }


def main():
    logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] [%(levelname)s] custom-pacman: %(message)s", stream=sys.stderr)

    pacman = PacmanUpdates()
    pacman.get_updates()
    sys.stdout.write(json.dumps(pacman.to_waybar_json()) + "\n")
    sys.stdout.flush()


if __name__ == "__main__":
    main()

custom-pacman.jsonc

    "custom/pacman": {
        "format": "󰏔 {text}",
        "exec": "~/.config/waybar/scripts/pacman-updates.py",
        "on-click": "kitty --hold yay -Syu && pkill -SIGRTMIN+8 waybar",
        "on-click-right": "~/.config/waybar/scripts/pacman-updates.py",
        "signal": 8,
        "return-type": "json",
        "tooltip": true,
        "tooltip-format": "󰏔 {tooltip}", // this way not working
        "escape": true
    }
[2026-02-10 00:03:19.806] [error] custom/pacman: argument not found

Verification

Tested locally, working fine.

Closes #4786

@Cprakhar
Copy link
Contributor Author

Cprakhar commented Feb 9, 2026

Need to update Custom module wiki, if PR merged.

@Cprakhar Cprakhar changed the title fix: add {tooltip} in format strings in custom modules feat: add {tooltip} in format strings in custom modules Feb 9, 2026
@Cprakhar Cprakhar force-pushed the fix/tooltip-return-type-in-format-strings branch from d5a3c9d to d088b3f Compare February 9, 2026 19:19
@Cprakhar Cprakhar changed the title feat: add {tooltip} in format strings in custom modules feat: add {tooltip} in format replacements in custom module Feb 9, 2026
@Cprakhar Cprakhar force-pushed the fix/tooltip-return-type-in-format-strings branch from d088b3f to f96fb53 Compare February 9, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tooltips do not display provided values

1 participant