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 d67bc99f08)
r14.0.x
Michele Calgaro 9 years ago
parent 504511d4a5
commit bcf8fa06f0

@ -27,7 +27,7 @@
#include "autodimm.h" #include "autodimm.h"
/*! The default constructor of the class autodimm */ /*! The default constructor of the class autodimm */
autodimm::autodimm() : inactivity() { autodimm::autodimm(screen *disp) : inactivity(disp) {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
lastIdleTime = 0; lastIdleTime = 0;

@ -42,7 +42,7 @@ class autodimm : public inactivity
public: public:
//! default constructor //! default constructor
autodimm(); autodimm(screen *disp);
//! default destructor //! default destructor
~autodimm(); ~autodimm();

@ -26,7 +26,7 @@
#include "autosuspend.h" #include "autosuspend.h"
/*! The default constructor of the class autosuspend */ /*! The default constructor of the class autosuspend */
autosuspend::autosuspend() : inactivity () { autosuspend::autosuspend(screen *disp) : inactivity (disp) {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
} }

@ -41,7 +41,7 @@ class autosuspend : public inactivity
public: public:
//! default constructor //! default constructor
autosuspend(); autosuspend(screen *disp);
//! default destructor //! default destructor
~autosuspend(); ~autosuspend();
}; };

@ -37,7 +37,8 @@ extern "C" {
#include <tdelocale.h> #include <tdelocale.h>
/*! The default constructor of the class autosuspend */ /*! 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); kdDebugFuncIn(trace);
proc = NULL; proc = NULL;
@ -71,7 +72,7 @@ inactivity::~inactivity() {
/*! /*!
* This function start the monitoring of inactivity of user on the X-Server. * 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. * 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. * to elapse befor send signal. The time is in seconds.
@ -86,6 +87,9 @@ void inactivity::start( int timeToExpire, TQStringList blacked ) {
if(timeToExpire > 0 && has_XSC_Extension){ if(timeToExpire > 0 && has_XSC_Extension){
stop(); stop();
timeToInactivity = (unsigned long) (timeToExpire * 1000); timeToInactivity = (unsigned long) (timeToExpire * 1000);
prev_screensaver_enabled = false;
prev_idle_time = 0;
correction_value = 0;
checkInactivity->start(CHECK_for_INACTIVITY, true); checkInactivity->start(CHECK_for_INACTIVITY, true);
} }
@ -198,7 +202,7 @@ unsigned long inactivity::getXInactivity(){
if (!mitInfo) mitInfo = XScreenSaverAllocInfo (); if (!mitInfo) mitInfo = XScreenSaverAllocInfo ();
XScreenSaverQueryInfo (tqt_xdisplay(), DefaultRootWindow (tqt_xdisplay()), mitInfo); XScreenSaverQueryInfo (tqt_xdisplay(), DefaultRootWindow (tqt_xdisplay()), mitInfo);
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
return workaroundCreepyXServer(mitInfo->idle); return workaroundCreepyXServer(mitInfo);
} }
else { else {
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
@ -219,12 +223,36 @@ unsigned long inactivity::getXInactivity(){
* current timeout for this state and add this value to * current timeout for this state and add this value to
* the current idle time and return. * the current idle time and return.
* *
* \param _idleTime a unsigned long value with the current ideletime fromm * \param _mitInfo a pointer to a structure containing the current XScreenSaver state
* XScreenSaverInfo->idle
* \return a unsigned long with the corrected idletime * \return a unsigned long with the corrected idletime
*/ */
unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){ unsigned long inactivity::workaroundCreepyXServer(XScreenSaverInfo *_mitInfo){
kdDebugFuncOut(trace); 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; int dummy;
CARD16 standby, suspend, off; CARD16 standby, suspend, off;
@ -235,6 +263,8 @@ unsigned long inactivity::workaroundCreepyXServer( unsigned long _idleTime ){
kdDebug() << "Current idleTime: " << _idleTime << endl; 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 (DPMSQueryExtension(dpy, &dummy, &dummy)) {
if (DPMSCapable(dpy)) { if (DPMSCapable(dpy)) {
DPMSGetTimeouts(dpy, &standby, &suspend, &off); DPMSGetTimeouts(dpy, &standby, &suspend, &off);

@ -42,8 +42,14 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
/* needed for lXext C library linkage */
extern "C" {
#include <X11/extensions/scrnsaver.h>
}
// from project // from project
#include "tdepowersave_debug.h" #include "tdepowersave_debug.h"
#include "screen.h"
/*! /*!
* \file inactivity.h * \file inactivity.h
@ -63,7 +69,7 @@ class inactivity : public TQWidget
public: public:
//! default constructor //! default constructor
inactivity(); inactivity(screen *disp);
//! default destructor //! default destructor
~inactivity(); ~inactivity();
@ -135,16 +141,21 @@ private:
* The time intervall to check for the current status and time of * The time intervall to check for the current status and time of
* userinactivity. The timeslice is currently 30 sec. * 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 //! TQTimer for check inactivity
/*! /*!
* This timer is used to check the currently status and time of * 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 . * \ref CHECK_for_INACTIVITY .
*/ */
TQTimer *checkInactivity; TQTimer *checkInactivity;
screen *display; // No ownership here!!
bool prev_screensaver_enabled;
unsigned long prev_idle_time;
unsigned long correction_value;
// -------- FUNCTIONS ------------ // -------- FUNCTIONS ------------
//! to check the user-inactivity on the XServer //! to check the user-inactivity on the XServer
@ -154,7 +165,7 @@ private:
//! to monitor the values //! to monitor the values
void check( bool recheck ); void check( bool recheck );
//! to workaround a strange behavior of the XScreenSaver extension //! to workaround a strange behavior of the XScreenSaver extension
unsigned long workaroundCreepyXServer( unsigned long ); unsigned long workaroundCreepyXServer(XScreenSaverInfo *_mitInfo);
private slots: private slots:

@ -298,6 +298,36 @@ int screen::checkScreenSaverStatus() {
return -1; 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 * \b TQT_SLOT which called if the call of gnomescreensaver-command exited
* \param gnomecheckcommand the KPocess which called this SLOT * \param gnomecheckcommand the KPocess which called this SLOT

@ -170,6 +170,8 @@ public:
int checkScreenSaverStatus(); int checkScreenSaverStatus();
//! for check the actual status of DPMS on the machine //! for check the actual status of DPMS on the machine
int checkDPMSStatus(); int checkDPMSStatus();
//! for check whether the screensaver is being displayed or not
bool checkScreenSaverActive();
//! default constructor //! default constructor
screen(); screen();

@ -59,8 +59,8 @@ tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTr
display = new screen(); display = new screen();
settings = new Settings(); settings = new Settings();
autoSuspend = new autosuspend(); autoSuspend = new autosuspend(display);
autoDimm = new autodimm(); autoDimm = new autodimm(display);
hwinfo = new HardwareInfo(); hwinfo = new HardwareInfo();
suspend = hwinfo->getSuspendSupport(); suspend = hwinfo->getSuspendSupport();
@ -1936,7 +1936,7 @@ void tdepowersave::setAutoSuspend( bool resumed ){
if (resumed) { if (resumed) {
autoSuspend->stop(); autoSuspend->stop();
delete autoSuspend; delete autoSuspend;
autoSuspend = new autosuspend(); autoSuspend = new autosuspend(display);
connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn())); connect(autoSuspend, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_autosuspendWarn()));
} }
@ -1986,7 +1986,7 @@ void tdepowersave::setAutoDimm( bool resumed ){
// setup again // setup again
autoDimm->stop(); autoDimm->stop();
delete autoDimm; delete autoDimm;
autoDimm = new autodimm(); autoDimm = new autodimm(display);
connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm())); connect(autoDimm, TQT_SIGNAL(inactivityTimeExpired()), this, TQT_SLOT(do_downDimm()));
connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm())); connect(autoDimm, TQT_SIGNAL(UserIsActiveAgain()), this, TQT_SLOT(do_upDimm()));
} }

Loading…
Cancel
Save