feat(disk)!: handle multiple disks at once#4762
feat(disk)!: handle multiple disks at once#4762szbmrk wants to merge 1 commit intoAlexays:masterfrom
Conversation
|
I know that this is possible to do this multiple disk handling with workarounds and multiple widgets. But for me for example one of the reasons why i implemented this is the tooltip, so if i only have for example a label like disks and hover over it i can see all my different disk information in one tooltip (i haven't found a workaround for it with the current disk widget). |
There was a problem hiding this comment.
Pull request overview
This PR adds support for monitoring multiple disks simultaneously in the disk module. The module previously supported only a single disk path, and now supports an array of paths with configurable header and separator text.
Changes:
- Added support for multiple disk paths via new
pathsarray configuration option - Deprecated single
pathoption with backward compatibility and warning - Added
headerandseparatorconfiguration options for customizing multi-disk display
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| include/modules/disk.hpp | Updated member variables: replaced path_ string with paths_ vector, added header_ and separator_ strings |
| src/modules/disk.cpp | Modified constructor to parse new configuration options; refactored update() to loop over multiple paths and aggregate disk information |
| man/waybar-disk.5.scd | Updated documentation to describe new configuration options and usage examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| *paths*: ++ | ||
| typeof: array ++ | ||
| default: ["/"] ++ | ||
| Array of paths residing in the filesystem or mountpoint for which the information should be displayed. | ||
|
|
||
| *header*: ++ | ||
| typeof: string ++ | ||
| default: "" ++ | ||
| Text to appear before the disk information defined in the format. | ||
|
|
||
| *separator*: ++ | ||
| typeof: string ++ | ||
| default: " " ++ | ||
| Separator string between multiple disk informations. | ||
|
|
There was a problem hiding this comment.
The deprecated "path" configuration option is not documented. Since the PR description states this is a breaking change with backward compatibility and existing configurations using "path" will continue to work with a deprecation warning, the documentation should mention this deprecated option and indicate that users should migrate to "paths".
| util::SleeperThread thread_; | ||
| std::string path_; | ||
| std::string header_; | ||
| std::vector<std::string> paths_; |
There was a problem hiding this comment.
The header file uses std::vector but does not include the vector header. While this may compile due to transitive includes, it's fragile and violates best practices. Add #include <vector> to the includes section.
src/modules/disk.cpp
Outdated
| std::string tooltip_format = "{used} used out of {total} on {path} ({percentage_used}%)"; | ||
| if (config_["tooltip-format"].isString()) { | ||
| tooltip_format = config_["tooltip-format"].asString(); | ||
| } | ||
| label_.set_tooltip_text(fmt::format( | ||
| fmt::runtime(tooltip_format), stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), | ||
| fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("used", used), | ||
| fmt::arg("percentage_used", percentage_used), fmt::arg("total", total), | ||
| fmt::arg("path", path_), fmt::arg("specific_free", specific_free), | ||
| fmt::arg("specific_used", specific_used), fmt::arg("specific_total", specific_total))); | ||
|
|
||
| tooltip_label += | ||
| fmt::format(fmt::runtime(tooltip_format), stats.f_bavail * 100 / stats.f_blocks, | ||
| fmt::arg("free", free), | ||
| fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), | ||
| fmt::arg("used", used), fmt::arg("percentage_used", percentage_used), | ||
| fmt::arg("total", total), fmt::arg("path", path), | ||
| fmt::arg("specific_free", specific_free), | ||
| fmt::arg("specific_used", specific_used), | ||
| fmt::arg("specific_total", specific_total)) + | ||
| (i < paths_.size() - 1 ? "\n" : ""); |
There was a problem hiding this comment.
When disk_format is empty, the disk information is skipped in the label (lines 90-103) but is still added to the tooltip (lines 105-119). This creates an inconsistency where the tooltip might show information for disks that aren't displayed in the label. The tooltip generation should also be conditional on the format not being empty.
src/modules/disk.cpp
Outdated
| if (disk_format.empty()) { | ||
| event_box_.hide(); | ||
| } else { | ||
| event_box_.show(); |
There was a problem hiding this comment.
The event_box_.hide() and show() calls inside the loop (lines 91 and 93) cause the visibility state to toggle on every iteration. The final visibility depends on the last disk processed, not on whether any valid disk information exists. This should be refactored: collect all valid disk information first, then show/hide the box once after the loop based on whether any valid data was collected. For example, track whether any disk had valid content, and only call show/hide after the loop completes.
src/modules/disk.cpp
Outdated
| fmt::arg("specific_free", specific_free), | ||
| fmt::arg("specific_used", specific_used), | ||
| fmt::arg("specific_total", specific_total)) + | ||
| (i < paths_.size() - 1 ? separator_ : ""); |
There was a problem hiding this comment.
The separator logic is fragile when some disks have empty formats or fail to load. If the last disk in paths_ has an empty format, previous disks will still add separators based on their index, potentially leaving a trailing separator in the output. The separator should only be added if there are more valid disks to display after the current one, not just based on the array index.
src/modules/disk.cpp
Outdated
| fmt::arg("specific_free", specific_free), | ||
| fmt::arg("specific_used", specific_used), | ||
| fmt::arg("specific_total", specific_total)) + | ||
| (i < paths_.size() - 1 ? "\n" : ""); |
There was a problem hiding this comment.
The same separator issue affects tooltips: if the last disk has an empty format or fails to load, there could be a trailing newline in the tooltip text.
|
@Alexays i implemented all the suggestions. |
da94e58 to
ca0b068
Compare
Summary
This PR adds support for monitoring multiple disks/mountpoints simultaneously in the disk module.
Breaking Changes
pathconfiguration option is deprecated in favor ofpathsarraypathwill continue to work with a deprecation warningNew Configuration Options
paths: Array of paths to monitor (default:["/"])header: Optional text displayed before disk information (default:"")separator: Text separator between disk entries (default:" ")Example Configuration