-
Notifications
You must be signed in to change notification settings - Fork 14
feat(power): add session power management plugin #70
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| add_subdirectory(session) | ||
| # TODO: system-level power is provided by dde-daemon's dde-system-daemon | ||
| # for both X11 and Wayland. Remove this when unified. | ||
| # add_subdirectory(system) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace PowerDConfig { | ||
| inline constexpr auto kAppId = "org.deepin.dde.daemon"; | ||
| inline constexpr auto kPowerName = "org.deepin.dde.daemon.power"; | ||
|
|
||
| inline constexpr auto kLinePowerScreensaverDelay = "linePowerScreensaverDelay"; | ||
| inline constexpr auto kLinePowerScreenBlackDelay = "linePowerScreenBlackDelay"; | ||
| inline constexpr auto kLinePowerSleepDelay = "linePowerSleepDelay"; | ||
| inline constexpr auto kLinePowerLockDelay = "linePowerLockDelay"; | ||
| inline constexpr auto kLinePowerLidClosedAction = "linePowerLidClosedAction"; | ||
| inline constexpr auto kLinePowerPressPowerButton = "linePowerPressPowerButton"; | ||
|
|
||
| inline constexpr auto kBatteryScreensaverDelay = "batteryScreensaverDelay"; | ||
| inline constexpr auto kBatteryScreenBlackDelay = "batteryScreenBlackDelay"; | ||
| inline constexpr auto kBatterySleepDelay = "batterySleepDelay"; | ||
| inline constexpr auto kBatteryLockDelay = "batteryLockDelay"; | ||
| inline constexpr auto kBatteryLidClosedAction = "batteryLidClosedAction"; | ||
| inline constexpr auto kBatteryPressPowerButton = "batteryPressPowerButton"; | ||
|
|
||
| inline constexpr auto kScreenBlackLock = "screenBlackLock"; | ||
| inline constexpr auto kSleepLock = "sleepLock"; | ||
| inline constexpr auto kPowerButtonPressedExec = "powerButtonPressedExec"; | ||
|
|
||
| inline constexpr auto kLowPowerNotifyEnable = "lowPowerNotifyEnable"; | ||
| inline constexpr auto kLowPowerNotifyThreshold = "lowPowerNotifyThreshold"; | ||
| inline constexpr auto kUsePercentageForPolicy = "usePercentageForPolicy"; | ||
| inline constexpr auto kPercentageAction = "percentageAction"; | ||
| inline constexpr auto kTimeToEmptyLow = "timeToEmptyLow"; | ||
| inline constexpr auto kTimeToEmptyDanger = "timeToEmptyDanger"; | ||
| inline constexpr auto kTimeToEmptyCritical = "timeToEmptyCritical"; | ||
| inline constexpr auto kTimeToEmptyAction = "timeToEmptyAction"; | ||
| inline constexpr auto kLowPowerAction = "lowPowerAction"; | ||
| inline constexpr auto kPowerSavingModeBrightnessDropPercent = "powerSavingModeBrightnessDropPercent"; | ||
| inline constexpr auto kPowerSavingModeEnabled = "powerSavingModeEnabled"; | ||
| inline constexpr auto kPowerSavingModeAuto = "powerSavingModeAuto"; | ||
| inline constexpr auto kPowerSavingModeAutoWhenBatteryLow = "powerSavingModeAutoWhenBatteryLow"; | ||
| inline constexpr auto kPowerSavingModeAutoBatteryPercent = "powerSavingModeAutoBatteryPercent"; | ||
| inline constexpr auto kLastMode = "lastMode"; | ||
| inline constexpr auto kMode = "mode"; | ||
| inline constexpr auto kAdjustBrightnessEnabled = "adjustBrightnessEnabled"; | ||
| inline constexpr auto kHighPerformanceEnabled = "highPerformanceEnabled"; | ||
| inline constexpr auto kAmbientLightAdjustBrightness = "ambientLightAdjustBrightness"; | ||
|
|
||
| inline constexpr auto kScheduledShutdownState = "scheduledShutdownState"; | ||
| inline constexpr auto kShutdownTime = "shutdownTime"; | ||
| inline constexpr auto kShutdownRepetition = "shutdownRepetition"; | ||
| inline constexpr auto kCustomShutdownWeekDays = "customShutdownWeekDays"; | ||
| inline constexpr auto kShutdownCountdown = "shutdownCountdown"; | ||
| inline constexpr auto kNextShutdownTime = "nextShutdownTime"; | ||
| } | ||
|
|
||
| namespace PowerDBus { | ||
| inline constexpr auto kService = "org.deepin.dde.Power1"; | ||
| inline constexpr auto kPath = "/org/deepin/dde/Power1"; | ||
| inline constexpr auto kInterface = "org.deepin.dde.Power1"; | ||
|
|
||
| inline constexpr auto kLogin1Service = "org.freedesktop.login1"; | ||
| inline constexpr auto kLogin1Path = "/org/freedesktop/login1"; | ||
| inline constexpr auto kLogin1Manager = "org.freedesktop.login1.Manager"; | ||
| inline constexpr auto kLogin1Session = "org.freedesktop.login1.Session"; | ||
|
|
||
| inline constexpr auto kSessionManager = "org.deepin.dde.SessionManager1"; | ||
| inline constexpr auto kSessionPath = "/org/deepin/dde/SessionManager1"; | ||
|
|
||
| inline constexpr auto kSessionWatcher = "org.deepin.dde.SessionWatcher1"; | ||
| inline constexpr auto kSessionWatcherPath = "/org/deepin/dde/SessionWatcher1"; | ||
|
|
||
| inline constexpr auto kDaemonService = "org.deepin.dde.Daemon1"; | ||
| inline constexpr auto kDaemonPath = "/org/deepin/dde/Daemon1"; | ||
|
|
||
| inline constexpr auto kLockFront = "org.deepin.dde.LockFront1"; | ||
| inline constexpr auto kLockFrontPath = "/org/deepin/dde/LockFront1"; | ||
|
|
||
| inline constexpr auto kShutdownFront = "org.deepin.dde.ShutdownFront1"; | ||
| inline constexpr auto kShutdownPath = "/org/deepin/dde/ShutdownFront1"; | ||
|
|
||
| inline constexpr auto kScreensaver = "com.deepin.ScreenSaver"; | ||
| inline constexpr auto kScreensaverPath = "/com/deepin/ScreenSaver"; | ||
|
|
||
| inline constexpr auto kDisplay = "org.deepin.dde.Display1"; | ||
| inline constexpr auto kDisplayPath = "/org/deepin/dde/Display1"; | ||
|
|
||
| inline constexpr auto kBlackScreen = "org.deepin.dde.BlackScreen1"; | ||
| inline constexpr auto kBlackScreenPath = "/org/deepin/dde/BlackScreen1"; | ||
|
|
||
| inline constexpr auto kNotifications = "org.freedesktop.Notifications"; | ||
| inline constexpr auto kNotificationsPath = "/org/freedesktop/Notifications"; | ||
|
|
||
| inline constexpr auto kFreedesktopDBus = "org.freedesktop.DBus"; | ||
| inline constexpr auto kFreedesktopPath = "/org/freedesktop/DBus"; | ||
|
|
||
| inline constexpr auto kUPowerService = "org.freedesktop.UPower"; | ||
| inline constexpr auto kUPowerPath = "/org/freedesktop/UPower"; | ||
|
|
||
| inline constexpr auto kCalendarService = "com.deepin.dataserver.Calendar"; | ||
| inline constexpr auto kCalendarPath = "/com/deepin/dataserver/Calendar/HuangLi"; | ||
| inline constexpr auto kCalendarIface = "com.deepin.dataserver.Calendar.HuangLi"; | ||
| } | ||
|
|
||
| namespace PowerFS { | ||
| inline constexpr auto kCpuSysfsDir = "/sys/devices/system/cpu"; | ||
| inline constexpr auto kCpuGovernorFmt = "/sys/devices/system/cpu/%1/cpufreq/scaling_governor"; | ||
| inline constexpr auto kCpuBoostPath = "/sys/devices/system/cpu/cpufreq/boost"; | ||
| inline constexpr auto kLidStatePath = "/proc/acpi/button/lid/LID/state"; | ||
| inline constexpr auto kDpmsStateFile = "/tmp/dpms-state"; | ||
| inline constexpr auto kNoSuspendFile = "/etc/deepin/no_suspend"; | ||
| inline constexpr auto kLowPowerCmd = "/usr/lib/deepin-daemon/dde-lowpower"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| cmake_minimum_required(VERSION 3.16) | ||
|
|
||
| set(BIN_NAME "plugin-power-session") | ||
| project(${BIN_NAME}) | ||
|
|
||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
| find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus Gui WaylandClient LinguistTools) | ||
| find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core) | ||
| find_package(PkgConfig REQUIRED) | ||
| pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols) | ||
| pkg_check_modules(WLR_PROTOCOLS REQUIRED wlr-protocols) | ||
| pkg_check_modules(TREELAND_PROTOCOLS REQUIRED treeland-protocols) | ||
| pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir) | ||
| pkg_get_variable(WLR_PROTOCOLS_DATADIR wlr-protocols pkgdatadir) | ||
| pkg_get_variable(TREELAND_PROTOCOLS_DATADIR treeland-protocols pkgdatadir) | ||
|
|
||
| set(_src_idle | ||
| idle/idlewatcher_wl.cpp | ||
| idle/idlewatcher_x11.cpp | ||
| ) | ||
| set(_src_screen | ||
| screen/screencontroller.cpp | ||
| screen/screencontroller_wl.cpp | ||
| screen/screencontroller_x11.cpp | ||
| ) | ||
| set(_src_core | ||
| plugin-power-session.cpp | ||
| powermanager.cpp | ||
| sessiondbusproxy.cpp | ||
| powersaveplan.cpp | ||
| lidswitchhandler.cpp | ||
| sleepinhibitor.cpp | ||
| lowpowermanager.cpp | ||
| ) | ||
| set(_src_headers | ||
| idle/idlewatcher.h | ||
| idle/idlewatcher_wl.h | ||
| screen/screencontroller.h | ||
| screen/screencontroller_wl.h | ||
| powersaveplan.h | ||
| lidswitchhandler.h | ||
| sleepinhibitor.h | ||
| lowpowermanager.h | ||
| powermanager.h | ||
| sessiondbusproxy.h | ||
| ) | ||
|
|
||
| file(GLOB TS_FILES translations/*.ts) | ||
|
|
||
| add_library(${BIN_NAME} MODULE | ||
| ${_src_idle} ${_src_screen} ${_src_core} ${_src_headers} | ||
| ) | ||
|
|
||
| qt6_generate_wayland_protocol_client_sources(${BIN_NAME} | ||
| FILES | ||
| ${WAYLAND_PROTOCOLS_DATADIR}/staging/ext-idle-notify/ext-idle-notify-v1.xml | ||
| ${WLR_PROTOCOLS_DATADIR}/unstable/wlr-output-power-management-unstable-v1.xml | ||
| ${TREELAND_PROTOCOLS_DATADIR}/treeland-output-manager-v1.xml | ||
| ) | ||
|
|
||
| qt_add_translations(${BIN_NAME} | ||
| TS_FILES ${TS_FILES} | ||
| QM_FILES_OUTPUT_VARIABLE QM_FILES | ||
| LUPDATE_OPTIONS -no-ui-lines -locations none | ||
| ) | ||
|
|
||
|
|
||
| target_include_directories(${BIN_NAME} PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| ) | ||
|
|
||
| target_link_libraries(${BIN_NAME} PRIVATE | ||
| Qt${QT_VERSION_MAJOR}::Core | ||
| Qt${QT_VERSION_MAJOR}::DBus | ||
| Qt${QT_VERSION_MAJOR}::Gui | ||
| Qt${QT_VERSION_MAJOR}::WaylandClient | ||
| Dtk${DTK_VERSION_MAJOR}::Core | ||
| ) | ||
|
|
||
| install(TARGETS ${BIN_NAME} | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager/ | ||
| ) | ||
|
|
||
| install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/plugin-power-session.json | ||
| DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/deepin-service-manager/user/ | ||
| ) | ||
|
|
||
| install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/dbus/org.deepin.dde.Power1.service | ||
| DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/services/ | ||
| ) | ||
|
|
||
| install(FILES ${QM_FILES} | ||
| DESTINATION ${CMAKE_INSTALL_DATADIR}/${BIN_NAME}/translations | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QObject> | ||
| #include <cstdint> | ||
|
|
||
| /** | ||
| * @brief Abstract interface for user idle detection. | ||
| * | ||
| * X11 implementation: uses org.freedesktop.ScreenSaver D-Bus signals. | ||
| * Wayland implementation: uses ext-idle-notify-v1 protocol. | ||
| */ | ||
| class IdleWatcher : public QObject | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit IdleWatcher(QObject *parent = nullptr) : QObject(parent) {} | ||
| ~IdleWatcher() override = default; | ||
|
|
||
| /// Whether the underlying backend initialized successfully. | ||
| virtual bool isValid() const = 0; | ||
|
|
||
| /// Set the idle timeout in seconds. Re-creates the notification object | ||
| /// with the new timeout when the backend supports it. | ||
| virtual void setTimeout(uint32_t timeoutSec) = 0; | ||
|
|
||
| /// Simulate user activity — resets the idle timer. | ||
| virtual void simulateActivity() = 0; | ||
|
|
||
| /// Elapsed idle time in milliseconds (0 if not idle). | ||
| virtual uint32_t idleTimeMs() const = 0; | ||
|
|
||
| /// Whether the user is currently idle. | ||
| virtual bool isIdle() const = 0; | ||
|
|
||
| Q_SIGNALS: | ||
| /// Emitted when the user becomes idle. | ||
| void idled(); | ||
|
|
||
| /// Emitted when the user resumes activity. | ||
| void resumed(); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.