Skip to content

battery ​

Battery level, charging state, and a dropdown with the batteries of peripherals UPower reports (wireless mice, keyboards, controllers, pens) and power-profile controls. Low and critical battery levels send critical notifications whether or not the module is placed.

The battery is UPower's sample of the kernel's /sys/class/power_supply. Its warning levels are UPower's too, and upower.conf sets them (PercentageLow, PercentageCritical and PercentageAction, 10, 5 and 2 by default); no key here changes when a battery warns. The dropdown's gauge and percentage are painted by those levels as well: yellow at PercentageLow, red at PercentageCritical or PercentageAction, with no percentage of their own.

Add it to your layout with battery:

yaml
bar:
  layout:
    - monitor: "*"
      right: [battery]

General ​

FieldTypeDefaultDescription
level-iconsarray of string[...]Icons for battery levels from empty to full.
charging-iconstring"ld-battery-animated-symbolic"Icon shown when battery is charging.
alert-iconstring"ld-battery-animated-symbolic"Icon shown when battery is not present or in an error state.
border-showboolfalseDisplay border around button.
icon-showbooltrueDisplay module icon.
tooltipbooltrueShow the module's state in a tooltip on hover.
labelLabelMode"hover"When the label beside the icon shows the charge percentage; hover grows it out while the pointer is on the module.
formatstring"{{ percent }}%"Format string for the label.
label-max-lengthu320Max label characters before truncation with ellipsis. Set to 0 to disable.
notify-lowbooltrueSend a critical notification when the battery, or a peripheral UPower reports such as a wireless mouse, enters the low or critical warning level.
notify-charged-atPercentage0Notify once when the charging battery reaches this percentage. Set to 0 to disable.
app-napmap of NapLevel{}How hard each app naps while the user cannot see it, by app ID.
More about level-icons

The percentage is divided evenly among icons. With 5 icons: 0-20% uses icons[0], 21-40% uses icons[1], etc.

Every battery icon is also put in the state of the charge (empty, low, medium, full), charging or alert; the default is one animated icon that declares them, and an icon without states ignores them.

More about format

Placeholders ​

  • {{ percent }} - Battery level (0-100)

Examples ​

  • "{{ percent }}%" - "45%"
More about notify-low

The levels are UPower's, which upower.conf sets: PercentageLow, PercentageCritical and PercentageAction, 10, 5 and 2 by default, on battery. Each level notifies once; plugging in and unplugging again re-arms them.

The Low Power offer is not one of those levels: it comes at 20% on battery, as iOS offers it, before PercentageLow warns, so there is still charge to save by accepting it. It has a button that turns power-saver on, once until the next unplug, and never while power-saver is already on.

More about app-nap

An app not listed naps at default. Freezing and the efficiency cores are never the default: a frozen app's downloads and sockets stop, and a hidden build is real work.

Example: {"org.mozilla.firefox": "never", "com.slack.Slack": "frozen"}

Colors ​

FieldTypeDefaultDescription
border-colorColorValue"yellow"Border color token.
icon-colorColorValue"auto"Icon foreground color. Auto selects based on variant for contrast.
icon-bg-colorColorValue"yellow"Icon container background color token.
label-colorColorValue"fg-default"Label text color token.
button-bg-colorColorValue"bg-surface-elevated"Button background color token.

Click actions ​

FieldTypeDefaultDescription
left-clickClickAction"dropdown:battery"Action on left click.
right-clickClickAction""Action on right click.
middle-clickClickAction""Action on middle click.
scroll-upClickAction""Action on scroll up.
scroll-downClickAction""Action on scroll down.

Default configuration ​

yaml
modules:
  battery:
    level-icons:
      - ld-battery-animated-symbolic
    charging-icon: ld-battery-animated-symbolic
    alert-icon: ld-battery-animated-symbolic
    border-show: false
    border-color: yellow
    icon-show: true
    tooltip: true
    icon-color: auto
    icon-bg-color: yellow
    label: hover
    label-color: fg-default
    format: '{{ percent }}%'
    label-max-length: 0
    button-bg-color: bg-surface-elevated
    left-click: dropdown:battery
    right-click: ""
    middle-click: ""
    scroll-up: ""
    scroll-down: ""
    notify-low: true
    notify-charged-at: 0
    app-nap: {}

Released under the MIT License.