Skip to content

Commit fd960f4

Browse files
mhduiydeepin-bot[bot]
authored andcommitted
feat(power): add session power management plugin
1. Add new session-level power management plugin with org.deepin.dde.Power1 DBus service 2. Implement power save plan management with balance, performance, and power saver modes 3. Add low power notification and auto-sleep with configurable percentage and time thresholds 4. Implement idle detection (Wayland + X11), screen dimming/off/turn-off control 5. Add lid switch handler and sleep inhibitor mechanism for active operations 6. Include 20+ language translations and DBus service configuration files 7. Add qt6-tools-dev-tools and libudev-dev build dependencies Log: Add session-level power management plugin with DBus service, power save plans, low power management, idle detection, and screen control feat(power): 添加会话级电源管理插件 1. 新增会话级电源管理插件,提供 org.deepin.dde.Power1 DBus 服务接口 2. 实现电源节能方案管理,支持平衡、高性能、节能三种模式 3. 添加低电量通知与自动休眠功能,支持百分比和时间阈值配置 4. 实现空闲检测(Wayland 和 X11),支持屏幕调暗、熄屏、关闭显示器控制 5. 添加合盖事件处理和活跃操作防休眠机制 6. 包含 20+ 语言翻译文件及 DBus 服务配置文件 7. 新增 qt6-tools-dev-tools 和 libudev-dev 编译依赖 Log: 添加会话级电源管理插件,包含 DBus 服务、节能方案、低电量管理、空闲检测及屏幕控制 PMS: BUG-346597 PMS: BUG-346589 PMS: BUG-346575
1 parent 4d24b6e commit fd960f4

61 files changed

Lines changed: 5394 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

debian/control

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Build-Depends: debhelper (>= 11),
66
pkg-config,
77
cmake,
88
qt6-base-dev,
9+
qt6-tools-dev-tools,
10+
qt6-wayland-dev,
11+
qt6-wayland-private-dev,
12+
qt6-wayland-dev-tools,
913
libsystemd-dev,
1014
libpcap-dev,
1115
libnet-dev,
@@ -15,6 +19,9 @@ Build-Depends: debhelper (>= 11),
1519
libx11-dev,
1620
libxcb-randr0-dev,
1721
libxcb1-dev,
22+
treeland-protocols,
23+
wlr-protocols,
24+
wayland-protocols,
1825
Standards-Version: 4.1.3
1926
Homepage: https://github.com/linuxdeepin
2027

src/plugin-qt/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
add_subdirectory("thememanager")
66
add_subdirectory("wallpapercache")
77
add_subdirectory("wallpaperslideshow")
8-
add_subdirectory("xsettings")
8+
add_subdirectory("xsettings")
9+
add_subdirectory("power")

