1 /***************************************************************************
2 * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 **************************************************************************/
20 #include "TimerBasedPoller.h"
22 #include <klocalizedstring.h>
24 TimerBasedPoller::TimerBasedPoller(QObject
*parent
)
25 : AbstractSystemPoller(parent
),
26 m_pollTimer(new QTimer(this)),
33 TimerBasedPoller::~TimerBasedPoller()
38 QString
TimerBasedPoller::name()
40 return i18n("Timer Based");
43 bool TimerBasedPoller::isAvailable()
45 #ifdef HAVE_XSCREENSAVER
52 bool TimerBasedPoller::setUpPoller()
54 m_pollTimer
->start(800);
56 connect(m_pollTimer
, SIGNAL(timeout()), SLOT(poll()));
61 void TimerBasedPoller::unloadPoller()
65 void TimerBasedPoller::setNextTimeout(int nextTimeout
)
71 void TimerBasedPoller::forcePollRequest()
77 #ifdef HAVE_XSCREENSAVER
78 #include <X11/extensions/scrnsaver.h>
82 void TimerBasedPoller::poll()
84 /* Hack! Since KRunner still doesn't behave properly, the
85 * correct way to go doesn't work (yet), and it's this one:
86 ------------------------------------------------------------
87 int idle = m_screenSaverIface->GetSessionIdleTime();
88 ------------------------------------------------------------
90 /// In the meanwhile, this X11 hackish way gets its job done.
91 //----------------------------------------------------------
95 #ifdef HAVE_XSCREENSAVER
96 XScreenSaverInfo
* mitInfo
= 0;
97 mitInfo
= XScreenSaverAllocInfo();
98 XScreenSaverQueryInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display()), mitInfo
);
99 idle
= mitInfo
->idle
/ 1000;
100 //----------------------------------------------------------
103 if (m_lastIdleTime
> idle
&& m_catchingIdle
) {
105 emit
resumingFromIdle();
108 m_lastIdleTime
= idle
;
109 emit
pollRequest(m_lastIdleTime
);
113 void TimerBasedPoller::stopCatchingTimeouts()
115 // Nothing we can do here
118 void TimerBasedPoller::stopCatchingIdleEvents()
120 m_catchingIdle
= false;
123 void TimerBasedPoller::catchIdleEvent()
125 m_catchingIdle
= true;
128 #include "TimerBasedPoller.moc"