2
* idle_win.cpp - detect desktop idle time
3
* Copyright (C) 2003 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#if defined(Q_OS_WIN32) && !defined(Q_CC_GNU) && (_WIN32_WINNT < 0x0500)
27
typedef struct tagLASTINPUTINFO {
30
} LASTINPUTINFO, *PLASTINPUTINFO;
33
class IdlePlatform::Private
39
IdleUIGetLastInputTime = 0;
43
BOOL (__stdcall * GetLastInputInfo)(PLASTINPUTINFO);
44
DWORD (__stdcall * IdleUIGetLastInputTime)(void);
48
IdlePlatform::IdlePlatform()
53
IdlePlatform::~IdlePlatform()
59
bool IdlePlatform::init()
65
// try to find the built-in Windows 2000 function
66
d->lib = new QLibrary("user32");
67
if(d->lib->load() && (p = d->lib->resolve("GetLastInputInfo"))) {
68
d->GetLastInputInfo = (BOOL (__stdcall *)(PLASTINPUTINFO))p;
76
// fall back on idleui
77
d->lib = new QLibrary("idleui");
78
if(d->lib->load() && (p = d->lib->resolve("IdleUIGetLastInputTime"))) {
79
d->IdleUIGetLastInputTime = (DWORD (__stdcall *)(void))p;
90
int IdlePlatform::secondsIdle()
93
if(d->GetLastInputInfo) {
95
li.cbSize = sizeof(LASTINPUTINFO);
96
bool ok = d->GetLastInputInfo(&li);
101
else if(d->IdleUIGetLastInputTime) {
102
i = d->IdleUIGetLastInputTime();
107
return (GetTickCount() - i) / 1000;