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 
13 WindowsPoller::WindowsPoller(QObject *parent)
14  : KWindowBasedIdleTimePoller(parent)
15 {
16 }
17 
18 WindowsPoller::~WindowsPoller()
19 {
20 }
21 
22 int 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 
43 bool WindowsPoller::additionalSetUp()
44 {
45  m_idleTimer = new QTimer(this);
46  connect(m_idleTimer, &QTimer::timeout, this, &WindowsPoller::checkForIdle);
47  return true;
48 }
49 
50 void 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 
61 void WindowsPoller::catchIdleEvent()
62 {
63  m_idleTimer->start(800);
64 }
65 
66 void WindowsPoller::stopCatchingIdleEvents()
67 {
68  m_idleTimer->stop();
69 }
70 
71 void WindowsPoller::checkForIdle()
72 {
73  if (getIdleTime() < 1000) {
74  stopCatchingIdleEvents();
75  Q_EMIT resumingFromIdle();
76  }
77 }
78 
79 #include "moc_windowspoller.cpp"
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 04:07:39 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.