diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2016-03-13 16:50:36 +0100 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2016-03-13 16:51:41 +0100 |
commit | bcf8fa06f0c48612f14beb216521eea9c4957501 (patch) | |
tree | e89ee7463305e1e7a2367bb4e105da0f5a773e26 /src/inactivity.cpp | |
parent | 504511d4a5758ad54ee4650aa5a6ddc92e26bcb8 (diff) | |
download | tdepowersave-bcf8fa06f0c48612f14beb216521eea9c4957501.tar.gz tdepowersave-bcf8fa06f0c48612f14beb216521eea9c4957501.zip |
Fixed up timer for autosuspend and autodimm when a screensaver is also in use. This resolves bug 2603.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit d67bc99f08c6ba9113a769c45538ab3711cc1cfa)
Diffstat (limited to 'src/inactivity.cpp')
-rw-r--r-- | src/inactivity.cpp | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/src/inactivity.cpp b/src/inactivity.cpp index 8d7205e..977161e 100644 --- a/src/inactivity.cpp +++ b/src/inactivity.cpp @@ -18,7 +18,7 @@ ***************************************************************************/ /*! \file inactivity.cpp - * \brief In this file can be found the inactivity related code. + * \brief In this file can be found the inactivity related code. * \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de> * \date 2006-2007 */ @@ -37,7 +37,8 @@ extern "C" { #include <tdelocale.h> /*! The default constructor of the class autosuspend */ -inactivity::inactivity() { +inactivity::inactivity(screen *disp) : display(disp), + prev_screensaver_enabled(false), prev_idle_time(0), correction_value(0) { kdDebugFuncIn(trace); proc = NULL; @@ -71,11 +72,11 @@ inactivity::~inactivity() { /*! * This function start the monitoring of inactivity of user on the X-Server. - * Here wee set the time for the signal \ref inactivityTimeExpired() and start + * Here we set the time for the signal \ref inactivityTimeExpired() and start * the needed TQTimer. - * \param timeToExpire Integer value representing the time of inactivity which need + * \param timeToExpire Integer value representing the time of inactivity which need * to elapse befor send signal. The time is in seconds. - * \param blacked TQStringList with blacklisted programs which if detected with + * \param blacked TQStringList with blacklisted programs which if detected with * pidof() as running prevent the autosuspend. */ void inactivity::start( int timeToExpire, TQStringList blacked ) { @@ -86,6 +87,9 @@ void inactivity::start( int timeToExpire, TQStringList blacked ) { if(timeToExpire > 0 && has_XSC_Extension){ stop(); timeToInactivity = (unsigned long) (timeToExpire * 1000); + prev_screensaver_enabled = false; + prev_idle_time = 0; + correction_value = 0; checkInactivity->start(CHECK_for_INACTIVITY, true); } @@ -198,7 +202,7 @@ unsigned long inactivity::getXInactivity(){ if (!mitInfo) mitInfo = XScreenSaverAllocInfo (); XScreenSaverQueryInfo (tqt_xdisplay(), DefaultRootWindow (tqt_xdisplay()), mitInfo); kdDebugFuncOut(trace); - return workaroundCreepyXServer(mitInfo->idle); + return workaroundCreepyXServer(mitInfo); } else { kdDebugFuncOut(trace); @@ -219,12 +223,36 @@ unsigned long inactivity::getXInactivity(){ * current timeout for this state and add this value to * the current idle time and return. * - * \param _idleTime a unsigned long value with the current ideletime fromm - * XScreenSaverInfo->idle + * \param _mitInfo a pointer to a structure containing the current XScreenSaver state * \return a unsigned long with the corrected idletime */ -unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){ +unsigned long inactivity::workaroundCreepyXServer(XScreenSaverInfo *_mitInfo){ kdDebugFuncOut(trace); + unsigned long _idleTime = _mitInfo->idle; + + // Detect whether the screensaver has become active since the last time, + // because the idle time returned by XScreenSaverQueryInfo() is resetted + // to 0 when the screensaver kicks in. Correct the idle time value if the + // screensaver is active + bool screensaver_enabled = false; + if (display->checkScreenSaverActive()) + { + screensaver_enabled = true; + } + if (!prev_screensaver_enabled && screensaver_enabled) + { + correction_value = prev_idle_time + CHECK_for_INACTIVITY - _idleTime; + } + prev_idle_time = _idleTime; + if (screensaver_enabled) + { + _idleTime += correction_value; + } + else + { + correction_value = 0; + } + prev_screensaver_enabled = screensaver_enabled; int dummy; CARD16 standby, suspend, off; @@ -235,6 +263,8 @@ unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){ kdDebug() << "Current idleTime: " << _idleTime << endl; + // Idle time is reset when the screensaver kicks in. Need to correct with the right offset + if (DPMSQueryExtension(dpy, &dummy, &dummy)) { if (DPMSCapable(dpy)) { DPMSGetTimeouts(dpy, &standby, &suspend, &off); @@ -245,7 +275,7 @@ unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){ case DPMSModeStandby: kdDebug() << "DPMS enabled. Monitor in Standby. Standby: " << standby << " sec" << endl; - // this check is a littlebit paranoid, but be sure + // this check is a little bit paranoid, but be sure if (_idleTime < (unsigned) (standby * 1000)) _idleTime += (standby * 1000); break; @@ -266,7 +296,7 @@ unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){ break; } } - } + } } kdDebug() << "Corrected idleTime: " << _idleTime << endl; @@ -323,7 +353,7 @@ void inactivity::getPIDs(TDEProcess */*proc*/, char *buffer, int /*length*/) { if(pids.isEmpty() || pids == "\n" ) { kdDebug() << "NO! BLACKLISTED IS RUNNING" << endl; blacklisted_running = false; - } + } else { if (pids.contains(TQRegExp("[0-9]"))) { kdDebug() << "BLACKLISTED IS RUNNING" << endl; @@ -359,7 +389,7 @@ void inactivity::getPIDsExited(TDEProcess *proc){ kdDebugFuncOut(trace); return; } - } + } // if something crashed/failed pidof_call_failed = true; kdDebugFuncOut(trace); |