mirror of
https://github.com/JakeStanger/ironbar.git
synced 2026-07-11 05:15:23 +01:00
[PR #1349] [MERGED] Standardised profiles system #6945
Labels
No labels
A:Build
A:CI
A:Client
A:Config
A:Core
A:Documentation
A:Documentation
A:IPC
A:Testing
A:UX/UI
blocked
BREAKING CHANGE
duplicate
good first issue
GTK4
help wanted
invalid
M:Battery
M:Battery
M:Bindmode
M:Bluetooth
M:Brightness
M:Cairo
M:Clipboard
M:Clock
M:Clock
M:Custom
M:Focused
M:Keyboard
M:Launcher
M:Menu
M:Music
M:Music
M:Music
M:Network Manager
M:Notifications
M:SysInfo
M:Tray
M:Volume
M:Workspaces
partially resolved
P:Critical
P:High
P:Low
P:Medium
pull-request
T:Bug
T:Bug
T:Core Enhancement
T:Module Enhancement
T:New Module
T:Question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
JakeStanger/ironbar#6945
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/JakeStanger/ironbar/pull/1349
Author: @JakeStanger
Created: 1/27/2026
Status: ✅ Merged
Merged: 2/3/2026
Merged by: @JakeStanger
Base:
master← Head:feat/profiles📝 Commits (3)
775b1b1feat(config): standardised profiles systembb9b337feat(volume): introduce profiles support1d0b966feat(battery): introduce profiles support📊 Changes
12 files changed (+970 additions, -258 deletions)
View changed files
📝
docs/Development guide.md(+108 -0)➕
docs/Profiles.md(+125 -0)📝
docs/_Sidebar.md(+1 -0)📝
docs/modules/Battery.md(+8 -7)📝
docs/modules/Volume.md(+20 -20)📝
src/config/mod.rs(+2 -0)➕
src/config/profiles.rs(+379 -0)📝
src/modules/battery.rs(+107 -85)📝
src/modules/mod.rs(+4 -0)➕
src/modules/volume/config.rs(+113 -0)📝
src/modules/volume/mod.rs(+74 -144)📝
test-configs/battery.corn(+29 -2)📄 Description
Adds a new standard configuration system for setting up module "profiles", which allow a defined subset of the configuration to change reactively when a certain value (volume, battery, brightness) reaches defined thresholds.
The primary use of this system is to allow for dynamic icons (ie the volume indicator, wifi strength indicator) to be fully configurable. This approach also allows for any options included in a profile definition to be part of the same system.
It also introduces a more declarative reactive UI approach via the profile update callback, which should in time lead to cleaner module code.
Included in this PR is support for the following modules:
volume(configure volume icon)battery(configure format)The system would additionally apply to the following modules:
backlight(configure brightness icon, #1235)network_manager(configure wifi strength icon, #1233)The following locations would also expand to use this with future updates:
battery(configure battery icon, #935)music(configure volume icon)In future,
sys_infomay also be supported, although this is not being considered for now.Configuration
Profiles always include a "default" which is merged flat into the config. This means setting eg
icons.volumeoutside of the profiles object will apply if no other profile definition takes precedent.Each profile must include a
whenkey, which indicates the threshold. Once the monitored value (eg volume %) is less than or equal to the threshold, this profile activates.Only one profile is active at a time. In the example below, if the volume was
<= 33%, the low profile would activate.Same config in JSON for clarity & highlighting
The system also supports compound matchers, which is suitable where a single state value is not considered sufficient. These should be kept simple and contain a minimal amount of values, two or three at an absolute push.
An example below for the battery module. A
percentvalue must be provided. Achargingvalue can also be provided, which takes higher priority.JSON
Each profile is named according to its key (low, medium). When a profile is active, a class name is appended to the relevant widget in the form
profile-{name}. This allows for dynamic styling (#415), and for replacing the batterythresholdsoption.Config API
The API is more involved than the original thresholds design.
Within a configuration struct you'd place a
profilesfield of typeProfiles<S, T>.Srepresents the state/matcher type, andTrepresents the configuration contained within a profile.You must include
#[serde(flatten)]on the field to avoid a doubleprofiles.profilessyntax and ensure the default is merged at the top-level correctly.Compound state
Complex state objects must manually implement the
PartialOrdandStatetraits. DerivingPartialOrdwill likely produce an incorrect sorter.The PartialOrd implementation must obey the following rules:
Somevariant is less than aNone. This is because internally the first matching profile is used.The state implementation requires a single method, which checks whether an input state matches the profile matcher. Again optional fields need to be considered here - if omitted in
&self(the config value), matching should ignore this field.Profiles
Each module should provide a default implementation for its profile type, and a set of appropriate default profiles.
Defaults
Due to serde limitations, relying on
#[serde(default = "default_profiles")]does not work, and these must be injected manually. A new module lifecycle method has been added namedon_createwhich takes a&mut self, allowing for alterations to the config as appropriate.The
Profilesstruct exposes asetup_defaultsmethod which takes anotherProfilesinstance and merges it in. Any keys which do not exist in the user's configuration are added from the defaults.The
profiles!macro allows for quick creation of the profile map.Module API
The
Profilesstruct exposes anattachmethod, which allows you to connect a 'primary' widget to the configuration (upon which the classnames are added), and an update callback.This callback includes arguments for the widget and event data. Event data includes the value sent in the update, the associated profile configuration (including the default), and any user-data sent in the update.
The
attachmethod returns a profiles manager used for dispatching updates.Updates can then be sent elsewhere in the module code using
manager.update.Outstanding
thresholdsoptionSupersedes https://github.com/JakeStanger/ironbar/pull/1274
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.