src/plugin-qt/power/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
#
3+
# SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
add_subdirectory(session)
6+
# TODO: system-level power is provided by dde-daemon's dde-system-daemon
7+
# for both X11 and Wayland. Remove this when unified.
8+
# add_subdirectory(system)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
#pragma once
6+
7+
namespace PowerDConfig {
8+
inline constexpr auto kAppId = "org.deepin.dde.daemon";
9+
inline constexpr auto kPowerName = "org.deepin.dde.daemon.power";
10+
11+
inline constexpr auto kLinePowerScreensaverDelay = "linePowerScreensaverDelay";
12+
inline constexpr auto kLinePowerScreenBlackDelay = "linePowerScreenBlackDelay";
13+
inline constexpr auto kLinePowerSleepDelay = "linePowerSleepDelay";
14+
inline constexpr auto kLinePowerLockDelay = "linePowerLockDelay";
15+
inline constexpr auto kLinePowerLidClosedAction = "linePowerLidClosedAction";
16+
inline constexpr auto kLinePowerPressPowerButton = "linePowerPressPowerButton";
17+
18+
inline constexpr auto kBatteryScreensaverDelay = "batteryScreensaverDelay";
19+
inline constexpr auto kBatteryScreenBlackDelay = "batteryScreenBlackDelay";
20+
inline constexpr auto kBatterySleepDelay = "batterySleepDelay";
21+
inline constexpr auto kBatteryLockDelay = "batteryLockDelay";
22+
inline constexpr auto kBatteryLidClosedAction = "batteryLidClosedAction";
23+
inline constexpr auto kBatteryPressPowerButton = "batteryPressPowerButton";
24+
25+
inline constexpr auto kScreenBlackLock = "screenBlackLock";
26+
inline constexpr auto kSleepLock = "sleepLock";
27+
inline constexpr auto kPowerButtonPressedExec = "powerButtonPressedExec";
28+
29+
inline constexpr auto kLowPowerNotifyEnable = "lowPowerNotifyEnable";
30+
inline constexpr auto kLowPowerNotifyThreshold = "lowPowerNotifyThreshold";
31+
inline constexpr auto kUsePercentageForPolicy = "usePercentageForPolicy";
32+
inline constexpr auto kPercentageAction = "percentageAction";
33+
inline constexpr auto kTimeToEmptyLow = "timeToEmptyLow";
34+
inline constexpr auto kTimeToEmptyDanger = "timeToEmptyDanger";
35+
inline constexpr auto kTimeToEmptyCritical = "timeToEmptyCritical";
36+
inline constexpr auto kTimeToEmptyAction = "timeToEmptyAction";
37+
inline constexpr auto kLowPowerAction = "lowPowerAction";
38+
inline constexpr auto kPowerSavingModeBrightnessDropPercent = "powerSavingModeBrightnessDropPercent";
39+
inline constexpr auto kPowerSavingModeEnabled = "powerSavingModeEnabled";
40+
inline constexpr auto kPowerSavingModeAuto = "powerSavingModeAuto";
41+
inline constexpr auto kPowerSavingModeAutoWhenBatteryLow = "powerSavingModeAutoWhenBatteryLow";
42+
inline constexpr auto kPowerSavingModeAutoBatteryPercent = "powerSavingModeAutoBatteryPercent";
43+
inline constexpr auto kLastMode = "lastMode";
44+
inline constexpr auto kMode = "mode";
45+
inline constexpr auto kAdjustBrightnessEnabled = "adjustBrightnessEnabled";
46+
inline constexpr auto kHighPerformanceEnabled = "highPerformanceEnabled";
47+
inline constexpr auto kAmbientLightAdjustBrightness = "ambientLightAdjustBrightness";
48+
49+
inline constexpr auto kScheduledShutdownState = "scheduledShutdownState";
50+
inline constexpr auto kShutdownTime = "shutdownTime";
51+
inline constexpr auto kShutdownRepetition = "shutdownRepetition";
52+
inline constexpr auto kCustomShutdownWeekDays = "customShutdownWeekDays";
53+
inline constexpr auto kShutdownCountdown = "shutdownCountdown";
54+
inline constexpr auto kNextShutdownTime = "nextShutdownTime";
55+
}
56+
57+
namespace PowerDBus {
58+
inline constexpr auto kService = "org.deepin.dde.Power1";
59+
inline constexpr auto kPath = "/org/deepin/dde/Power1";
60+
inline constexpr auto kInterface = "org.deepin.dde.Power1";
61+
62+
inline constexpr auto kLogin1Service = "org.freedesktop.login1";
63+
inline constexpr auto kLogin1Path = "/org/freedesktop/login1";
64+
inline constexpr auto kLogin1Manager = "org.freedesktop.login1.Manager";
65+
inline constexpr auto kLogin1Session = "org.freedesktop.login1.Session";
66+
67+
inline constexpr auto kSessionManager = "org.deepin.dde.SessionManager1";
68+
inline constexpr auto kSessionPath = "/org/deepin/dde/SessionManager1";
69+
70+
inline constexpr auto kSessionWatcher = "org.deepin.dde.SessionWatcher1";
71+
inline constexpr auto kSessionWatcherPath = "/org/deepin/dde/SessionWatcher1";
72+
73+
inline constexpr auto kDaemonService = "org.deepin.dde.Daemon1";
74+
inline constexpr auto kDaemonPath = "/org/deepin/dde/Daemon1";
75+
76+
inline constexpr auto kLockFront = "org.deepin.dde.LockFront1";
77+
inline constexpr auto kLockFrontPath = "/org/deepin/dde/LockFront1";
78+
79+
inline constexpr auto kShutdownFront = "org.deepin.dde.ShutdownFront1";
80+
inline constexpr auto kShutdownPath = "/org/deepin/dde/ShutdownFront1";
81+
82+
inline constexpr auto kScreensaver = "com.deepin.ScreenSaver";
83+
inline constexpr auto kScreensaverPath = "/com/deepin/ScreenSaver";
84+
85+
inline constexpr auto kDisplay = "org.deepin.dde.Display1";
86+
inline constexpr auto kDisplayPath = "/org/deepin/dde/Display1";
87+
88+
inline constexpr auto kBlackScreen = "org.deepin.dde.BlackScreen1";
89+
inline constexpr auto kBlackScreenPath = "/org/deepin/dde/BlackScreen1";
90+
91+
inline constexpr auto kNotifications = "org.freedesktop.Notifications";
92+
inline constexpr auto kNotificationsPath = "/org/freedesktop/Notifications";
93+
94+
inline constexpr auto kFreedesktopDBus = "org.freedesktop.DBus";
95+
inline constexpr auto kFreedesktopPath = "/org/freedesktop/DBus";
96+
97+
inline constexpr auto kUPowerService = "org.freedesktop.UPower";
98+
inline constexpr auto kUPowerPath = "/org/freedesktop/UPower";
99+
100+
inline constexpr auto kCalendarService = "com.deepin.dataserver.Calendar";
101+
inline constexpr auto kCalendarPath = "/com/deepin/dataserver/Calendar/HuangLi";
102+
inline constexpr auto kCalendarIface = "com.deepin.dataserver.Calendar.HuangLi";
103+
}
104+
105+
namespace PowerFS {
106+
inline constexpr auto kCpuSysfsDir = "/sys/devices/system/cpu";
107+
inline constexpr auto kCpuGovernorFmt = "/sys/devices/system/cpu/%1/cpufreq/scaling_governor";
108+
inline constexpr auto kCpuBoostPath = "/sys/devices/system/cpu/cpufreq/boost";
109+
inline constexpr auto kLidStatePath = "/proc/acpi/button/lid/LID/state";
110+
inline constexpr auto kDpmsStateFile = "/tmp/dpms-state";
111+
inline constexpr auto kNoSuspendFile = "/etc/deepin/no_suspend";
112+
inline constexpr auto kLowPowerCmd = "/usr/lib/deepin-daemon/dde-lowpower";
113+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
#
3+
# SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
cmake_minimum_required(VERSION 3.16)
6+
7+
set(BIN_NAME "plugin-power-session")
8+
project(${BIN_NAME})
9+
10+
set(CMAKE_AUTOMOC ON)
11+
set(CMAKE_AUTORCC ON)
12+
13+
include(GNUInstallDirs)
14+
15+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus Gui WaylandClient LinguistTools)
16+
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core)
17+
find_package(PkgConfig REQUIRED)
18+
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
19+
pkg_check_modules(WLR_PROTOCOLS REQUIRED wlr-protocols)
20+
pkg_check_modules(TREELAND_PROTOCOLS REQUIRED treeland-protocols)
21+
pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)
22+
pkg_get_variable(WLR_PROTOCOLS_DATADIR wlr-protocols pkgdatadir)
23+
pkg_get_variable(TREELAND_PROTOCOLS_DATADIR treeland-protocols pkgdatadir)
24+
25+
set(_src_idle
26+
idle/idlewatcher_wl.cpp
27+
idle/idlewatcher_x11.cpp
28+
)
29+
set(_src_screen
30+
screen/screencontroller.cpp
31+
screen/screencontroller_wl.cpp
32+
screen/screencontroller_x11.cpp
33+
)
34+
set(_src_core
35+
plugin-power-session.cpp
36+
powermanager.cpp
37+
sessiondbusproxy.cpp
38+
powersaveplan.cpp
39+
lidswitchhandler.cpp
40+
sleepinhibitor.cpp
41+
lowpowermanager.cpp
42+
)
43+
set(_src_headers
44+
idle/idlewatcher.h
45+
idle/idlewatcher_wl.h
46+
screen/screencontroller.h
47+
screen/screencontroller_wl.h
48+
powersaveplan.h
49+
lidswitchhandler.h
50+
sleepinhibitor.h
51+
lowpowermanager.h
52+
powermanager.h
53+
sessiondbusproxy.h
54+
)
55+
56+
file(GLOB TS_FILES translations/*.ts)
57+
58+
add_library(${BIN_NAME} MODULE
59+
${_src_idle} ${_src_screen} ${_src_core} ${_src_headers}
60+
)
61+
62+
qt6_generate_wayland_protocol_client_sources(${BIN_NAME}
63+
FILES
64+
${WAYLAND_PROTOCOLS_DATADIR}/staging/ext-idle-notify/ext-idle-notify-v1.xml
65+
${WLR_PROTOCOLS_DATADIR}/unstable/wlr-output-power-management-unstable-v1.xml
66+
${TREELAND_PROTOCOLS_DATADIR}/treeland-output-manager-v1.xml
67+
)
68+
69+
qt_add_translations(${BIN_NAME}
70+
TS_FILES ${TS_FILES}
71+
QM_FILES_OUTPUT_VARIABLE QM_FILES
72+
LUPDATE_OPTIONS -no-ui-lines -locations none
73+
)
74+
75+
76+
target_include_directories(${BIN_NAME} PRIVATE
77+
${CMAKE_CURRENT_SOURCE_DIR}
78+
${CMAKE_CURRENT_BINARY_DIR}
79+
)
80+
81+
target_link_libraries(${BIN_NAME} PRIVATE
82+
Qt${QT_VERSION_MAJOR}::Core
83+
Qt${QT_VERSION_MAJOR}::DBus
84+
Qt${QT_VERSION_MAJOR}::Gui
85+
Qt${QT_VERSION_MAJOR}::WaylandClient
86+
Dtk${DTK_VERSION_MAJOR}::Core
87+
)
88+
89+
install(TARGETS ${BIN_NAME}
90+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager/
91+
)
92+
93+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/plugin-power-session.json
94+
DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/deepin-service-manager/user/
95+
)
96+
97+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/dbus/org.deepin.dde.Power1.service
98+
DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/services/
99+
)
100+
101+
install(FILES ${QM_FILES}
102+
DESTINATION ${CMAKE_INSTALL_DATADIR}/${BIN_NAME}/translations
103+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
#pragma once
6+
7+
#include <QObject>
8+
#include <cstdint>
9+
10+
/**
11+
* @brief Abstract interface for user idle detection.
12+
*
13+
* X11 implementation: uses org.freedesktop.ScreenSaver D-Bus signals.
14+
* Wayland implementation: uses ext-idle-notify-v1 protocol.
15+
*/
16+
class IdleWatcher : public QObject
17+
{
18+
Q_OBJECT
19+
20+
public:
21+
explicit IdleWatcher(QObject *parent = nullptr) : QObject(parent) {}
22+
~IdleWatcher() override = default;
23+
24+
/// Whether the underlying backend initialized successfully.
25+
virtual bool isValid() const = 0;
26+
27+
/// Set the idle timeout in seconds. Re-creates the notification object
28+
/// with the new timeout when the backend supports it.
29+
virtual void setTimeout(uint32_t timeoutSec) = 0;
30+
31+
/// Simulate user activity — resets the idle timer.
32+
virtual void simulateActivity() = 0;
33+
34+
/// Elapsed idle time in milliseconds (0 if not idle).
35+
virtual uint32_t idleTimeMs() const = 0;
36+
37+
/// Whether the user is currently idle.
38+
virtual bool isIdle() const = 0;
39+
40+
Q_SIGNALS:
41+
/// Emitted when the user becomes idle.
42+
void idled();
43+
44+
/// Emitted when the user resumes activity.
45+
void resumed();
46+
};

0 commit comments

Comments
 (0)