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 #ifndef _WIN32_WCE 00038 int idle = 0; 00039 00040 LASTINPUTINFO lii; 00041 memset(&lii, 0, sizeof(lii)); 00042 00043 lii.cbSize = sizeof(lii); 00044 00045 BOOL ok = GetLastInputInfo(&lii); 00046 if (ok) { 00047 idle = GetTickCount() - lii.dwTime; 00048 } 00049 00050 return idle; 00051 #else 00052 return GetIdleTime(); 00053 #endif 00054 } 00055 00056 bool WindowsPoller::additionalSetUp() 00057 { 00058 m_idleTimer = new QTimer(this); 00059 connect(m_idleTimer, SIGNAL(timeout()), this, SLOT(checkForIdle())); 00060 return true; 00061 } 00062 00063 void WindowsPoller::simulateUserActivity() 00064 { 00065 int width = GetSystemMetrics(SM_CXSCREEN); 00066 int height = GetSystemMetrics(SM_CYSCREEN); 00067 00068 int x = (int)100 * 65536 / width; 00069 int y = (int)100 * 65536 / height; 00070 00071 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, NULL, NULL); 00072 } 00073 00074 void WindowsPoller::catchIdleEvent() 00075 { 00076 m_idleTimer->start(800); 00077 } 00078 00079 void WindowsPoller::stopCatchingIdleEvents() 00080 { 00081 m_idleTimer->stop(); 00082 } 00083 00084 void WindowsPoller::checkForIdle() 00085 { 00086 if (getIdleTime() < 1000) { 00087 stopCatchingIdleEvents(); 00088 emit resumingFromIdle(); 00089 } 00090 } 00091 00092 #include "windowspoller.moc"
KDE 4.6 API Reference