Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Build-Depends: debhelper (>= 11),
pkg-config,
cmake,
qt6-base-dev,
qt6-tools-dev-tools,
qt6-wayland-dev,
qt6-wayland-private-dev,
qt6-wayland-dev-tools,
libsystemd-dev,
libpcap-dev,
libnet-dev,
Expand All @@ -15,6 +19,9 @@ Build-Depends: debhelper (>= 11),
libx11-dev,
libxcb-randr0-dev,
libxcb1-dev,
treeland-protocols,
wlr-protocols,
wayland-protocols,
Standards-Version: 4.1.3
Homepage: https://github.com/linuxdeepin

Expand Down
3 changes: 2 additions & 1 deletion src/plugin-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
add_subdirectory("thememanager")
add_subdirectory("wallpapercache")
add_subdirectory("wallpaperslideshow")
add_subdirectory("xsettings")
add_subdirectory("xsettings")
add_subdirectory("power")
8 changes: 8 additions & 0 deletions src/plugin-qt/power/CMakeLists.txt
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)
113 changes: 113 additions & 0 deletions src/plugin-qt/power/powerconstants.h
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";
}
103 changes: 103 additions & 0 deletions src/plugin-qt/power/session/CMakeLists.txt
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
)
46 changes: 46 additions & 0 deletions src/plugin-qt/power/session/idle/idlewatcher.h
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>

Check warning on line 7 in src/plugin-qt/power/session/idle/idlewatcher.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstdint>

Check warning on line 8 in src/plugin-qt/power/session/idle/idlewatcher.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstdint> not found. Please note: Cppcheck does not need standard library headers to get proper results.

/**
* @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();
};
Loading
Loading