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

Shared subprocesses for custom modules #1276

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rtoijala
Copy link

@rtoijala rtoijala commented Oct 3, 2021

This is an implementation of a new feature: shared subprocesses for custom modules. The feature basically allows the user to configure per-bar commands to be exec'd. The output is a JSON object with module names as keys and output as values. The configuration is described in the updated man page.

The use case for this is that I have a complicated MPD bar with custom handling for several of the modules (so I can't use the builtin MPD module) and several clickable things (so they need to be separate modules). I have a custom MPD client that creates the output for the custom modules. Without shared subprocesses, each module runs its own instance of the MPD client, creating unnecessary CPU load. This feature allows me to run the script only once, outputting data for all of the modules. I also have separate "system status bar" where I use the same setup for various statistics about the system, also with many clickable things.

Since most of the subprocess handling is now shared between the custom module and the bar, I created a new helper class "WorkerThread" which handles the configuration, starts the process, runs the thread reading the output, and calls callbacks when output is read or the child exits.

(Side note: Even before my changes, trying to refresh modules by sending signals always terminates Waybar. I'm note sure what is wrong, but since it I just moved the signal handling from one place to another and I do not use the feature myself, I did not investigate much.)

Any feedback is welcome.

Risto Toijala added 3 commits October 14, 2021 18:27
For more complicated configurations with several actions activated
through clicks on various connected modules, it is currently necessary
to have each of those connected modules exec their own subprocess to
produce the wanted output. This is problematic because it greatly
increases CPU usage.

Implement a new configuration option for bars, "custom-execs", which
contains an array of subprocess specifications ("exec", "exec_if",
"interval", "restart-interval"). The bar runs each of these executables
and reads their output. The output is in the form of a JSON object with
module names as keys and either strings (for "raw" type output) or
objects (for "json" type output) as values. These values are forwarded
to the custom modules named by the keys.
@pocek
Copy link

pocek commented Jan 25, 2022

This is a great work, but it would be even better if custom execs could be shared not only between custom modules, but also between bars. See #368 and #1203.

@pocek
Copy link

pocek commented Jan 25, 2022

In case anyone is interested, I've rebased this onto the current master: pocek/Waybar@custom-execs. It works fine for me, but I have not tested anything related to signals.

@deviant
Copy link

deviant commented Feb 24, 2022

Oh, I'd love this feature. I'm doing similar things, and being unable to share state between modules (which are all semantically a single module, I suppose!) has been really bugging me.

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.

3 participants