summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-05-27 23:14:26 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-05-27 23:14:26 (GMT)
commit99166f48dd544d3fef849683b0b40175d7238547 (patch)
tree628e1802dd6cb304781edf0f4c92998bc0d943cf /win
parent1c838522c0b377c7567543d50640f9290e506db4 (diff)
downloadtk-99166f48dd544d3fef849683b0b40175d7238547.zip
tk-99166f48dd544d3fef849683b0b40175d7238547.tar.gz
tk-99166f48dd544d3fef849683b0b40175d7238547.tar.bz2
Partial implementation of TIP#245; thanks Reinhard!
Diffstat (limited to 'win')
-rw-r--r--win/tkWinX.c96
1 files changed, 95 insertions, 1 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c
index ef99c24..bea8b9f 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -10,9 +10,17 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinX.c,v 1.45 2005/03/04 01:13:03 hobbs Exp $
+ * RCS: @(#) $Id: tkWinX.c,v 1.46 2005/05/27 23:14:29 dkf Exp $
*/
+/*
+ * Make sure the SendInput API is available:
+ */
+#if (_WIN32_WINNT <= 0x0400)
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0401
+#endif
+
#include "tkWinInt.h"
/*
@@ -1837,3 +1845,89 @@ Tk_SetCaretPos(Tk_Window tkwin, int x, int y, int height)
}
}
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tk_GetUserInactiveTime --
+ *
+ * Return the number of milliseconds the user was inactive.
+ *
+ * Results:
+ * Milliseconds of user inactive time or -1 if the user32.dll doesn't
+ * have the symbol GetLastInputInfo or GetLastInputInfo returns an
+ * error.
+ *
+ * Side effects:
+ * None.
+ *----------------------------------------------------------------------
+ */
+
+long
+Tk_GetUserInactiveTime(dpy)
+ Display *dpy; /* Ignored on Windows */
+{
+ struct tagLASTINPUTINFO {
+ UINT cbSize;
+ DWORD dwTime;
+ } li;
+ /*
+ * Multiple settings of either of these variables should be OK;
+ * any thread hazards should just cause inefficiency...
+ */
+ static FARPROC pfnGetLastInputInfo = NULL;
+ static int initinfo = 0;
+
+ if (!initinfo) {
+ HMODULE hMod = GetModuleHandleA("USER32.DLL");
+
+ initinfo = 1;
+ if (hMod){
+ pfnGetLastInputInfo =
+ GetProcAddress(hMod, "GetLastInputInfo");
+ }
+ }
+ if (pfnGetLastInputInfo == NULL) {
+ return -1;
+ }
+ li.cbSize = sizeof(li);
+ if (!(BOOL)(pfnGetLastInputInfo)(&li)) {
+ return -1;
+ }
+ /* last input info is in milliseconds, since restart time. */
+ return (GetTickCount()-li.dwTime);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tk_ResetUserInactiveTime --
+ *
+ * Reset the user inactivity timer
+ *
+ * Results:
+ * none
+ *
+ * Side effects:
+ * The user inactivity timer of the underlaying windowing system
+ * is reset to zero.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+Tk_ResetUserInactiveTime(dpy)
+ Display *dpy;
+{
+ INPUT inp;
+
+ inp.type=INPUT_MOUSE;
+ inp.mi.dx=0;
+ inp.mi.dy=0;
+ inp.mi.mouseData=0;
+ inp.mi.dwFlags=MOUSEEVENTF_MOVE;
+ inp.mi.time=0;
+ inp.mi.dwExtraInfo=NULL;
+
+ SendInput(1, &inp, sizeof(inp));
+}