[PR #1274] [CLOSED] Centralised thresholds system #9700

Closed
opened 2026-05-23 03:57:19 +01:00 by JakeStanger · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/JakeStanger/ironbar/pull/1274
Author: @JakeStanger
Created: 12/7/2025
Status: Closed

Base: masterHead: feat/thresholds


📝 Commits (2)

  • 2887b08 feat(config) : standardised thresholds system
  • 5053197 refactor(volume): use standardised threshold system

📊 Changes

6 files changed (+248 additions, -59 deletions)

View changed files

📝 Cargo.lock (+39 -4)
📝 Cargo.toml (+6 -1)
📝 docs/modules/Volume.md (+37 -31)
📝 src/config/mod.rs (+2 -0)
src/config/thresholds.rs (+156 -0)
📝 src/modules/volume.rs (+8 -23)

📄 Description

Overview

This is a first draft at attempting to introduce a standardised system for configuring thresholds, ie for icon boundaries.

The system would apply to the following modules:

  • backlight (configure brightness icon, #1235)
  • network_manager (configure wifi strength icon, #1233)
  • volume (configure volume icon)

The following locations would also expand to use this with future updates:

  • battery (configure battery icon, #935)
  • music (configure volume icon)

There may also be places I've missed.

Syntaxes

This introduces three separate syntax for configuring the thresholds in an attempt to appease everybody:

Basic

Offers pre-defined low/medium/high keywords that abstract the thresholds. The thresholds are always divided into equal thirds from 0-max

icons.volume.low = "icon:volume_low"
icons.volume.medium = "icon:volume_medium"
icons.volume.high = "icon:volume_high"

Dynamic

Uses an array of dynamic length to define N number of thresholds, all equally divided from 0-max. Keys are provided in order from low-high.

icons.volume = [ "icon:volume_low" "icon_volume_medium" "icon_volume_high" ]

Manual

Uses a map to define N number of thresholds, manually specifying the lower bound for each threshold. This allows for more explicit configuration, and non-linear thresholds.

A zero threshold must be defined.

icons.volume.0 = "icon:volume_low"
icons.volume.33 = "icon:volume_medium"
icons.volume.66 = "icon:volume_high"

API

The struct would be placed inside the config:

struct Icons {
  volume: Thresholds<String>
}

Currently a single threshold_for method is provided:

let icon = icons.volume.threshold_for(curr_volume, max_volume); // Option<String>

Outstanding

  • The manual format assumes integers are used as HashMap keys. This may not be supported by all formats.
  • The naming is a little all over the place (level, threshold, value, ...). This needs improving.

Questions:

  • Is three separate syntaxes too many? Could this introduce confusion more than it creates benefit?
    • If not, which one is the preference?
  • Do we need to support negative values?
  • How do we better deal with the zero value in the map syntax?
  • How do we handle non-linear implementations (ie network manager)?
  • This conflicts with the battery module existing thresholds option. What to do there?

I am looking for feedback on this! This is a bit of a "throw everything at the wall and see what sticks" approach. Anything regarding anything I've thought of above, or anything else you see.

Paging @xMAC94x @Rodrigodd as both of you have open PRs pending a decision around this - feedback from the both of you on whether you think this would work for your modules would be especially valuable.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/JakeStanger/ironbar/pull/1274 **Author:** [@JakeStanger](https://github.com/JakeStanger) **Created:** 12/7/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `feat/thresholds` --- ### 📝 Commits (2) - [`2887b08`](https://github.com/JakeStanger/ironbar/commit/2887b0823f3965ee03aac0786195d48cd8fc24ac) feat(config) : standardised thresholds system - [`5053197`](https://github.com/JakeStanger/ironbar/commit/50531973c3cd4698b4d8dd351eb5411e92132b48) refactor(volume): use standardised threshold system ### 📊 Changes **6 files changed** (+248 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+39 -4) 📝 `Cargo.toml` (+6 -1) 📝 `docs/modules/Volume.md` (+37 -31) 📝 `src/config/mod.rs` (+2 -0) ➕ `src/config/thresholds.rs` (+156 -0) 📝 `src/modules/volume.rs` (+8 -23) </details> ### 📄 Description ## Overview This is a first draft at attempting to introduce a standardised system for configuring thresholds, ie for icon boundaries. The system would apply to the following modules: - `backlight` (configure brightness icon, #1235) - `network_manager` (configure wifi strength icon, #1233) - `volume` (configure volume icon) The following locations would also expand to use this with future updates: - `battery` (configure battery icon, #935) - `music` (configure volume icon) There may also be places I've missed. ## Syntaxes This introduces three separate syntax for configuring the thresholds in an attempt to appease everybody: ### Basic Offers pre-defined low/medium/high keywords that abstract the thresholds. The thresholds are always divided into equal thirds from `0-max` ```corn icons.volume.low = "icon:volume_low" icons.volume.medium = "icon:volume_medium" icons.volume.high = "icon:volume_high" ``` ### Dynamic Uses an array of dynamic length to define N number of thresholds, all equally divided from `0-max`. Keys are provided in order from low-high. ```corn icons.volume = [ "icon:volume_low" "icon_volume_medium" "icon_volume_high" ] ``` ### Manual Uses a map to define N number of thresholds, manually specifying the lower bound for each threshold. This allows for more explicit configuration, and non-linear thresholds. A zero threshold must be defined. ```corn icons.volume.0 = "icon:volume_low" icons.volume.33 = "icon:volume_medium" icons.volume.66 = "icon:volume_high" ``` ## API The struct would be placed inside the config: ```rust struct Icons { volume: Thresholds<String> } ``` Currently a single `threshold_for` method is provided: ```rust let icon = icons.volume.threshold_for(curr_volume, max_volume); // Option<String> ``` ## Outstanding - The `manual` format assumes integers are used as `HashMap` keys. This may not be supported by all formats. - The naming is a little all over the place (level, threshold, value, ...). This needs improving. Questions: - Is three separate syntaxes too many? Could this introduce confusion more than it creates benefit? - If not, which one is the preference? - Do we need to support negative values? - How do we better deal with the zero value in the map syntax? - How do we handle non-linear implementations (ie network manager)? - This conflicts with the `battery` module existing thresholds option. What to do there? --- I am looking for feedback on this! This is a bit of a "throw everything at the wall and see what sticks" approach. Anything regarding anything I've thought of above, or anything else you see. Paging @xMAC94x @Rodrigodd as both of you have open PRs pending a decision around this - feedback from the both of you on whether you think this would work for your modules would be especially valuable. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
JakeStanger 2026-05-23 03:57:19 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JakeStanger/ironbar#9700
No description provided.