comparison src/win32/IdleTracker/idletrack.c @ 13430:099bb2149158

[gaim-migrate @ 15805] Cleanup. Mostly whitespace, but also some warning fixes. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 07 Mar 2006 04:58:43 +0000
parents 5c50be815a4e
children
comparison
equal deleted inserted replaced
13429:a37e21fbde75 13430:099bb2149158
15 * 15 *
16 * Windows 9x doesn't have GetLastInputInfo - when Gaim runs on these machines 16 * Windows 9x doesn't have GetLastInputInfo - when Gaim runs on these machines
17 * the code silently falls back onto the old hooking scheme. 17 * the code silently falls back onto the old hooking scheme.
18 */ 18 */
19 #define _WIN32_WINNT 0x0500 19 #define _WIN32_WINNT 0x0500
20 #include <windows.h> 20 #include "idletrack.h"
21 21
22 #define EXPORT __declspec(dllexport) 22 #define EXPORT __declspec(dllexport)
23 23
24 static HANDLE hMapObject = NULL; 24 static HANDLE hMapObject = NULL;
25 static DWORD *lastTime = NULL; 25 static DWORD *lastTime = NULL;
45 PAGE_READWRITE, /* read/write access */ 45 PAGE_READWRITE, /* read/write access */
46 0, /* size: high 32-bits */ 46 0, /* size: high 32-bits */
47 sizeof(DWORD), /* size: low 32-bits */ 47 sizeof(DWORD), /* size: low 32-bits */
48 "timermem"); /* name of map object */ 48 "timermem"); /* name of map object */
49 49
50 if (hMapObject == NULL) 50 if(hMapObject == NULL)
51 return NULL; 51 return NULL;
52 52
53 /* The first process to attach initializes memory. */ 53 /* The first process to attach initializes memory. */
54 fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 54 fInit = (GetLastError() != ERROR_ALREADY_EXISTS);
55 55
58 FILE_MAP_WRITE, /* read/write access */ 58 FILE_MAP_WRITE, /* read/write access */
59 0, /* high offset: map from */ 59 0, /* high offset: map from */
60 0, /* low offset: beginning */ 60 0, /* low offset: beginning */
61 0); /* default: map entire file */ 61 0); /* default: map entire file */
62 62
63 if (lastTime == NULL) 63 if(lastTime == NULL)
64 return NULL; 64 return NULL;
65 65
66 *lastTime = GetTickCount(); 66 *lastTime = GetTickCount();
67 67
68 return lastTime; 68 return lastTime;
69 } 69 }
70 70
71 71
72 LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam) { 72 static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
73 if (!(code < 0)) { 73 if(!(code < 0)) {
74 if (lastTime == NULL) 74 if(lastTime == NULL)
75 lastTime = setup_shared_mem(); 75 lastTime = setup_shared_mem();
76 76
77 if (lastTime) 77 if(lastTime)
78 *lastTime = GetTickCount(); 78 *lastTime = GetTickCount();
79 } 79 }
80 return CallNextHookEx(keyHook, code, wParam, lParam); 80 return CallNextHookEx(keyHook, code, wParam, lParam);
81 } 81 }
82 82
83 83
84 LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam) { 84 static LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam) {
85 /* We need to verify that the Mouse pointer has actually moved. */ 85 /* We need to verify that the Mouse pointer has actually moved. */
86 if(!(code < 0) && 86 if(!(code < 0) &&
87 !((g_point.x == ((MOUSEHOOKSTRUCT*)lParam)->pt.x) && 87 !((g_point.x == ((MOUSEHOOKSTRUCT*) lParam)->pt.x) &&
88 (g_point.y == ((MOUSEHOOKSTRUCT*)lParam)->pt.y))) { 88 (g_point.y == ((MOUSEHOOKSTRUCT*) lParam)->pt.y))) {
89 g_point.x = ((MOUSEHOOKSTRUCT*)lParam)->pt.x; 89 g_point.x = ((MOUSEHOOKSTRUCT*) lParam)->pt.x;
90 g_point.y = ((MOUSEHOOKSTRUCT*)lParam)->pt.y; 90 g_point.y = ((MOUSEHOOKSTRUCT*) lParam)->pt.y;
91 91
92 if (lastTime == NULL) 92 if(lastTime == NULL)
93 lastTime = setup_shared_mem(); 93 lastTime = setup_shared_mem();
94 94
95 if (lastTime) 95 if(lastTime)
96 *lastTime = GetTickCount(); 96 *lastTime = GetTickCount();
97 } 97 }
98 return CallNextHookEx(mouseHook, code, wParam, lParam); 98 return CallNextHookEx(mouseHook, code, wParam, lParam);
99 } 99 }
100 100
101 101
102 EXPORT DWORD wgaim_get_lastactive() { 102 EXPORT DWORD wgaim_get_lastactive() {
103 DWORD result = 0; 103 DWORD result = 0;
104 104
105 /* If we have GetLastInputInfo then use it, otherwise use the hooks*/ 105 /* If we have GetLastInputInfo then use it, otherwise use the hooks*/
106 if (g_GetLastInputInfo != NULL) { 106 if(g_GetLastInputInfo != NULL) {
107 LASTINPUTINFO lii; 107 LASTINPUTINFO lii;
108 memset(&lii, 0, sizeof(lii)); 108 memset(&lii, 0, sizeof(lii));
109 lii.cbSize = sizeof(lii); 109 lii.cbSize = sizeof(lii);
110 if (g_GetLastInputInfo(&lii)) { 110 if(g_GetLastInputInfo(&lii)) {
111 result = lii.dwTime; 111 result = lii.dwTime;
112 } 112 }
113 } else { 113 } else {
114 if (lastTime == NULL) 114 if(lastTime == NULL)
115 lastTime = setup_shared_mem(); 115 lastTime = setup_shared_mem();
116 116
117 if (lastTime) 117 if(lastTime)
118 result = *lastTime; 118 result = *lastTime;
119 } 119 }
120 120
121 return result; 121 return result;
122 } 122 }
123 123
124 124
125 EXPORT BOOL wgaim_set_idlehooks() { 125 EXPORT BOOL wgaim_set_idlehooks() {
126 /* Is GetLastInputInfo available?*/ 126 /* Is GetLastInputInfo available?*/
127 g_user32 = LoadLibrary("user32.dll"); 127 g_user32 = LoadLibrary("user32.dll");
128 if (g_user32) { 128 if(g_user32) {
129 g_GetLastInputInfo = (GETLASTINPUTINFO)GetProcAddress(g_user32, "GetLastInputInfo"); 129 g_GetLastInputInfo = (GETLASTINPUTINFO) GetProcAddress(g_user32, "GetLastInputInfo");
130 } 130 }
131 131
132 /* If we couldn't find GetLastInputInfo then fall back onto the hooking scheme*/ 132 /* If we couldn't find GetLastInputInfo then fall back onto the hooking scheme*/
133 if (g_GetLastInputInfo == NULL) { 133 if(g_GetLastInputInfo == NULL) {
134 /* Set up the shared memory.*/ 134 /* Set up the shared memory.*/
135 lastTime = setup_shared_mem(); 135 lastTime = setup_shared_mem();
136 if (lastTime == NULL) 136 if(lastTime == NULL)
137 return FALSE; 137 return FALSE;
138 *lastTime = GetTickCount(); 138 *lastTime = GetTickCount();
139 139
140 /* Set up the keyboard hook.*/ 140 /* Set up the keyboard hook.*/
141 keyHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0); 141 keyHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstance, 0);
142 if (keyHook == NULL) { 142 if(keyHook == NULL) {
143 UnmapViewOfFile(lastTime); 143 UnmapViewOfFile(lastTime);
144 CloseHandle(hMapObject); 144 CloseHandle(hMapObject);
145 return FALSE; 145 return FALSE;
146 } 146 }
147 147
148 /* Set up the mouse hook.*/ 148 /* Set up the mouse hook.*/
149 mouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInstance, 0); 149 mouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInstance, 0);
150 if (mouseHook == NULL) { 150 if(mouseHook == NULL) {
151 UnhookWindowsHookEx(keyHook); 151 UnhookWindowsHookEx(keyHook);
152 UnmapViewOfFile(lastTime); 152 UnmapViewOfFile(lastTime);
153 CloseHandle(hMapObject); 153 CloseHandle(hMapObject);
154 return FALSE; 154 return FALSE;
155 } 155 }
156 } 156 }
157 157
158 return TRUE; 158 return TRUE;
159 } 159 }
160 160
161 161
162 EXPORT void wgaim_remove_idlehooks() { 162 EXPORT void wgaim_remove_idlehooks() {
163 if (g_user32 != NULL) 163 if(g_user32 != NULL)
164 FreeLibrary(g_user32); 164 FreeLibrary(g_user32);
165 if (keyHook) 165 if(keyHook)
166 UnhookWindowsHookEx(keyHook); 166 UnhookWindowsHookEx(keyHook);
167 if (mouseHook) 167 if(mouseHook)
168 UnhookWindowsHookEx(mouseHook); 168 UnhookWindowsHookEx(mouseHook);
169 if (lastTime) 169 if(lastTime)
170 UnmapViewOfFile(lastTime); 170 UnmapViewOfFile(lastTime);
171 if (hMapObject) 171 if(hMapObject)
172 CloseHandle(hMapObject); 172 CloseHandle(hMapObject);
173 } 173 }
174 174
175 int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { 175 int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
176 switch(dwReason) { 176 switch(dwReason) {