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
typedef struct tagLASTINPUTINFO {
29
} LASTINPUTINFO, *PLASTINPUTINFO;
31
class IdlePlatform::Private
37
IdleUIGetLastInputTime = 0;
41
BOOL (__stdcall * GetLastInputInfo)(PLASTINPUTINFO);
42
DWORD (__stdcall * IdleUIGetLastInputTime)(void);
46
IdlePlatform::IdlePlatform()
51
IdlePlatform::~IdlePlatform()
57
bool IdlePlatform::init()
63
// try to find the built-in Windows 2000 function
64
d->lib = new QLibrary("user32");
65
if(d->lib->load() && (p = d->lib->resolve("GetLastInputInfo"))) {
66
d->GetLastInputInfo = (BOOL (__stdcall *)(PLASTINPUTINFO))p;
74
// fall back on idleui
75
d->lib = new QLibrary("idleui");
76
if(d->lib->load() && (p = d->lib->resolve("IdleUIGetLastInputTime"))) {
77
d->IdleUIGetLastInputTime = (DWORD (__stdcall *)(void))p;
88
int IdlePlatform::secondsIdle()
91
if(d->GetLastInputInfo) {
93
li.cbSize = sizeof(LASTINPUTINFO);
94
bool ok = d->GetLastInputInfo(&li);
99
else if(d->IdleUIGetLastInputTime) {
100
i = d->IdleUIGetLastInputTime();
105
return (GetTickCount() - i) / 1000;