-
-
Notifications
You must be signed in to change notification settings - Fork 899
PowerAdapter
Print power adapter name and charging watts
| Module type | poweradapter |
| Default order | 46 (only used by --gen-config) |
| Module source | src/modules/poweradapter/poweradapter.c |
| Detection source | src/detection/poweradapter/ |
Prints one line per detected mains power supply. The default line is the adapter's name, and falls back to its wattage when the name is empty:
Power Adapter: 65W
That fallback is the normal case on Linux — see the pitfalls. Everything else the detection layer
reads (manufacturer, model, description, serial) is only reachable through a custom format or the
JSON output.
| Platform | Implementation | Notes |
|---|---|---|
| Linux | poweradapter_linux.c |
Reads /sys/class/power_supply/
|
| macOS | poweradapter_apple.c |
IOPSCopyExternalPowerAdapterDetails() |
| Windows | poweradapter_nosupport.c |
Reports Not supported on this platform
|
| Android | poweradapter_nosupport.c |
Not supported, even though it is a Linux kernel |
| FreeBSD / MidnightBSD / DragonFly | poweradapter_nosupport.c |
Not supported |
| NetBSD | poweradapter_nosupport.c |
Not supported |
| OpenBSD | poweradapter_nosupport.c |
Not supported |
| Solaris / illumos | poweradapter_nosupport.c |
Not supported |
| Haiku | poweradapter_nosupport.c |
Not supported |
| GNU/Hurd | poweradapter_nosupport.c |
Not supported |
Only Linux and macOS have an implementation — Android compiles the nosupport stub despite having a
Linux kernel. Elsewhere the module reports
Not supported on this platform, which becomes the JSON error and — because
display.showErrors defaults to false — makes the text run print nothing at all.
| Key | Type | Default | Description |
|---|---|---|---|
key |
string | Power Adapter |
Module key. A single space hides the key and the separator |
keyColor |
color | – | Overrides display.color.keys
|
keyIcon |
string | built-in glyph | Printed when display.key.type includes the icon bit. Any glyph works; "" prints none. |
keyWidth |
integer | – | Overrides display.key.width
|
outputColor |
color | – | Overrides display.color.output
|
format |
string | – | Custom output format (see below) |
condition |
object | – | Show the module only if the conditions match |
There is no module-specific option. Every key other than the generic ones produces
Unknown JSON key ….
Run fastfetch -h poweradapter-format for the authoritative list.
| Variable | Description |
|---|---|
{watts} |
Power adapter watts |
{name} |
Power adapter name |
{manufacturer} |
Power adapter manufacturer |
{model-name} |
Power adapter model |
{description} |
Power adapter description |
{serial} |
Power adapter serial number |
None of the six is marked * in the help output, so none is available in the key format.
{watts} is a plain integer with no unit — 65, not 65W. The default line is the only place the
W suffix appears, and it is appended by the module itself.
-
resultis always an array, one object per adapter. When detection fails the module carries{"type": "PowerAdapter", "error": "…"}instead, with noresultkey. -
wattsis a number; the five other fields are strings and are""when unknown — nevernulland never omitted. - The key inside the object is
modelName, notmodel-name: the JSON uses camelCase while the format variable uses a hyphen. - The key order inside each object is
description,manufacturer,modelName,name,serial,watts.
// Watts with the unit, plus the manufacturer
{ "type": "poweradapter", "format": "{watts}W ({manufacturer})" }// The model and serial, skipping everything else
{ "type": "poweradapter", "format": "{model-name} #{serial}" }// Rename the line
{ "type": "poweradapter", "key": "Charger" }-
On Linux the name is always empty, so the default line is always a wattage. The Linux backend
fills
watts,manufacturer,modelNameandserialbut never touchesname, anddescriptionstays empty as well.Power Adapter: 65Wis therefore the only shape the default line can take there, and a config that wants a nicer line has to setformatexplicitly. -
An empty result is an error in text but an empty array in JSON. The text path reports
No power adapters foundwhen the list is empty; the JSON path has no such check and emits{"result": []}with noerror. The same divergence exists inkeyboardandmouse. -
Linux only reports adapters that are online right now. A supply is skipped when
presentis0, whentypeis not exactlyMains, whenscopeisDevice, or whenonlineis not1. A charger that is plugged in but not currently supplying power therefore disappears, and so does a battery (whosetypeisBattery). -
wattson Linux comes frominput_power_limit, not from a nameplate rating. The sysfs value is in microwatts and is divided by 1e6 and rounded, so it is the kernel's current input power limit. On a machine that negotiates a lower limit the number changes, and a supply that does not exposeinput_power_limitat all is skipped entirely. -
wattscan legitimately be0. Both backends initialise it to0and only overwrite it when the corresponding key is present, so0means "unknown" rather than "no power". -
macOS reports nothing at all when running on battery.
IOPSCopyExternalPowerAdapterDetails()returnsNULLwith no adapter connected, which is the common case — the module then falls into the empty-list branch rather than reporting an error. -
On macOS the model and serial have numeric fallbacks. When the
Modelstring is missing the adapter id (kIOPSPowerAdapterIDKey) is formatted as a decimal number instead, and whenSerialStringis missing the serial number is formatted as upper-case hex ("%X", no0xprefix). Both fallbacks leave a numeric-looking string where a name would be expected. -
Windows, the BSDs, Solaris, Haiku and GNU/Hurd have no implementation, so on those platforms
the module never prints anything unless
display.showErrorsistrue.
ffDetectPowerAdapter() appends FFPowerAdapterResult values (five FFstrbufs — description,
name, modelName, manufacturer, serial — plus an int watts) to a list and returns an error
string. ffPrintPowerAdapter() and ffGeneratePowerAdapterJsonResult() each call it and each
release the strings of every element afterwards; nothing is cached, so a --dynamic-interval run
re-reads the supply state on every round.
With more than one adapter the lines are numbered by index, and with a single adapter the bare key is printed.
/sys/class/power_supply/ is enumerated with opendir() and each entry is opened with openat().
An entry is kept only when all of these hold: present is not 0, type is exactly Mains
(after trimming trailing whitespace), scope is either missing or not Device, online is 1, and
input_power_limit exists and is non-empty. watts is input_power_limit / 1e6 rounded to the
nearest integer. manufacturer, model_name and serial_number are read and trimmed; when
manufacturer is missing and the directory is named macsmc-ac (Apple Silicon under Asahi) it is
set to Apple Inc. name and description are left empty.
IOPSCopyExternalPowerAdapterDetails() is called once and, when the dictionary contains
kIOPSPowerAdapterWattsKey, a single adapter is produced. name comes from kIOPSNameKey,
manufacturer from Manufacturer, description from Description, and watts from
kIOPSPowerAdapterWattsKey. modelName comes from the Model string with the numeric adapter id as
a fallback, and serial from SerialString with the numeric serial in hex as a fallback. Note that
this backend can only ever produce one adapter, whereas the Linux one produces as many as sysfs
exposes.
[ { "type": "PowerAdapter", "result": [ { "description": "", "manufacturer": "Apple Inc.", "modelName": "", "name": "", "serial": "0", "watts": 65 } ] } ]