summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2016-03-13 16:50:36 +0100
committerMichele Calgaro <michele.calgaro@yahoo.it>2016-03-13 16:50:36 +0100
commitd67bc99f08c6ba9113a769c45538ab3711cc1cfa (patch)
treea288b1a17230f7fa4a1e759d2455c2a43a4c984d
parent2f0cf5202c83fe9d034dc3254e8db127f5bdffe3 (diff)
downloadtdepowersave-d67bc99f08c6ba9113a769c45538ab3711cc1cfa.tar.gz
tdepowersave-d67bc99f08c6ba9113a769c45538ab3711cc1cfa.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>
-rw-r--r--src/autodimm.cpp6
-rw-r--r--src/autodimm.h2
-rw-r--r--src/autosuspend.cpp4
-rw-r--r--src/autosuspend.h2
-rw-r--r--src/inactivity.cpp56
-rw-r--r--src/inactivity.h23
-rw-r--r--src/screen.cpp42
-rw-r--r--src/screen.h2
-rw-r--r--src/tdepowersave.cpp8
9 files changed, 109 insertions, 36 deletions
diff --git a/src/autodimm.cpp b/src/autodimm.cpp
index 4e2967f..e797e61 100644
--- a/src/autodimm.cpp
+++ b/src/autodimm.cpp
@@ -18,7 +18,7 @@
***************************************************************************/
/*! \file autodimm.cpp
- * \brief In this file can be found the autodimm class related code.
+ * \brief In this file can be found the autodimm class related code.
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
* \version 0.0.1
* \date 2007
@@ -27,8 +27,8 @@
#include "autodimm.h"
/*! The default constructor of the class autodimm */
-autodimm::autodimm() : inactivity() {
- kdDebugFuncIn(trace);
+autodimm::autodimm(screen *disp) : inactivity(disp) {
+ kdDebugFuncIn(trace);
lastIdleTime = 0;
diff --git a/src/autodimm.h b/src/autodimm.h
index 1ac7ec5..81b1cf9 100644
--- a/src/autodimm.h
+++ b/src/autodimm.h
@@ -42,7 +42,7 @@ class autodimm : public inactivity
public:
//! default constructor
- autodimm();
+ autodimm(screen *disp);
//! default destructor
~autodimm();
diff --git a/src/autosuspend.cpp b/src/autosuspend.cpp
index a46a93c..01372ba 100644
--- a/src/autosuspend.cpp
+++ b/src/autosuspend.cpp
@@ -18,7 +18,7 @@
***************************************************************************/
/*! \file autosuspend.cpp
- * \brief In this file can be found the autosuspend related code.
+ * \brief In this file can be found the autosuspend related code.
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
* \date 2005
*/
@@ -26,7 +26,7 @@
#include "autosuspend.h"
/*! The default constructor of the class autosuspend */
-autosuspend::autosuspend() : inactivity () {
+autosuspend::autosuspend(screen *disp) : inactivity (disp) {
kdDebugFuncIn(trace);
}
diff --git a/src/autosuspend.h b/src/autosuspend.h
index 1a881c5..4fe5832 100644
--- a/src/autosuspend.h
+++ b/src/autosuspend.h
@@ -41,7 +41,7 @@ class autosuspend : public inactivity
public:
//! default constructor
- autosuspend();
+ autosuspend(screen *disp);
//! default destructor
~autosuspend();
};
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);
diff --git a/src/inactivity.h b/src/inactivity.h
index e2d88a8..7fafab9 100644
--- a/src/inactivity.h
+++ b/src/inactivity.h
@@ -42,8 +42,14 @@
#include <X11/Xatom.h>
#include <X11/Xutil.h>
+/* needed for lXext C library linkage */
+extern "C" {
+ #include <X11/extensions/scrnsaver.h>
+}
+
// from project
#include "tdepowersave_debug.h"
+#include "screen.h"
/*!
* \file inactivity.h
@@ -63,7 +69,7 @@ class inactivity : public TQWidget
public:
//! default constructor
- inactivity();
+ inactivity(screen *disp);
//! default destructor
~inactivity();
@@ -135,16 +141,21 @@ private:
* The time intervall to check for the current status and time of
* userinactivity. The timeslice is currently 30 sec.
*/
- static const int CHECK_for_INACTIVITY = 30000;
-
+ static const int CHECK_for_INACTIVITY = 10000;
+
//! TQTimer for check inactivity
/*!
* This timer is used to check the currently status and time of
- * userinactivity on the X-Server. The timerinterval is defined trough
+ * user inactivity on the X-Server. The timer interval is defined through
* \ref CHECK_for_INACTIVITY .
*/
TQTimer *checkInactivity;
-
+
+ screen *display; // No ownership here!!
+ bool prev_screensaver_enabled;
+ unsigned long prev_idle_time;
+ unsigned long correction_value;
+
// -------- FUNCTIONS ------------
//! to check the user-inactivity on the XServer
@@ -154,7 +165,7 @@ private:
//! to monitor the values
void check( bool recheck );
//! to workaround a strange behavior of the XScreenSaver extension
- unsigned long workaroundCreepyXServer( unsigned long );
+ unsigned long workaroundCreepyXServer(XScreenSaverInfo *_mitInfo);
private slots:
diff --git a/src/screen.cpp b/src/screen.cpp
index 4adb0f4..ef68a26 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -17,12 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
/*! \file screen.cpp
- * All here displayed file members of screen.cpp are related to operations with the
- * XSreensaver/XServer. This functions are basic/low level operations. They are
+ * All here displayed file members of screen.cpp are related to operations with the
+ * XSreensaver/XServer. This functions are basic/low level operations. They are
* inspired, partly copied and modified from <a href="http://www.mplayerhq.hu/">MPlayer</a>
* code (1.05pre). Thanks for the inspiration. \n \n
- * All 'higher level' class members of the class screen can be found here: \ref screen
- * \brief In this file can be found all screensaver related code.
+ * All 'higher level' class members of the class screen can be found here: \ref screen
+ * \brief In this file can be found all screensaver related code.
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
* \date 2004 - 2006
*/
@@ -81,7 +81,7 @@ bool screen::setScreenSaver(bool enable){
kdDebugFuncIn(trace);
if(SCREENSAVER_STATUS == -1) SCREENSAVER_STATUS = checkScreenSaverStatus();
- if((SCREENSAVER_STATUS == 1) || (SCREENSAVER_STATUS == 0)){
+ if((SCREENSAVER_STATUS == 1) || (SCREENSAVER_STATUS == 0)){
screen_save_dcop_ref.send( "enable", enable);
kdDebugFuncOut(trace);
return true;
@@ -298,6 +298,36 @@ int screen::checkScreenSaverStatus() {
return -1;
}
+bool screen::checkScreenSaverActive()
+{
+ // Check whether the screensaver is enabled
+ bool flagOK = false;
+ bool get_reply = false;
+ DCOPReply reply = screen_save_dcop_ref.call("isEnabled()");
+ if (reply.isValid()) {
+ if (reply.get(get_reply)) {
+ if (get_reply) {
+ flagOK = true;
+ }
+ }
+ }
+ if (!flagOK) {
+ return false;
+ }
+ // Check whether the screensaver is displayed
+ flagOK = false;
+ get_reply = false;
+ reply = screen_save_dcop_ref.call("isBlanked()");
+ if (reply.isValid()) {
+ if (reply.get(get_reply)) {
+ if (get_reply) {
+ flagOK = true;
+ }
+ }
+ }
+ return flagOK;
+}
+
/*!
* \b TQT_SLOT which called if the call of gnomescreensaver-command exited
* \param gnomecheckcommand the KPocess which called this SLOT
@@ -435,7 +465,7 @@ bool screen::lockScreen(){
if(SCREENSAVER_STATUS == -1) SCREENSAVER_STATUS = checkScreenSaverStatus();
// set lock for TDEScreensaver
- if((SCREENSAVER_STATUS == 1) || (SCREENSAVER_STATUS == 0)){
+ if((SCREENSAVER_STATUS == 1) || (SCREENSAVER_STATUS == 0)){
DCOPReply reply = screen_save_dcop_ref.call("lock");
if ( reply.isValid() ) {
return true;
diff --git a/src/screen.h b/src/screen.h
index 56f2acd..eb45fb4 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -170,6 +170,8 @@ public:
int checkScreenSaverStatus();
//! for check the actual status of DPMS on the machine
int checkDPMSStatus();
+ //! for check whether the screensaver is being displayed or not
+ bool checkScreenSaverActive();
//! default constructor
screen();
diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp
index 7737089..793d38c 100644
--- a/src/tdepowersave.cpp
+++ b/src/tdepowersave.cpp
@@ -59,8 +59,8 @@ tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTr
display = new screen();
settings = new Settings();
- autoSuspend = new autosuspend();
- autoDimm = new autodimm();
+ autoSuspend = new autosuspend(display);
+ autoDimm = new autodimm(display);
hwinfo = new HardwareInfo();
suspend = hwinfo->getSuspendSupport();
@@ -1936,7 +1936,7 @@ void tdepowersave::setAutoSuspend( bool resumed ){
if (resumed) {
autoSuspend->stop();
delete autoSuspend;
- autoSuspend = new autosuspend();
+ autoSuspend = new autosuspend(display);
connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn()));
}
@@ -1986,7 +1986,7 @@ void tdepowersave::setAutoDimm( bool resumed ){
// setup again
autoDimm->stop();
delete autoDimm;
- autoDimm = new autodimm();
+ autoDimm = new autodimm(display);
connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm()));
connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm()));
}