summaryrefslogtreecommitdiffstats
blob: 783cc1476cf65e0c7f98a2d650271987604cb519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "QtIdleDetector.h"

#include <QCursor>

namespace Swift {

QtIdleDetector::QtIdleDetector() {
	signalled_ = false;
	lastMoveTime_ = QDateTime::currentDateTime();
	lastPosition_ = QCursor::pos();
	connect(&timer_, SIGNAL(timeout()), this, SLOT(handleTimerTick()));
	timer_.start(1000);
}

QtIdleDetector::~QtIdleDetector() {
}

void QtIdleDetector::forceNotIdle() {

}

void QtIdleDetector::handleTimerTick() {
	QPoint position = QCursor::pos();
	QDateTime now = QDateTime::currentDateTime();
	if (position != lastPosition_) {
		if (signalled_) {
			onInputNotIdle();
		}
		lastPosition_ = position;
		lastMoveTime_ = now;
		signalled_ = false;
	} else if (!signalled_ && now > lastMoveTime_.addSecs(600) && position == lastPosition_) {
		signalled_ = true;
		onInputIdle();
	}
}

}