Shared subprocesses for custom modules #1276
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.