Persist Framework power-button lighting across reboots

This commit is contained in:
ajp_anton committed 2026-10-20 13:30:03 +00:00
1 parent ddb912d4ba
commit dc2372ef3f
10 files changed
+142 -5

No files matched your search

+5 -1
View File
@@ -13,7 +13,7 @@ find_package(KF6Auth REQUIRED)
find_package(KF6Service REQUIRED) find_package(KF6Service REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd) pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd)
add_library(framework-hardware STATIC src/hardware.cpp src/fan.cpp src/cpu.cpp src/power.cpp) add_library(framework-hardware STATIC src/hardware.cpp src/fan.cpp src/cpu.cpp src/power.cpp src/lighting.cpp)
target_include_directories(framework-hardware PUBLIC src) target_include_directories(framework-hardware PUBLIC src)
target_link_libraries(framework-hardware PUBLIC Qt6::Core) target_link_libraries(framework-hardware PUBLIC Qt6::Core)
set(gui_sources src/window.cpp src/chart.cpp src/legend.cpp src/tray.cpp src/traypage.cpp src/colorbutton.cpp src/cpupage.cpp src/valuecontrol.cpp src/tooltip.cpp src/processusage.cpp) set(gui_sources src/window.cpp src/chart.cpp src/legend.cpp src/tray.cpp src/traypage.cpp src/colorbutton.cpp src/cpupage.cpp src/valuecontrol.cpp src/tooltip.cpp src/processusage.cpp)
@@ -25,16 +25,20 @@ add_executable(framework-laptop-tools-fan src/fanservice.cpp)
target_link_libraries(framework-laptop-tools-fan PRIVATE framework-hardware PkgConfig::Systemd) target_link_libraries(framework-laptop-tools-fan PRIVATE framework-hardware PkgConfig::Systemd)
add_executable(framework-laptop-tools-cpu src/cpuservice.cpp) add_executable(framework-laptop-tools-cpu src/cpuservice.cpp)
target_link_libraries(framework-laptop-tools-cpu PRIVATE framework-hardware Qt6::DBus PkgConfig::Systemd) target_link_libraries(framework-laptop-tools-cpu PRIVATE framework-hardware Qt6::DBus PkgConfig::Systemd)
add_executable(framework-laptop-tools-lighting src/lightingservice.cpp)
target_link_libraries(framework-laptop-tools-lighting PRIVATE framework-hardware)
install(TARGETS framework-laptop-tools DESTINATION ${KDE_INSTALL_BINDIR}) install(TARGETS framework-laptop-tools DESTINATION ${KDE_INSTALL_BINDIR})
install(TARGETS framework-laptop-tools-helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) install(TARGETS framework-laptop-tools-helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
install(TARGETS framework-laptop-tools-fan DESTINATION libexec) install(TARGETS framework-laptop-tools-fan DESTINATION libexec)
install(TARGETS framework-laptop-tools-cpu DESTINATION libexec) install(TARGETS framework-laptop-tools-cpu DESTINATION libexec)
install(TARGETS framework-laptop-tools-lighting DESTINATION libexec)
kauth_install_helper_files(framework-laptop-tools-helper se.ajpanton.frameworktools root) kauth_install_helper_files(framework-laptop-tools-helper se.ajpanton.frameworktools root)
kauth_install_actions(se.ajpanton.frameworktools data/se.ajpanton.frameworktools.actions) kauth_install_actions(se.ajpanton.frameworktools data/se.ajpanton.frameworktools.actions)
install(FILES data/se.ajpanton.framework-laptop-tools.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES data/se.ajpanton.framework-laptop-tools.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES data/framework-laptop-tools.json DESTINATION ${KDE_INSTALL_DATADIR}/fedora-tools/settings) install(FILES data/framework-laptop-tools.json DESTINATION ${KDE_INSTALL_DATADIR}/fedora-tools/settings)
install(FILES data/framework-laptop-tools-fan.service data/framework-laptop-tools-fan-resume.service DESTINATION /usr/lib/systemd/system) install(FILES data/framework-laptop-tools-fan.service data/framework-laptop-tools-fan-resume.service DESTINATION /usr/lib/systemd/system)
install(FILES data/framework-laptop-tools-cpu.service DESTINATION /usr/lib/systemd/system) install(FILES data/framework-laptop-tools-cpu.service DESTINATION /usr/lib/systemd/system)
install(FILES data/framework-laptop-tools-lighting.service DESTINATION /usr/lib/systemd/system)
if(BUILD_TESTING) if(BUILD_TESTING)
find_package(Qt6 6.8 REQUIRED COMPONENTS Test) find_package(Qt6 6.8 REQUIRED COMPONENTS Test)
add_executable(test-hardware tests/test-hardware.cpp) add_executable(test-hardware tests/test-hardware.cpp)
+8
View File
@@ -139,10 +139,16 @@ the system tray to suppress that effect.
- Keyboard brightness: 0–100%. **Use Fn+Space to leave or enter Auto mode.** - Keyboard brightness: 0–100%. **Use Fn+Space to leave or enter Auto mode.**
The inspected 13 Pro firmware does not expose a host command to change that The inspected 13 Pro firmware does not expose a host command to change that
mode; its ambient-light logic overrides manual percentage changes in Auto. mode; its ambient-light logic overrides manual percentage changes in Auto.
The tool does not save or restore keyboard brightness itself; Fedora's
backlight service may restore it, while firmware Auto can override it.
- Power-button brightness: 1–100%, or firmware Auto. This is the illuminated - Power-button brightness: 1–100%, or firmware Auto. This is the illuminated
power button surrounding the fingerprint reader, not its authentication. power button surrounding the fingerprint reader, not its authentication.
The Automatic brightness checkbox disables the slider; both mode and brightness The Automatic brightness checkbox disables the slider; both mode and brightness
are staged until Save and Apply. Unchecking it allows a fixed brightness to be selected. are staged until Save and Apply. Unchecking it allows a fixed brightness to be selected.
Saving writes `/etc/framework-laptop-tools/power-button.json` and enables a
one-shot service to restore the choice at boot, even without the GUI running.
Installation alone does not enable it. After upgrading from an older version,
change and save the power-button setting once to enable restoration.
- Fan: firmware Auto, manual duty, or a four-point curve. Manual values - Fan: firmware Auto, manual duty, or a four-point curve. Manual values
range from 0–100%, including fan off. Manual speeds below 30% show a warning. range from 0–100%, including fan off. Manual speeds below 30% show a warning.
Saving manual or curve speeds below 30% also requires explicit confirmation. Saving manual or curve speeds below 30% also requires explicit confirmation.
@@ -165,6 +171,8 @@ the system tray to suppress that effect.
vary with voltage and system/charger limits. Zero restores firmware defaults. vary with voltage and system/charger limits. Zero restores firmware defaults.
This is **battery charging power**, not wall power or total laptop power. This is **battery charging power**, not wall power or total laptop power.
Charge current has no read-back command in the interface used here. Charge current has no read-back command in the interface used here.
The charging-power limit is currently applied only for the running session;
it is not saved or restored by this tool.
The C-rate used by some other utilities expresses current relative to battery The C-rate used by some other utilities expresses current relative to battery
capacity: 1 C means 4.64 A for a 4.64 Ah battery, not a fixed number of watts. capacity: 1 C means 4.64 A for a 4.64 Ah battery, not a fixed number of watts.
- CPU: minimum/maximum frequency, governor and energy preference, with optional - CPU: minimum/maximum frequency, governor and energy preference, with optional
@@ -0,0 +1,22 @@
[Unit]
Description=Restore saved Framework power-button lighting
After=systemd-modules-load.service
ConditionPathExists=/etc/framework-laptop-tools/power-button.json
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
Type=oneshot
ExecStart=/usr/libexec/framework-laptop-tools-lighting
# Allow briefly for the embedded-controller driver to become available at boot.
Restart=on-failure
RestartSec=2
TimeoutStartSec=10
NoNewPrivileges=yes
ProtectHome=yes
PrivateTmp=yes
ProtectSystem=strict
RestrictAddressFamilies=AF_UNIX
[Install]
WantedBy=multi-user.target
@@ -1,6 +1,6 @@
Name: framework-laptop-tools Name: framework-laptop-tools
Version: 0.1.0 Version: 0.1.0
Release: 28%{?dist} Release: 29%{?dist}
Summary: Hardware controls and monitoring for Framework Laptop 13 Pro Summary: Hardware controls and monitoring for Framework Laptop 13 Pro
License: MIT License: MIT
URL: https://git.ajpanton.se/ajp_anton/fedora-tools URL: https://git.ajpanton.se/ajp_anton/fedora-tools
@@ -37,7 +37,7 @@ install -Dpm 0644 %{SOURCE1} %{buildroot}%{_licensedir}/%{name}/LICENSE
%post %post
%systemd_post framework-laptop-tools-fan.service framework-laptop-tools-fan-resume.service %systemd_post framework-laptop-tools-fan.service framework-laptop-tools-fan-resume.service
%preun %preun
%systemd_preun framework-laptop-tools-fan.service framework-laptop-tools-fan-resume.service framework-laptop-tools-cpu.service %systemd_preun framework-laptop-tools-fan.service framework-laptop-tools-fan-resume.service framework-laptop-tools-cpu.service framework-laptop-tools-lighting.service
%postun %postun
%systemd_postun_with_restart framework-laptop-tools-fan.service framework-laptop-tools-cpu.service %systemd_postun_with_restart framework-laptop-tools-fan.service framework-laptop-tools-cpu.service
%files %files
@@ -46,6 +46,7 @@ install -Dpm 0644 %{SOURCE1} %{buildroot}%{_licensedir}/%{name}/LICENSE
%{_bindir}/framework-laptop-tools %{_bindir}/framework-laptop-tools
%{_libexecdir}/framework-laptop-tools-fan %{_libexecdir}/framework-laptop-tools-fan
%{_libexecdir}/framework-laptop-tools-cpu %{_libexecdir}/framework-laptop-tools-cpu
%{_libexecdir}/framework-laptop-tools-lighting
%{_libexecdir}/kf6/kauth/framework-laptop-tools-helper %{_libexecdir}/kf6/kauth/framework-laptop-tools-helper
%{_datadir}/applications/se.ajpanton.framework-laptop-tools.desktop %{_datadir}/applications/se.ajpanton.framework-laptop-tools.desktop
%{_datadir}/fedora-tools/settings/framework-laptop-tools.json %{_datadir}/fedora-tools/settings/framework-laptop-tools.json
@@ -55,7 +56,11 @@ install -Dpm 0644 %{SOURCE1} %{buildroot}%{_licensedir}/%{name}/LICENSE
%{_unitdir}/framework-laptop-tools-fan.service %{_unitdir}/framework-laptop-tools-fan.service
%{_unitdir}/framework-laptop-tools-fan-resume.service %{_unitdir}/framework-laptop-tools-fan-resume.service
%{_unitdir}/framework-laptop-tools-cpu.service %{_unitdir}/framework-laptop-tools-cpu.service
%{_unitdir}/framework-laptop-tools-lighting.service
%changelog %changelog
* Wed Sep 23 2026 fedora-tools contributors - 0.1.0-29
- Save power-button brightness or Auto mode and restore it at boot
* Fri Sep 18 2026 fedora-tools contributors - 0.1.0-28 * Fri Sep 18 2026 fedora-tools contributors - 0.1.0-28
- Add an optional second numeric tray reading and P/E-core maximum frequencies - Add an optional second numeric tray reading and P/E-core maximum frequencies
+12 -1
View File
@@ -2,6 +2,7 @@
#include "hardware.h" #include "hardware.h"
#include "fan.h" #include "fan.h"
#include "cpu.h" #include "cpu.h"
#include "lighting.h"
#include <KAuth/ActionReply> #include <KAuth/ActionReply>
#include <KAuth/HelperSupport> #include <KAuth/HelperSupport>
#include <QDir> #include <QDir>
@@ -122,7 +123,17 @@ public Q_SLOTS:
error = saveConfig(savedFanConfigPath, args); error = saveConfig(savedFanConfigPath, args);
if (error.isEmpty()) error = service("start"); if (error.isEmpty()) error = service("start");
} }
} else if (operation == "powerAuto") error = setFirmwareValue(operation, 0); } else if (operation == "powerAuto" || operation == "powerBrightness") {
const QVariantMap config{{"operation", operation}, {"value", operation == "powerAuto" ? 0 : value}};
error = validatePowerButtonConfig(config);
if (!error.isEmpty()) return reply(error);
error = saveConfig(powerButtonConfigPath, config);
if (!error.isEmpty()) return reply(error);
const QString unit = "framework-laptop-tools-lighting.service";
error = service("enable", unit);
if (error.isEmpty()) error = service("restart", unit);
if (!error.isEmpty()) error = "Power-button settings were saved, but applying them failed: " + error;
}
else if (value >= 0) error = setFirmwareValue(operation, value); else if (value >= 0) error = setFirmwareValue(operation, value);
else error = "Unknown operation or invalid value."; else error = "Unknown operation or invalid value.";
return reply(error); return reply(error);
+32
View File
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
#include "lighting.h"
#include <QFile>
#include <QJsonDocument>
#include <cmath>
QString validatePowerButtonConfig(const QVariantMap &config)
{
const auto operation = config.value("operation").toString();
if (operation == "powerAuto") return {};
bool valid;
const double value = config.value("value").toDouble(&valid);
if (operation == "powerBrightness" && valid && value >= 1 && value <= 100 && std::floor(value) == value)
return {};
return "Invalid power-button setting: choose Auto or a whole-number brightness from 1 to 100%.";
}
QVariantMap readPowerButtonConfig(QString &error, const QString &path)
{
error.clear();
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) { error = file.errorString(); return {}; }
QJsonParseError parseError;
const auto document = QJsonDocument::fromJson(file.readAll(), &parseError);
if (parseError.error != QJsonParseError::NoError || !document.isObject()) {
error = "Invalid power-button settings file.";
return {};
}
const auto config = document.toVariant().toMap();
error = validatePowerButtonConfig(config);
return error.isEmpty() ? config : QVariantMap{};
}
+7
View File
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <QVariantMap>
inline const QString powerButtonConfigPath = QStringLiteral("/etc/framework-laptop-tools/power-button.json");
QString validatePowerButtonConfig(const QVariantMap &config);
QVariantMap readPowerButtonConfig(QString &error, const QString &path = powerButtonConfigPath);
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
#include "hardware.h"
#include "lighting.h"
#include <QCoreApplication>
#include <QTextStream>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QString error;
const auto config = readPowerButtonConfig(error);
if (error.isEmpty()) error = compatibilityError();
if (error.isEmpty()) error = setFirmwareValue(config["operation"].toString(), config.value("value", 0).toInt());
if (error.isEmpty()) return 0;
QTextStream(stderr) << "Could not restore power-button lighting: " << error << '\n';
return 1;
}
+1 -1
View File
@@ -243,7 +243,7 @@ QWidget *Window::batteryPage()
m_charge = spin(50, 100, "%"); m_charge->setValue(100); m_charge->setObjectName("chargeLimit"); m_charge = spin(50, 100, "%"); m_charge->setValue(100); m_charge->setObjectName("chargeLimit");
form->addRow("Limit battery:", m_charge); form->addRow("Limit battery:", m_charge);
m_watts = spin(0, 75, " W"); m_watts->setSpecialValueText("Firmware default"); m_watts->setObjectName("chargeWatts"); m_watts = spin(0, 75, " W"); m_watts->setSpecialValueText("Firmware default"); m_watts->setObjectName("chargeWatts");
m_watts->setToolTip("Zero restores firmware defaults. The current charging-power limit cannot be read back."); m_watts->setToolTip("Applies only for the current session; not saved or restored after reboot. Zero restores firmware defaults. The current charging-power limit cannot be read back.");
form->addRow("Limit charging power:", m_watts); form->addRow("Limit charging power:", m_watts);
form->addRow(note("Limiting charging power is approximate.")); form->addRow(note("Limiting charging power is approximate."));
layout->addWidget(group); layout->addStretch(); return page; layout->addWidget(group); layout->addStretch(); return page;
@@ -3,6 +3,7 @@
#include "fan.h" #include "fan.h"
#include "cpu.h" #include "cpu.h"
#include "power.h" #include "power.h"
#include "lighting.h"
#include <QTest> #include <QTest>
#include <QTemporaryDir> #include <QTemporaryDir>
#include <QDir> #include <QDir>
@@ -15,6 +16,36 @@ class HardwareTest : public QObject {
QFile file(path); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write(value), value.size()); QFile file(path); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write(value), value.size());
} }
private Q_SLOTS: private Q_SLOTS:
void powerButtonSettings() {
QVERIFY(validatePowerButtonConfig({{"operation", "powerAuto"}}).isEmpty());
for (const int brightness : {1, 50, 100})
QVERIFY(validatePowerButtonConfig({{"operation", "powerBrightness"}, {"value", brightness}}).isEmpty());
for (const QVariant &value : {QVariant(-1), QVariant(0), QVariant(101), QVariant(2.5), QVariant("invalid"), QVariant()})
QVERIFY(!validatePowerButtonConfig({{"operation", "powerBrightness"}, {"value", value}}).isEmpty());
QVERIFY(!validatePowerButtonConfig({}).isEmpty());
QVERIFY(!validatePowerButtonConfig({{"operation", "fan"}, {"value", 50}}).isEmpty());
QTemporaryDir directory;
const QString path = directory.filePath("power-button.json");
QString error;
QVERIFY(readPowerButtonConfig(error, path).isEmpty());
QVERIFY(!error.isEmpty()); // No saved setting must not turn into a default override.
for (const auto &data : {QByteArray("broken"), QByteArray("[]"), QByteArray("{}"),
QByteArray("{\"operation\":\"powerBrightness\",\"value\":0}"), QByteArray("{\"operation\":\"chargeLimit\",\"value\":80}")}) {
put(path, data);
QVERIFY(readPowerButtonConfig(error, path).isEmpty());
QVERIFY(!error.isEmpty());
}
put(path, "{\"operation\":\"powerBrightness\",\"value\":15}");
const auto fixed = readPowerButtonConfig(error, path);
QVERIFY2(error.isEmpty(), qPrintable(error));
QCOMPARE(fixed["operation"].toString(), QString("powerBrightness"));
QCOMPARE(fixed["value"].toInt(), 15);
put(path, "{\"operation\":\"powerAuto\",\"value\":0}");
QCOMPARE(readPowerButtonConfig(error, path)["operation"].toString(), QString("powerAuto"));
QVERIFY(error.isEmpty());
}
void coreGroupFrequencies() { void coreGroupFrequencies() {
QTemporaryDir root; QTemporaryDir root;
const QString base = root.path() + "/devices/system/cpu/cpufreq/"; const QString base = root.path() + "/devices/system/cpu/cpufreq/";