diff --git a/src/components/format_indicator.rs b/src/components/format_indicator.rs index 8b01710e..90625197 100644 --- a/src/components/format_indicator.rs +++ b/src/components/format_indicator.rs @@ -50,12 +50,14 @@ impl<'a, Msg: 'static + Clone> From> for Element<'a, Ms let content = match fi.format { SettingsFormat::Icon => fi.icon.to_text().into(), - SettingsFormat::Percentage | SettingsFormat::Time | SettingsFormat::Name => { - fi.label_element - } + SettingsFormat::Percentage + | SettingsFormat::Time + | SettingsFormat::Name + | SettingsFormat::PercentageAndTime => fi.label_element, SettingsFormat::IconAndPercentage | SettingsFormat::IconAndTime - | SettingsFormat::IconAndName => row![fi.icon.to_text(), fi.label_element] + | SettingsFormat::IconAndName + | SettingsFormat::IconAndPercentageAndTime => row![fi.icon.to_text(), fi.label_element] .spacing(space.xxs) .align_y(Alignment::Center) .into(), diff --git a/src/config.rs b/src/config.rs index 3c5eb138..3764c769 100644 --- a/src/config.rs +++ b/src/config.rs @@ -595,6 +595,8 @@ pub enum SettingsFormat { IconAndTime, Name, IconAndName, + PercentageAndTime, + IconAndPercentageAndTime, } #[derive(Deserialize, Clone, Default, PartialEq, Eq, Debug)] diff --git a/src/modules/settings/power.rs b/src/modules/settings/power.rs index 9d7f725d..6262f576 100644 --- a/src/modules/settings/power.rs +++ b/src/modules/settings/power.rs @@ -292,6 +292,29 @@ impl PowerSettings { SettingsFormat::Name | SettingsFormat::IconAndName => { convert::Into::>::into(icon(p.get_icon_state())) } + SettingsFormat::PercentageAndTime => row!( + text(format!("{}%", p.data.capacity)), + text(format_time_for_battery(&p.data)) + ) + .spacing(space.xxs) + .align_y(Alignment::Center) + .into(), + SettingsFormat::IconAndPercentageAndTime => { + let battery_capacity = format!("{}%", p.data.capacity); + let battery_time = format_time_for_battery(&p.data); + if battery_time == "100%" || battery_time == battery_capacity { + row!(icon(p.get_icon_state()), text(battery_capacity)) + } else { + row!( + icon(p.get_icon_state()), + text(battery_capacity), + text(battery_time) + ) + } + } + .spacing(space.xxs) + .align_y(Alignment::Center) + .into(), }) .style(move |theme: &Theme| container::Style { text_color: Some(match state { @@ -333,6 +356,16 @@ impl PowerSettings { SettingsFormat::Time | SettingsFormat::IconAndTime => { format_time_for_battery(&battery) } + SettingsFormat::PercentageAndTime + | SettingsFormat::IconAndPercentageAndTime => { + let battery_time = format_time_for_battery(&battery); + let battery_capacity = format!("{}%", battery.capacity); + if battery_time == "100%" || battery_time == battery_capacity { + battery_capacity + } else { + battery_capacity + " " + &battery_time + } + } _ => format!("{}%", battery.capacity), }; diff --git a/website/docs/configuration/full_config.md b/website/docs/configuration/full_config.md index e5187864..cbb9303f 100644 --- a/website/docs/configuration/full_config.md +++ b/website/docs/configuration/full_config.md @@ -132,7 +132,7 @@ audio_sources_more_cmd = "pavucontrol -t 4" wifi_more_cmd = "nm-connection-editor" vpn_more_cmd = "nm-connection-editor" bluetooth_more_cmd = "blueberry" -battery_format = "IconAndPercentage" # (default), "Icon", "Percentage", "Time", "IconAndTime" +battery_format = "IconAndPercentage" # (default), "Icon", "Percentage", "Time", "IconAndTime", "PercentageAndTime", "IconAndPercentageAndTime" # battery_hide_when_full = false # (default) # peripheral_indicators = "All" # (default) or { Specific = ["Keyboard", "Mouse", "Headphones", "Gamepad"] } peripheral_battery_format = "Icon" # (default), "IconAndPercentage", "Percentage", etc. diff --git a/website/docs/configuration/modules/settings.md b/website/docs/configuration/modules/settings.md index b6acab23..348a1297 100644 --- a/website/docs/configuration/modules/settings.md +++ b/website/docs/configuration/modules/settings.md @@ -101,6 +101,8 @@ The possible values are: - `IconAndPercentage` - Show both the battery icon and percentage (default) - `Time` - Show smart time display (time to full when charging, time to empty when discharging, "100%" when full) - `IconAndTime` - Show battery icon with smart time display +- `PercentageAndTime` - Show the battery percentage along with smart time display +- `IconAndPercentageAndTime` - Show battery icon with battery percentage and smart time display ```toml [settings]