summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-24 18:09:37 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-24 18:09:37 (GMT)
commitc7fb528f0d80f9d96a2d84444352386d5d4288dc (patch)
treebc52f4729e948c5021ab322e6ad739f315d41140 /SwifTools/Idle/XSSIdleQuerier.cpp
parentea951bec1c4b84b739a9f435e0d17dbb99e4d724 (diff)
downloadswift-c7fb528f0d80f9d96a2d84444352386d5d4288dc.zip
swift-c7fb528f0d80f9d96a2d84444352386d5d4288dc.tar.bz2
Added SwifTools/Idle module.
Diffstat (limited to 'SwifTools/Idle/XSSIdleQuerier.cpp')
-rw-r--r--SwifTools/Idle/XSSIdleQuerier.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/SwifTools/Idle/XSSIdleQuerier.cpp b/SwifTools/Idle/XSSIdleQuerier.cpp
new file mode 100644
index 0000000..2259620
--- /dev/null
+++ b/SwifTools/Idle/XSSIdleQuerier.cpp
@@ -0,0 +1,36 @@
+#include "SwifTools/Idle/XSSIdleQuerier.h"
+
+#include <cassert>
+#include <iostream>
+
+namespace Swift {
+
+XSSIdleQuerier::XSSIdleQuerier() : display(NULL), info(NULL) {
+ display = XOpenDisplay(NULL);
+ assert(display);
+ rootWindow = DefaultRootWindow(display);
+ int event, error;
+ available = XScreenSaverQueryExtension(display, &event, &error);
+ if (available) {
+ info = XScreenSaverAllocInfo();
+ }
+ else {
+ std::cerr << "Warning: XScreenSaver extension not found. Idle time detection will not work." << std::endl;
+ }
+}
+
+XSSIdleQuerier::~XSSIdleQuerier() {
+ XFree(info);
+}
+
+int XSSIdleQuerier::getIdleTimeSeconds() {
+ if (available) {
+ XScreenSaverQueryInfo(display, rootWindow, info);
+ return info->idle / 1000;
+ }
+ else {
+ return 0;
+ }
+}
+
+}