Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/battery level labels #402

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 84 additions & 20 deletions GlazeWM.Bar/Components/BatteryComponentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,95 @@ public LabelViewModel CreateLabel()

// Display the battery level as a 100% if device has no dedicated battery.
if (ps.BatteryFlag == 128)
return XamlHelper.ParseLabel(
_config.LabelDraining,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelDrainingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelDrainingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelDrainingHigh,
CreateVariableDict(batteryLevel),
this
)
};

if (ps.ACLineStatus == 1)
return XamlHelper.ParseLabel(
_config.LabelCharging,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelChargingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelChargingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelChargingHigh,
CreateVariableDict(batteryLevel),
this
)
};

if (ps.SystemStatusFlag == 1)
return XamlHelper.ParseLabel(
_config.LabelPowerSaver,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverHigh,
CreateVariableDict(batteryLevel),
this
)
};

return XamlHelper.ParseLabel(
_config.LabelDraining,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelDrainingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelDrainingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelDrainingHigh,
CreateVariableDict(batteryLevel),
this
)
};
}

public static Dictionary<string, Func<string>> CreateVariableDict(string batteryLevel)
Expand Down
36 changes: 30 additions & 6 deletions GlazeWM.Domain/UserConfigs/BatteryComponentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,40 @@ namespace GlazeWM.Domain.UserConfigs
public class BatteryComponentConfig : BarComponentConfig
{
/// <summary>
/// Formatted text to display when the device is draining battery power.
/// Formatted text to display when the device is draining battery power and battery level is low.
/// </summary>
public string LabelDraining { get; set; } = "{battery_level}%";
public string LabelDrainingLow { get; set; } = "{battery_level}% (low)";
/// <summary>
/// Formatted text to display when the device is in power saving mode.
/// Formatted text to display when the device is draining battery power and battery level is medium.
/// </summary>
public string LabelPowerSaver { get; set; } = "{battery_level}% (power saver)";
public string LabelDrainingMedium { get; set; } = "{battery_level}% (medium)";
/// <summary>
/// Formatted text to display when the device is connected to power.
/// Formatted text to display when the device is draining battery power and battery level is high.
/// </summary>
public string LabelCharging { get; set; } = "{battery_level}% (charging)";
public string LabelDrainingHigh { get; set; } = "{battery_level}% (high)";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is low.
/// </summary>
public string LabelPowerSaverLow { get; set; } = "{battery_level}% (power saver) (low)";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is medium.
/// </summary>
public string LabelPowerSaverMedium { get; set; } = "{battery_level}% (power saver) (medium)";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is high.
/// </summary>
public string LabelPowerSaverHigh { get; set; } = "{battery_level}% (power saver) (high)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is low.
/// </summary>
public string LabelChargingLow { get; set; } = "{battery_level}% (charging) (low)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is medium.
/// </summary>
public string LabelChargingMedium { get; set; } = "{battery_level}% (charging) (medium)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is high.
/// </summary>
public string LabelChargingHigh { get; set; } = "{battery_level}% (charging) (high)";
}
}
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,33 @@ Additionally supported format specifiers:
### Bar Component: Battery

The battery component displays the system's battery level in percent.
There are three labels available that can be customized:

- `label_draining`: used when the system is draining battery power(i.e. not charging).
- `label_power_saver`: used when the system is on power saving mode.
- `label_charging`: used when the system is connected to power.
There are nine labels available that can be customized:

- `label_draining_low`: used when the system is draining battery power(i.e. not charging) and the battery level is low.
- `label_draining_medium`: used when the system is draining battery power(i.e. not charging) and the battery level is medium.
- `label_draining_high`: used when the system is draining battery power(i.e. not charging) andthe battery level is high.
- `label_power_saver_low`: used when the system is on power saving mode and the battery level is low.
- `label_power_saver_medium`: used when the system is on power saving mode and the battery level is medium.
- `label_power_saver_high`: used when the system is on power saving mode and the battery level is high.
- `label_charging_low`: used when the system is connected to power and the battery level is low.
- `label_charging_medium`: used when the system is connected to power and the battery level is medium.
- `label_charging_high`: used when the system is connected to power and the battery level is high.

`{battery_level}` is a variable which is replaced by the actual battery level when the label is displayed.

**Example usage:**

```yaml
- type: "battery"
label_draining: "{battery_level}% remaining"
label_power_saver: "{battery_level}% (power saver)"
label_charging: "{battery_level}% (charging)"
label_draining_low: "{battery_level}% remaining (low)"
label_draining_medium: "{battery_level}% remaining (medium)"
label_draining_high: "{battery_level}% remaining (high)"
label_power_saver_low: "{battery_level}% (power saver) (low)"
label_power_saver_medium: "{battery_level}% (power saver) (medium)"
label_power_saver_high: "{battery_level}% (power saver) (high)"
label_charging_low: "{battery_level}% (charging) (low)"
label_charging_medium: "{battery_level}% (charging) (medium)"
label_charging_high: "{battery_level}% (charging) (high)"
```

### Bar Component: CPU Usage
Expand Down