annotate src/win32/IdleTracker/idletrack.c @ 10687:b256ce6b85b8

[gaim-migrate @ 12235] grim says this is really fixed this time. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Sat, 12 Mar 2005 01:10:37 +0000
parents 89ea4b4a9455
children 5c50be815a4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
1 /*
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
2 * idletrack.c
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
3 *
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
4 * Authors: mrgentry @ http://www.experts-exchange.com
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
5 * Herman Bloggs <hermanator12002@yahoo.com>
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
6 * Date: February, 2003
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
7 * Description: Track user inactivity.
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
8 *
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
9 * Andrew Whewell <awhewell@users.sourceforge.net> - 25th June 2004. Added
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
10 * support for GetLastInputInfo under Windows 2000 and above. This avoids having
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
11 * IDLETRACK.DLL hook itself into every process on the machine, which makes
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
12 * upgrades easier. The hook mechanism is also used by key loggers, so not
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
13 * using hooks doesn't put the willys up programs that keep an eye out for
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
14 * loggers.
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
15 *
9419
72013e9ba6d1 [gaim-migrate @ 10234]
Luke Schierer <lschiere@pidgin.im>
parents: 9418
diff changeset
16 * Windows 9x doesn't have GetLastInputInfo - when Gaim runs on these machines
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
17 * the code silently falls back onto the old hooking scheme.
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
18 */
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
19 #define _WIN32_WINNT 0x0500
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
20 #include <windows.h>
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
21
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
22 #define EXPORT __declspec(dllexport)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
23
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
24 static HANDLE hMapObject = NULL;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
25 static DWORD *lastTime = NULL;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
26 static HHOOK keyHook = NULL;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
27 static HHOOK mouseHook = NULL;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
28 static HINSTANCE g_hInstance = NULL;
4548
ae85f27e4948 [gaim-migrate @ 4827]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4533
diff changeset
29 static POINT g_point;
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
30
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
31 /* GetLastInputInfo address and module - if g_GetLastInputInfo == NULL then
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
32 * we fall back on the old "hook the world" method. GetLastInputInfo was brought
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
33 * in with Windows 2000 so Windows 9x will still hook everything.
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
34 */
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
35 typedef BOOL (WINAPI *GETLASTINPUTINFO)(LASTINPUTINFO *);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
36 static HMODULE g_user32 = NULL;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
37 static GETLASTINPUTINFO g_GetLastInputInfo = NULL;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
38
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
39 static DWORD* setup_shared_mem() {
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
40 BOOL fInit;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
41
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
42 /* Set up the shared memory. */
9865
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
43 /*hMapObject = CreateFileMapping((HANDLE) 0xFFFFFFFF, // use paging file
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
44 NULL, // no security attributes
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
45 PAGE_READWRITE, // read/write access
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
46 0, // size: high 32-bits
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
47 sizeof(DWORD), // size: low 32-bits
89ea4b4a9455 [gaim-migrate @ 10744]
Mark Doliner <mark@kingant.net>
parents: 9863
diff changeset
48 "timermem"); // name of map object
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
49 */
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
50 hMapObject = CreateFileMapping((HANDLE) 0xFFFFFFFF,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
51 NULL,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
52 PAGE_READWRITE,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
53 0,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
54 sizeof(DWORD),
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
55 "timermem");
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
56
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
57 if (hMapObject == NULL)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
58 return NULL;
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
59
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
60 /* The first process to attach initializes memory. */
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
61 fInit = (GetLastError() != ERROR_ALREADY_EXISTS);
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
62
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
63 /* Get a pointer to the file-mapped shared memory. */
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
64 /*lastTime = (DWORD*) MapViewOfFile(hMapObject, // object to map view of
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
65 * FILE_MAP_WRITE, // read/write access
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
66 * 0, // high offset: map from
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
67 * 0, // low offset: beginning
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
68 * 0); // default: map entire file
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
69 */
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
70 lastTime = (DWORD*) MapViewOfFile(hMapObject,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
71 FILE_MAP_WRITE,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
72 0,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
73 0,
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
74 0);
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
75
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
76 if (lastTime == NULL)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
77 return NULL;
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
78
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
79 *lastTime = GetTickCount();
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
80
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
81 return lastTime;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
82 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
83
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
84
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
85 LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
6561
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
86 if (!(code < 0)) {
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
87 if (lastTime == NULL)
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
88 lastTime = setup_shared_mem();
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
89
6561
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
90 if (lastTime)
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
91 *lastTime = GetTickCount();
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
92 }
5336
5480a73b2696 [gaim-migrate @ 5712]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4548
diff changeset
93 return CallNextHookEx(keyHook, code, wParam, lParam);
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
94 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
95
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
96
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
97 LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam) {
4548
ae85f27e4948 [gaim-migrate @ 4827]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4533
diff changeset
98 /* We need to verify that the Mouse pointer has actually moved. */
6561
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
99 if(!(code < 0) &&
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
100 !((g_point.x == ((MOUSEHOOKSTRUCT*)lParam)->pt.x) &&
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
101 (g_point.y == ((MOUSEHOOKSTRUCT*)lParam)->pt.y))) {
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
102 g_point.x = ((MOUSEHOOKSTRUCT*)lParam)->pt.x;
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
103 g_point.y = ((MOUSEHOOKSTRUCT*)lParam)->pt.y;
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
104
6561
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
105 if (lastTime == NULL)
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
106 lastTime = setup_shared_mem();
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
107
6561
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
108 if (lastTime)
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
109 *lastTime = GetTickCount();
33ceba0dfd9b [gaim-migrate @ 7083]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5336
diff changeset
110 }
5336
5480a73b2696 [gaim-migrate @ 5712]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4548
diff changeset
111 return CallNextHookEx(mouseHook, code, wParam, lParam);
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
112 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
113
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
114
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
115 EXPORT DWORD wgaim_get_lastactive() {
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
116 DWORD result = 0;
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
117
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
118 /* If we have GetLastInputInfo then use it, otherwise use the hooks*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
119 if (g_GetLastInputInfo != NULL) {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
120 LASTINPUTINFO lii;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
121 memset(&lii, 0, sizeof(lii));
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
122 lii.cbSize = sizeof(lii);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
123 if (g_GetLastInputInfo(&lii)) {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
124 result = lii.dwTime;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
125 }
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
126 } else {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
127 if (lastTime == NULL)
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
128 lastTime = setup_shared_mem();
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
129
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
130 if (lastTime)
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
131 result = *lastTime;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
132 }
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
133
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
134 return result;
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
135 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
136
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
137
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
138 EXPORT BOOL wgaim_set_idlehooks() {
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
139 /* Is GetLastInputInfo available?*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
140 g_user32 = LoadLibrary("user32.dll");
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
141 if (g_user32) {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
142 g_GetLastInputInfo = (GETLASTINPUTINFO)GetProcAddress(g_user32, "GetLastInputInfo");
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
143 }
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
144
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
145 /* If we couldn't find GetLastInputInfo then fall back onto the hooking scheme*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
146 if (g_GetLastInputInfo == NULL) {
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
147 /* Set up the shared memory.*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
148 lastTime = setup_shared_mem();
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
149 if (lastTime == NULL)
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
150 return FALSE;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
151 *lastTime = GetTickCount();
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
152
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
153 /* Set up the keyboard hook.*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
154 keyHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
155 if (keyHook == NULL) {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
156 UnmapViewOfFile(lastTime);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
157 CloseHandle(hMapObject);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
158 return FALSE;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
159 }
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
160
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
161 /* Set up the mouse hook.*/
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
162 mouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInstance, 0);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
163 if (mouseHook == NULL) {
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
164 UnhookWindowsHookEx(keyHook);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
165 UnmapViewOfFile(lastTime);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
166 CloseHandle(hMapObject);
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
167 return FALSE;
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
168 }
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
169 }
9418
61a588bd2e74 [gaim-migrate @ 10233]
Luke Schierer <lschiere@pidgin.im>
parents: 9417
diff changeset
170
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
171 return TRUE;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
172 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
173
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
174
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
175 EXPORT void wgaim_remove_idlehooks() {
9417
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
176 if (g_user32 != NULL)
9f6a28af7164 [gaim-migrate @ 10232]
Luke Schierer <lschiere@pidgin.im>
parents: 7242
diff changeset
177 FreeLibrary(g_user32);
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
178 if (keyHook)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
179 UnhookWindowsHookEx(keyHook);
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
180 if (mouseHook)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
181 UnhookWindowsHookEx(mouseHook);
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
182 if (lastTime)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
183 UnmapViewOfFile(lastTime);
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
184 if (hMapObject)
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
185 CloseHandle(hMapObject);
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
186 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
187
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
188 int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
189 switch(dwReason) {
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
190 case DLL_PROCESS_ATTACH:
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
191 g_hInstance = hInstance;
4548
ae85f27e4948 [gaim-migrate @ 4827]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4533
diff changeset
192 g_point.x = 0;
ae85f27e4948 [gaim-migrate @ 4827]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4533
diff changeset
193 g_point.y = 0;
4533
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
194 break;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
195 case DLL_PROCESS_DETACH:
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
196 break;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
197 }
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
198 return TRUE;
516061abad03 [gaim-migrate @ 4812]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
199 }