summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtIdleDetector.cpp')
-rw-r--r--Swift/QtUI/QtIdleDetector.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/Swift/QtUI/QtIdleDetector.cpp b/Swift/QtUI/QtIdleDetector.cpp
index e947854..783cc14 100644
--- a/Swift/QtUI/QtIdleDetector.cpp
+++ b/Swift/QtUI/QtIdleDetector.cpp
@@ -1,8 +1,15 @@
#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() {
@@ -12,5 +19,20 @@ 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();
+ }
+}
}