diff --git a/CMakeLists.txt b/CMakeLists.txt index a141da7d..4bd2fbd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,74 +1,72 @@ project(PowerDevil) set(PROJECT_VERSION "5.9.90") set(PROJECT_VERSION_MAJOR 5) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) set(QT_MIN_VERSION "5.4.0") find_package(ECM 1.2.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(FeatureSummary) include(WriteBasicConfigVersionFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) # require at least gcc 4.8 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.8") message(SEND_ERROR "Version ${CMAKE_CXX_COMPILER_VERSION} of the ${CMAKE_CXX_COMPILER_ID} C++ compiler is not supported. Please use version 4.8 or later.") endif() endif() find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets DBus X11Extras) find_package(KF5 REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Screen Wayland DocTools Crash Notifications) find_package(LibKWorkspace CONFIG REQUIRED) find_package(KF5BluezQt) set_package_properties(KF5BluezQt PROPERTIES DESCRIPTION "Qt wrapper for BlueZ 5 DBus API" TYPE OPTIONAL PURPOSE "Support for wireless energy saving actions" ) find_package(KF5NetworkManagerQt) set_package_properties(KF5NetworkManagerQt PROPERTIES DESCRIPTION "Qt wrapper for NetworkManager API" TYPE OPTIONAL PURPOSE "Support for wireless energy saving actions" ) set(HAVE_WIRELESS_SUPPORT FALSE) if(KF5NetworkManagerQt_FOUND AND KF5BluezQt_FOUND) set(HAVE_WIRELESS_SUPPORT TRUE) endif() add_feature_info( "Wireless power saving" HAVE_WIRELESS_SUPPORT "Support turning off signal-transmitting devices to save energy" ) find_package(UDev REQUIRED) find_package(XCB REQUIRED COMPONENTS XCB RANDR DPMS) include_directories ( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/daemon ) -configure_file(config-workspace.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-workspace.h) - add_definitions(-DQT_NO_KEYWORDS) add_definitions(-DQT_NO_KEYWORDS) add_subdirectory(daemon) add_subdirectory(kcmodule) add_subdirectory(doc) install( FILES powerdevil.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR} ) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) endif() diff --git a/config-workspace.h.cmake b/config-workspace.h.cmake deleted file mode 100644 index 66c1d635..00000000 --- a/config-workspace.h.cmake +++ /dev/null @@ -1,159 +0,0 @@ -/* config-workspace.h. Generated by cmake from config-workspace.h.cmake */ - -#cmakedefine HAVE_QIMAGEBLITZ - -/* Define if you have DPMS support */ -#cmakedefine HAVE_DPMS 1 - -/* Define if you have the DPMSCapable prototype in */ -#cmakedefine HAVE_DPMSCAPABLE_PROTO 1 - -/* Define if you have the DPMSInfo prototype in */ -#cmakedefine HAVE_DPMSINFO_PROTO 1 - -/* Defines if your system has the libfontconfig library */ -#cmakedefine HAVE_FONTCONFIG 1 - -/* Defines if your system has the freetype library */ -#cmakedefine HAVE_FREETYPE 1 - -/* Define if you have gethostname */ -#cmakedefine HAVE_GETHOSTNAME 1 - -/* Define if you have the gethostname prototype */ -#cmakedefine HAVE_GETHOSTNAME_PROTO 1 - -/* Define to 1 if you have the `getpeereid' function. */ -#cmakedefine HAVE_GETPEEREID 1 - -/* Defines if you have Solaris' libkstat */ -/* #undef HAVE_KSTAT */ - -/* Define if you have long long as datatype */ -#cmakedefine HAVE_LONG_LONG 1 - -/* Define to 1 if you have the `nice' function. */ -#cmakedefine HAVE_NICE 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SASL_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SASL_SASL_H 1 - -/* Define to 1 if you have the `setpriority' function. */ -#cmakedefine HAVE_SETPRIORITY 1 - -/* Define to 1 if you have the `sigaction' function. */ -#cmakedefine HAVE_SIGACTION 1 - -/* Define to 1 if you have the `sigset' function. */ -#cmakedefine HAVE_SIGSET 1 - -/* Define to 1 if you have statvfs */ -#cmakedefine HAVE_STATVFS 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STRING_H 1 - -/* Define if you have the struct ucred */ -#cmakedefine HAVE_STRUCT_UCRED 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_LOADAVG_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_MOUNT_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_PARAM_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STATFS_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STATVFS_H 1 - -/* Define to 1 if you have statfs(). */ -#cmakedefine HAVE_STATFS 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_VFS_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_WAIT_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_UNISTD_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MALLOC_H 1 - -/* Define if you have unsetenv */ -#cmakedefine HAVE_UNSETENV 1 - -/* Define if you have the unsetenv prototype */ -#cmakedefine HAVE_UNSETENV_PROTO 1 - -/* Define if you have usleep */ -#cmakedefine HAVE_USLEEP 1 - -/* Define if you have the usleep prototype */ -#cmakedefine HAVE_USLEEP_PROTO 1 - -/* Define to 1 if you have the `vsnprintf' function. */ -#cmakedefine HAVE_VSNPRINTF 1 - -/* Define to 1 if you have the Wayland libraries. */ -#cmakedefine WAYLAND_FOUND 1 - -/* KDE's default home directory */ -#cmakedefine KDE_DEFAULT_HOME "${KDE_DEFAULT_HOME}" - -/* KDE's binaries directory */ -#define KDE_BINDIR "${BIN_INSTALL_DIR}" - -/* KDE's configuration directory */ -#define KDE_CONFDIR "${CONFIG_INSTALL_DIR}" - -/* KDE's static data directory */ -#define KDE_DATADIR "${DATA_INSTALL_DIR}" - -/* Define where your java executable is */ -#undef PATH_JAVA - -/* Define to 1 if you can safely include both and . */ -#cmakedefine TIME_WITH_SYS_TIME 1 - -/* X binaries directory */ -#cmakedefine XBINDIR "${XBINDIR}" - -/* X libraries directory */ -#cmakedefine XLIBDIR "${XLIBDIR}" - -/* Number of bits in a file offset, on hosts where this is settable. */ -#define _FILE_OFFSET_BITS 64 - -/* - * On HP-UX, the declaration of vsnprintf() is needed every time ! - */ - -/* type to use in place of socklen_t if not defined */ -#define kde_socklen_t socklen_t - -#define WORKSPACE_VERSION_STRING "${KDE4WORKSPACE_VERSION}" \ No newline at end of file diff --git a/daemon/actions/dpms/powerdevildpmsaction.cpp b/daemon/actions/dpms/powerdevildpmsaction.cpp index 3993190a..d6bc71f6 100644 --- a/daemon/actions/dpms/powerdevildpmsaction.cpp +++ b/daemon/actions/dpms/powerdevildpmsaction.cpp @@ -1,190 +1,188 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * Copyright (C) 2015 by Kai Uwe Broulik * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "powerdevildpmsaction.h" #include "abstractdpmshelper.h" #include "xcbdpmshelper.h" #include "waylanddpmshelper.h" #include #include #include -#include - #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilDPMSActionFactory, registerPlugin(); ) PowerDevilDPMSAction::PowerDevilDPMSAction(QObject* parent, const QVariantList &args) : Action(parent) , m_helper() { setRequiredPolicies(PowerDevil::PolicyAgent::ChangeScreenSettings); if (QX11Info::isPlatformX11()) { m_helper.reset(new XcbDpmsHelper); } else if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) { m_helper.reset(new WaylandDpmsHelper); } // Is the action being loaded outside the core? if (args.size() > 0) { if (args.first().toBool()) { qCDebug(POWERDEVIL) << "Action loaded from outside the core, skipping early init"; return; } } // Pretend we're unloading profiles here, as if the action is not enabled, DPMS should be switched off. onProfileUnload(); // Listen to the policy agent connect(PowerDevil::PolicyAgent::instance(), &PowerDevil::PolicyAgent::unavailablePoliciesChanged, this, &PowerDevilDPMSAction::onUnavailablePoliciesChanged); // inhibitions persist over kded module unload/load m_inhibitScreen = PowerDevil::PolicyAgent::instance()->unavailablePolicies() & PowerDevil::PolicyAgent::ChangeScreenSettings; } PowerDevilDPMSAction::~PowerDevilDPMSAction() = default; bool PowerDevilDPMSAction::isSupported() { return !m_helper.isNull() && m_helper->isSupported(); } void PowerDevilDPMSAction::onProfileUnload() { if (m_helper.isNull()) { return; } m_helper->profileUnloaded(); } void PowerDevilDPMSAction::onWakeupFromIdle() { if (!m_helper.isNull()) { m_helper->stopFade(); } if (m_oldKeyboardBrightness > 0) { setKeyboardBrightnessHelper(m_oldKeyboardBrightness); m_oldKeyboardBrightness = 0; } } void PowerDevilDPMSAction::onIdleTimeout(int msec) { // Do not inhibit anything even if idleTimeout reaches because we are inhibit if (m_inhibitScreen) { return; } if (msec == m_idleTime * 1000 - 5000) { // fade out screen if (!m_helper.isNull()) { m_helper->startFade(); } } else if (msec == m_idleTime * 1000) { const int brightness = backend()->brightness(PowerDevil::BackendInterface::Keyboard); if (brightness > 0) { m_oldKeyboardBrightness = brightness; setKeyboardBrightnessHelper(0); } if (!m_helper.isNull()) { m_helper->dpmsTimeout(); } } } void PowerDevilDPMSAction::setKeyboardBrightnessHelper(int brightness) { trigger({ {"KeyboardBrightness", QVariant::fromValue(brightness)} }); } void PowerDevilDPMSAction::onProfileLoad() { if (m_helper.isNull()) { return; } m_helper->profileLoaded(m_idleTime); } void PowerDevilDPMSAction::triggerImpl(const QVariantMap& args) { QString KEYBOARD_BRIGHTNESS = QStringLiteral("KeyboardBrightness"); if (args.contains(KEYBOARD_BRIGHTNESS)) { backend()->setBrightness(args.value(KEYBOARD_BRIGHTNESS).toInt(), PowerDevil::BackendInterface::Keyboard); return; } if (m_helper.isNull()) { return; } m_helper->trigger(args.value(QStringLiteral("Type")).toString()); } bool PowerDevilDPMSAction::loadAction(const KConfigGroup& config) { m_idleTime = config.readEntry("idleTime", -1); if (m_idleTime > 0) { registerIdleTimeout(m_idleTime * 1000); registerIdleTimeout(m_idleTime * 1000 - 5000); // start screen fade a bit earlier to alert user } return true; } bool PowerDevilDPMSAction::onUnloadAction() { m_idleTime = 0; return Action::onUnloadAction(); } void PowerDevilDPMSAction::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies policies) { // only take action if screen inhibit changed PowerDevil::PolicyAgent::RequiredPolicies oldPolicy = m_inhibitScreen; m_inhibitScreen = policies & PowerDevil::PolicyAgent::ChangeScreenSettings; if (oldPolicy == m_inhibitScreen) { return; } if (m_inhibitScreen) { // Inhibition triggered: disable DPMS if (!m_helper.isNull()) { m_helper->inhibited(); } } else { // Inhibition removed: let's start again onProfileLoad(); qCDebug(POWERDEVIL) << "Restoring DPMS features after inhibition release"; } } #include "powerdevildpmsaction.moc" diff --git a/daemon/actions/dpms/xcbdpmshelper.cpp b/daemon/actions/dpms/xcbdpmshelper.cpp index 85163334..7a06f7b2 100644 --- a/daemon/actions/dpms/xcbdpmshelper.cpp +++ b/daemon/actions/dpms/xcbdpmshelper.cpp @@ -1,134 +1,133 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * Copyright (C) 2015 by Kai Uwe Broulik * * Copyright (C) 2015 by Martin Gräßlin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "xcbdpmshelper.h" // powerdevil #include #include -#include #include // Qt #include // xcb #include template using ScopedCPointer = QScopedPointer; XcbDpmsHelper::XcbDpmsHelper() : AbstractDpmsHelper() , m_fadeEffect(new PowerDevil::KWinKScreenHelperEffect()) { ScopedCPointer capableReply(xcb_dpms_capable_reply(QX11Info::connection(), xcb_dpms_capable(QX11Info::connection()), nullptr)); if (capableReply && capableReply->capable) { setSupported(true); } } XcbDpmsHelper::~XcbDpmsHelper() = default; void XcbDpmsHelper::profileLoaded(int idleTime) { using namespace PowerDevil; if (!(PolicyAgent::instance()->unavailablePolicies() & PolicyAgent::ChangeScreenSettings)) { xcb_dpms_enable(QX11Info::connection()); } else { qCDebug(POWERDEVIL) << "Not performing DPMS action due to inhibition"; return; } // An unloaded action will have idleTime = 0: // DPMS enabled with zeroed timeouts is effectively disabled. // So onProfileLoad is always safe xcb_dpms_set_timeouts(QX11Info::connection(), idleTime, idleTime * 1.5, idleTime * 2); } void XcbDpmsHelper::profileUnloaded() { using namespace PowerDevil; if (!(PolicyAgent::instance()->unavailablePolicies() & PolicyAgent::ChangeScreenSettings)) { xcb_dpms_disable(QX11Info::connection()); } else { qCDebug(POWERDEVIL) << "Not performing DPMS action due to inhibition"; } xcb_dpms_set_timeouts(QX11Info::connection(), 0, 0, 0); } void XcbDpmsHelper::startFade() { m_fadeEffect->start(); } void XcbDpmsHelper::stopFade() { m_fadeEffect->stop(); } void XcbDpmsHelper::trigger(const QString &type) { ScopedCPointer infoReply(xcb_dpms_info_reply(QX11Info::connection(), xcb_dpms_info(QX11Info::connection()), nullptr)); if (!infoReply) { qCWarning(POWERDEVIL) << "Failed to query DPMS state, cannot trigger"; return; } int level = 0; if (type == QLatin1String("ToggleOnOff")) { if (infoReply->power_level < XCB_DPMS_DPMS_MODE_OFF) { level = XCB_DPMS_DPMS_MODE_OFF; } else { level = XCB_DPMS_DPMS_MODE_ON; } } else if (type == QLatin1String("TurnOff")) { level = XCB_DPMS_DPMS_MODE_OFF; } else if (type == QLatin1String("Standby")) { level = XCB_DPMS_DPMS_MODE_STANDBY; } else if (type == QLatin1String("Suspend")) { level = XCB_DPMS_DPMS_MODE_SUSPEND; } else { // this leaves DPMS enabled but if it's meant to be disabled // then the timeouts will be zero and so effectively disabled return; } if (!infoReply->state) { xcb_dpms_enable(QX11Info::connection()); } xcb_dpms_force_level(QX11Info::connection(), level); } void XcbDpmsHelper::inhibited() { qCDebug(POWERDEVIL) << "Disabling DPMS due to inhibition"; xcb_dpms_set_timeouts(QX11Info::connection(), 0, 0, 0); xcb_dpms_disable(QX11Info::connection()); // wakes the screen - do we want this? }