20 #include <QtCore/QObject>
21 #include <QtCore/QDateTime>
22 #include <QtGui/QX11Info>
23 #include <QtDBus/QDBusInterface>
24 #include <QtDBus/QDBusReply>
27 #include <X11/Xutil.h>
28 #include <X11/extensions/scrnsaver.h>
33 if ( err->error_code == BadDrawable )
40 class Kopete::IdlePlatform::Private :
public QObject
46 XScreenSaverInfo *ss_info;
47 QDateTime screenSaverIdleSince;
49 void activeChanged(
bool active )
53 if ( ss_info && XScreenSaverQueryInfo( QX11Info::display(), QX11Info::appRootWindow(), ss_info ) )
54 screenSaverIdleSince = QDateTime::currentDateTime().addMSecs(-ss_info->idle);
56 screenSaverIdleSince = QDateTime::currentDateTime();
60 screenSaverIdleSince = QDateTime();
92 int event_base, error_base;
93 if ( XScreenSaverQueryExtension( QX11Info::display(), &event_base, &error_base ) )
95 d->ss_info = XScreenSaverAllocInfo();
98 QDBusConnection::sessionBus().connect(
"org.freedesktop.ScreenSaver",
"/ScreenSaver",
99 "org.freedesktop.ScreenSaver",
"ActiveChanged",
100 d, SLOT(activeChanged(
bool)));
103 QDBusInterface screenSaver(
"org.freedesktop.ScreenSaver",
"/ScreenSaver",
"org.freedesktop.ScreenSaver");
104 QDBusReply<bool> reply = screenSaver.call(
"GetActive");
105 if ( reply.isValid() && reply.value() )
106 d->screenSaverIdleSince = QDateTime::currentDateTime();
120 if ( d->screenSaverIdleSince.isValid() ) {
121 return d->screenSaverIdleSince.secsTo(QDateTime::currentDateTime());
124 if ( !XScreenSaverQueryInfo( QX11Info::display(), QX11Info::appRootWindow(), d->ss_info ) )
127 return d->ss_info->idle / 1000;
130 #include "kopeteidleplatform_x11.moc"