• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KUtils

windowspoller.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 "windowspoller.h"
00020 
00021 #define _WIN32_WINNT 0x0501
00022 #include <windows.h>
00023 
00024 #include <QTimer>
00025 
00026 WindowsPoller::WindowsPoller(QWidget *parent)
00027         : WidgetBasedPoller(parent)
00028 {
00029 }
00030 
00031 WindowsPoller::~WindowsPoller()
00032 {
00033 }
00034 
00035 int WindowsPoller::getIdleTime()
00036 {
00037     int idle = 0;
00038 
00039     LASTINPUTINFO lii;
00040     memset(&lii, 0, sizeof(lii));
00041 
00042     lii.cbSize = sizeof(lii);
00043 
00044     BOOL ok = GetLastInputInfo(&lii);
00045     if (ok) {
00046         idle = GetTickCount() - lii.dwTime;
00047     }
00048 
00049     return idle;
00050 }
00051 
00052 bool WindowsPoller::additionalSetUp()
00053 {
00054     m_idleTimer = new QTimer(this);
00055     connect(m_idleTimer, SIGNAL(timeout()), this, SLOT(checkForIdle()));
00056     return true;
00057 }
00058 
00059 void WindowsPoller::simulateUserActivity()
00060 {
00061     int width = GetSystemMetrics(SM_CXSCREEN);
00062     int height = GetSystemMetrics(SM_CYSCREEN);
00063 
00064     int x = (int)100 * 65536 / width;
00065     int y = (int)100 * 65536 / height;
00066 
00067     mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, NULL, NULL);
00068 }
00069 
00070 void WindowsPoller::catchIdleEvent()
00071 {
00072     m_idleTimer->start(800);
00073 }
00074 
00075 void WindowsPoller::stopCatchingIdleEvents()
00076 {
00077     m_idleTimer->stop();
00078 }
00079 
00080 void WindowsPoller::checkForIdle()
00081 {
00082     if (getIdleTime() < 1000) {
00083         stopCatchingIdleEvents();
00084         emit resumingFromIdle();
00085     }
00086 }
00087 
00088 #include "windowspoller.moc"

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal