KIdleTime

windowspoller.cpp
1/* This file is part of the KDE libraries
2 * SPDX-FileCopyrightText: 2009 Dario Freddi <drf at kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "windowspoller.h"
8
9#include <windows.h>
10
11#include <QTimer>
12
13WindowsPoller::WindowsPoller(QObject *parent)
14 : KWindowBasedIdleTimePoller(parent)
15{
16}
17
18WindowsPoller::~WindowsPoller()
19{
20}
21
22int WindowsPoller::getIdleTime()
23{
24#ifndef _WIN32_WCE
25 int idle = 0;
26
27 LASTINPUTINFO lii;
28 memset(&lii, 0, sizeof(lii));
29
30 lii.cbSize = sizeof(lii);
31
32 BOOL ok = GetLastInputInfo(&lii);
33 if (ok) {
34 idle = GetTickCount() - lii.dwTime;
35 }
36
37 return idle;
38#else
39 return GetIdleTime();
40#endif
41}
42
43bool WindowsPoller::additionalSetUp()
44{
45 m_idleTimer = new QTimer(this);
46 connect(m_idleTimer, &QTimer::timeout, this, &WindowsPoller::checkForIdle);
47 return true;
48}
49
50void WindowsPoller::simulateUserActivity()
51{
52 int width = GetSystemMetrics(SM_CXSCREEN);
53 int height = GetSystemMetrics(SM_CYSCREEN);
54
55 int x = (int)100 * 65536 / width;
56 int y = (int)100 * 65536 / height;
57
58 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, NULL, NULL);
59}
60
61void WindowsPoller::catchIdleEvent()
62{
63 m_idleTimer->start(800);
64}
65
66void WindowsPoller::stopCatchingIdleEvents()
67{
68 m_idleTimer->stop();
69}
70
71void WindowsPoller::checkForIdle()
72{
73 if (getIdleTime() < 1000) {
74 stopCatchingIdleEvents();
75 Q_EMIT resumingFromIdle();
76 }
77}
78
79#include "moc_windowspoller.cpp"
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void start()
void stop()
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:10:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.