From adc92c14ef621d8106796e63f499ec88eb3fe28e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Tue, 24 Nov 2009 20:24:36 +0100
Subject: Added Windows idle querier.


diff --git a/SConstruct b/SConstruct
index cfc34c5..ada5ef2 100644
--- a/SConstruct
+++ b/SConstruct
@@ -89,7 +89,7 @@ if env.get("coverage", 0) :
 	env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"])
 
 if env["PLATFORM"] == "win32" :
-	env.Append(LIBS = ["dnsapi", "ws2_32", "wsock32"])
+	env.Append(LIBS = ["user32", "dnsapi", "ws2_32", "wsock32"])
 	env.Append(CCFLAGS = ["/EHsc", "/nologo"])
 	env["LINKCOM"] = [env["LINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1']
 	env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2']
diff --git a/SwifTools/Idle/PlatformIdleQuerier.cpp b/SwifTools/Idle/PlatformIdleQuerier.cpp
index 80a5da3..fb206b7 100644
--- a/SwifTools/Idle/PlatformIdleQuerier.cpp
+++ b/SwifTools/Idle/PlatformIdleQuerier.cpp
@@ -3,6 +3,8 @@
 
 #if defined(SWIFTEN_PLATFORM_MACOSX)
 #include "SwifTools/Idle/MacOSXIdleQuerier.h"
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+#include "SwifTools/Idle/WindowsIdleQuerier.h"
 #elif defined(HAVE_XSS)
 #include "SwifTools/Idle/XSSIdleQuerier.h"
 #else
@@ -17,6 +19,8 @@ namespace Swift {
 PlatformIdleQuerier::PlatformIdleQuerier() : querier(NULL) {
 #if defined(SWIFTEN_PLATFORM_MACOSX)
 	querier = new MacOSXIdleQuerier();
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+	querier = new WindowsIdleQuerier();
 #elif defined(HAVE_XSS)
 	querier = new XSSIdleQuerier();
 #else
diff --git a/SwifTools/Idle/WindowsIdleQuerier.cpp b/SwifTools/Idle/WindowsIdleQuerier.cpp
new file mode 100644
index 0000000..11b1e75
--- /dev/null
+++ b/SwifTools/Idle/WindowsIdleQuerier.cpp
@@ -0,0 +1,21 @@
+#include "SwifTools/Idle/WindowsIdleQuerier.h"
+
+#include <windows.h>
+
+namespace Swift {
+
+WindowsIdleQuerier::WindowsIdleQuerier() {
+}
+
+int WindowsIdleQuerier::getIdleTimeSeconds() {
+	LASTINPUTINFO info;
+	info.cbSize = sizeof(info);
+	if (GetLastInputInfo(&info)) {
+		return (GetTickCount() - info.dwTime) / 1000;
+	}
+	else {
+		return 0;
+	}
+}
+
+}
diff --git a/SwifTools/Idle/WindowsIdleQuerier.h b/SwifTools/Idle/WindowsIdleQuerier.h
new file mode 100644
index 0000000..0786cbe
--- /dev/null
+++ b/SwifTools/Idle/WindowsIdleQuerier.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "SwifTools/Idle/IdleQuerier.h"
+
+namespace Swift {
+	class WindowsIdleQuerier : public IdleQuerier {
+		public:
+			WindowsIdleQuerier();
+
+			virtual int getIdleTimeSeconds();
+	};
+}
diff --git a/SwifTools/SConscript b/SwifTools/SConscript
index a92e0dc..2ae4e4e 100644
--- a/SwifTools/SConscript
+++ b/SwifTools/SConscript
@@ -17,7 +17,7 @@ sources = [
 	]
 
 if myenv["PLATFORM"] == "win32" :
-	pass
+	sources += ["Idle/WindowsIdleQuerier.cpp"]
 elif myenv["PLATFORM"] == "darwin" :
 	sources += ["Idle/MacOSXIdleQuerier.cpp"]
 elif myenv["HAVE_XSS"] :
-- 
cgit v0.10.2-6-g49f6