KUtils
xscreensaverbasedpoller.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2009 Dario Freddi <drf at kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "xscreensaverbasedpoller.h" 00020 00021 #include <config-kidletime.h> 00022 00023 #include <QX11Info> 00024 00025 #include <X11/Xlib.h> 00026 #include <X11/extensions/scrnsaver.h> 00027 00028 XScreensaverBasedPoller::XScreensaverBasedPoller(QWidget *parent) 00029 : WidgetBasedPoller(parent) 00030 { 00031 00032 } 00033 00034 XScreensaverBasedPoller::~XScreensaverBasedPoller() 00035 { 00036 } 00037 00038 bool XScreensaverBasedPoller::additionalSetUp() 00039 { 00040 m_screenSaverIface = new OrgFreedesktopScreenSaverInterface("org.freedesktop.ScreenSaver", "/ScreenSaver", 00041 QDBusConnection::sessionBus(), this); 00042 00043 connect(m_screenSaverIface, SIGNAL(ActiveChanged(bool)), SLOT(screensaverActivated(bool))); 00044 00045 return true; 00046 } 00047 00048 void XScreensaverBasedPoller::screensaverActivated(bool activated) 00049 { 00050 // We care only if it has been disactivated 00051 00052 if (!activated) { 00053 m_screenSaverIface->SimulateUserActivity(); 00054 emit resumingFromIdle(); 00055 } 00056 } 00057 00058 int XScreensaverBasedPoller::getIdleTime() 00059 { 00060 XScreenSaverInfo * mitInfo = 0; 00061 mitInfo = XScreenSaverAllocInfo(); 00062 XScreenSaverQueryInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display()), mitInfo); 00063 int ret = mitInfo->idle; 00064 XFree( mitInfo ); 00065 return ret; 00066 } 00067 00068 void XScreensaverBasedPoller::simulateUserActivity() 00069 { 00070 stopCatchingIdleEvents(); 00071 XResetScreenSaver(QX11Info::display()); 00072 emit resumingFromIdle(); 00073 } 00074 00075 #include "xscreensaverbasedpoller.moc"
KDE 4.6 API Reference