Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom modules: ability to hide a module? #3341

Closed
vikanezrimaya opened this issue Jun 8, 2024 · 6 comments · Fixed by #3395
Closed

Custom modules: ability to hide a module? #3341

vikanezrimaya opened this issue Jun 8, 2024 · 6 comments · Fixed by #3395

Comments

@vikanezrimaya
Copy link

vikanezrimaya commented Jun 8, 2024

I have a persistent module that uses JSON output to Waybar. I want it to be able to hide itself when the module thinks it has nothing useful to display — however, after reviewing src/modules/custom.cpp I found no obvious way for a JSON module to hide itself (other than exiting with a non-zero exit code, being restarted and not producing any output — but I would like to avoid that for efficiency reasons).

Possible API design:

  • {} hides the module
  • {"display": false} (a new key) hides the module until a new update arrives where it is unset or set to true
  • empty line hides the module until a non-empty line is produced
@vikanezrimaya
Copy link
Author

vikanezrimaya commented Jun 8, 2024

It seems this got mistakenly labeled as "clock". Whoever has the ability to change labels may want to fix that. (looks like "update" got mistaken for "date" by the labeler. May be useful to add a whitespace matcher to the regex?)

@RobertMueller2
Copy link
Contributor

I'm not 100% sure I understand it correctly, but when I return {} from a continuous script, the module does disable its event box. Is that not what you want to achieve?

E.g. test-output2.sh

#!/bin/sh

TEXT="";
TOOLTIP="DND is enabled";

if [ -e /home/user/tmp/testxyz ];then
  TEXT="";
  TOOLTIP="Notifications are enabled";
  printf '{"text": "%s", "tooltip": "%s"}\n' "$TEXT" "$TOOLTIP"
fi

printf '{}'

test config:

{
    "layer": "top", // Waybar at top layer
    "position": "top", // Waybar position (top|bottom|left|right)
    "height" : 50,
    "modules-center": ["custom/test-output"],

    "custom/test-output": {
      "exec": "/home/user/tmp/test-output2.sh",
      "return-type":"json",
      "interval": 1,
    },
}

test style:

window {
    background-color: transparent;
}

#custom-test-output {
    color: #ffffff;
    background-color: #ff0000;
}

testxyz exists: satty-20240630-11:52:26
testxyz gone: satty-20240630-11:53:29

@vikanezrimaya
Copy link
Author

Sadly, this doesn't work when using some sort of markup, e.g.:

{
  "exec": "/nix/store/0cj7jr5z48q2zki62a3hiysdqrcdvd1n-modem-watcher/bin/modem-watcher",
  "format": "{}  <span size=\"200%\" baseline_shift=\"-3pt\">{icon}</span>",
  "return-type": "json",
  "format-icons": { /* elided for brevity */ }
}

Script prints {}, but it looks like this:
20240630_214937_grim

Because the rest of the format markup is still present, the widget doesn't hide itself anymore.

Instead, if a special-case was made to explicitly set visible property to false, expected behavior would be achieved.

@RobertMueller2
Copy link
Contributor

Thanks for elaborating. Can you try #3395 with "hide-empty-text": true,?

I should imagine the name of the config option is subject to change if the PR is merged. ;)

@vikanezrimaya
Copy link
Author

Can confirm provided patch resolves the issue. Thank you!

(btw GitHub uses "resolves", "closes" or "fixes" as the magic word that closes a related issue, not "addresses", you might wanna fix that in the PR description)

@RobertMueller2
Copy link
Contributor

I had no idea, thanks. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants