Reactos

[STOBJECT][NTUSER][ACCESS] Don't use a systray timer when not needed (#7917)

authored by

Whindmar Saksit and committed by
GitHub
7eb8535e 78e04c07

+124 -36
+2 -2
dll/cpl/access/access.c
··· 189 189 PGLOBAL_DATA pGlobalData; 190 190 PROPSHEETPAGE psp[5]; 191 191 PROPSHEETHEADER psh; 192 - INT nPage = 0; 192 + UINT nPage = 0; // This is unsigned so we don't have to deal with negative numbers 193 193 INT ret; 194 194 195 195 if (uMsg == CPL_STARTWPARMSW && lParam != 0) 196 - nPage = _wtoi((PWSTR)lParam); 196 + nPage = (*(PWSTR)lParam) - '1'; // Convert from 1-based to 0-based. 197 197 198 198 pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA)); 199 199 if (pGlobalData == NULL)
+5
dll/cpl/access/mouse.c
··· 162 162 CheckDlgButton(hwndDlg, 163 163 IDC_MOUSE_BOX, 164 164 pGlobalData->mouseKeys.dwFlags & MKF_MOUSEKEYSON ? BST_CHECKED : BST_UNCHECKED); 165 + 166 + #if 1 // FIXME: Feature not implemented, disable the UI 167 + EnableWindow(GetDlgItem(hwndDlg, IDC_MOUSE_BOX), pGlobalData->mouseKeys.dwFlags & MKF_MOUSEKEYSON); 168 + EnableWindow(GetDlgItem(hwndDlg, IDC_MOUSE_BUTTON), pGlobalData->mouseKeys.dwFlags & MKF_MOUSEKEYSON); 169 + #endif 165 170 return TRUE; 166 171 167 172
+72 -25
dll/shellext/stobject/csystray.cpp
··· 12 12 #include <regstr.h> 13 13 #include <undocshell.h> 14 14 #include <shellutils.h> 15 + #include <shlwapi.h> 15 16 16 17 SysTrayIconHandlers_t g_IconHandlers [] = { 17 18 { VOLUME_SERVICE_FLAG, Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message }, ··· 20 21 }; 21 22 const int g_NumIcons = _countof(g_IconHandlers); 22 23 24 + SysTrayIconHandlers_t g_StandaloneHandlers[] = { 25 + { MOUSE_SERVICE_FLAG, MouseKeys_Init, MouseKeys_Shutdown, MouseKeys_Update, MouseKeys_Message }, 26 + }; 27 + 23 28 CSysTray::CSysTray() : dwServicesEnabled(0) 24 29 { 25 30 wm_SHELLHOOK = RegisterWindowMessageW(L"SHELLHOOK"); 26 - wm_DESTROYWINDOW = RegisterWindowMessageW(L"CSysTray_DESTROY"); 27 31 } 28 32 29 33 CSysTray::~CSysTray() ··· 69 73 this->dwServicesEnabled &= ~dwServiceFlag; 70 74 71 75 if (RegCreateKeyExW(HKEY_CURRENT_USER, 72 - L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray", 76 + REGSTR_PATH_SYSTRAY, 73 77 0, 74 78 NULL, 75 79 REG_OPTION_NON_VOLATILE, ··· 78 82 &hKey, 79 83 NULL) == ERROR_SUCCESS) 80 84 { 85 + DWORD dwConfig = this->dwServicesEnabled & ~STANDALONESERVICEMASK; 81 86 RegSetValueExW(hKey, 82 87 L"Services", 83 88 0, 84 89 REG_DWORD, 85 - (LPBYTE)&this->dwServicesEnabled, 86 - sizeof(DWORD)); 90 + (LPBYTE)&dwConfig, 91 + sizeof(dwConfig)); 87 92 88 93 RegCloseKey(hKey); 89 94 } 95 + 96 + ConfigurePollTimer(); 90 97 } 91 98 92 99 BOOL CSysTray::IsServiceEnabled(DWORD dwServiceFlag) ··· 94 101 return (this->dwServicesEnabled & dwServiceFlag); 95 102 } 96 103 104 + void CSysTray::ConfigurePollTimer() 105 + { 106 + // FIXME: VOLUME_SERVICE_FLAG should use mixerOpen(CALLBACK_WINDOW) 107 + // FIXME: POWER_SERVICE_FLAG should use WM_DEVICECHANGE, WM_POWERBROADCAST 108 + 109 + DWORD fNeedsTimer = VOLUME_SERVICE_FLAG | POWER_SERVICE_FLAG; 110 + if (this->dwServicesEnabled & fNeedsTimer) 111 + SetTimer(POLL_TIMER_ID, 2000, NULL); 112 + else 113 + KillTimer(POLL_TIMER_ID); 114 + } 115 + 97 116 HRESULT CSysTray::InitNetShell() 98 117 { 99 118 HRESULT hr = CoCreateInstance(CLSID_ConnectionTray, 0, 1u, IID_PPV_ARG(IOleCommandTarget, &pctNetShell)); ··· 119 138 HRESULT CSysTray::InitIcons() 120 139 { 121 140 TRACE("Initializing Notification icons...\n"); 122 - for (int i = 0; i < g_NumIcons; i++) 141 + for (UINT i = 0; i < g_NumIcons; i++) 123 142 { 124 143 if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag) 125 144 { ··· 128 147 return hr; 129 148 } 130 149 } 131 - 132 - MouseKeys_Init(this); 150 + for (UINT i = 0; i < _countof(g_StandaloneHandlers); ++i) 151 + { 152 + g_StandaloneHandlers[i].pfnInit(this); 153 + } 133 154 134 155 return InitNetShell(); 135 156 } ··· 137 158 HRESULT CSysTray::ShutdownIcons() 138 159 { 139 160 TRACE("Shutting down Notification icons...\n"); 140 - for (int i = 0; i < g_NumIcons; i++) 161 + for (UINT i = 0; i < g_NumIcons; i++) 141 162 { 142 163 if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag) 143 164 { ··· 146 167 FAILED_UNEXPECTEDLY(hr); 147 168 } 148 169 } 149 - 150 - MouseKeys_Shutdown(this); 170 + for (UINT i = 0; i < _countof(g_StandaloneHandlers); ++i) 171 + { 172 + g_StandaloneHandlers[i].pfnShutdown(this); 173 + } 151 174 152 175 return ShutdownNetShell(); 153 176 } ··· 170 193 171 194 HRESULT CSysTray::ProcessIconMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult) 172 195 { 173 - for (int i = 0; i < g_NumIcons; i++) 196 + for (UINT i = 0; i < g_NumIcons; i++) 174 197 { 175 198 HRESULT hr = g_IconHandlers[i].pfnMessage(this, uMsg, wParam, lParam, lResult); 176 199 if (FAILED(hr)) 177 200 return hr; 178 - 201 + if (hr == S_OK) 202 + return hr; 203 + } 204 + for (UINT i = 0; i < _countof(g_StandaloneHandlers); ++i) 205 + { 206 + HRESULT hr = g_StandaloneHandlers[i].pfnMessage(this, uMsg, wParam, lParam, lResult); 207 + if (FAILED(hr)) 208 + return hr; 179 209 if (hr == S_OK) 180 210 return hr; 181 211 } ··· 285 315 if (!DestroyWindow()) 286 316 { 287 317 // Window is from another thread, ask it politely to destroy itself: 288 - SendMessage(wm_DESTROYWINDOW); 318 + SendMessage(WM_CLOSE); 289 319 } 290 320 return S_OK; 291 321 } ··· 319 349 if (hWnd != m_hWnd) 320 350 return FALSE; 321 351 322 - if (wm_DESTROYWINDOW && uMsg == wm_DESTROYWINDOW) 352 + if (uMsg == wm_SHELLHOOK && wm_SHELLHOOK) 323 353 { 324 - return DestroyWindow(); 325 - } 326 - 327 - if (wm_SHELLHOOK && uMsg == wm_SHELLHOOK) 328 - { 329 - if (wParam == HSHELL_ACCESSIBILITYSTATE && lParam == ACCESS_MOUSEKEYS) 354 + if (wParam == HSHELL_ACCESSIBILITYSTATE && lParam == ACCESS_STICKYKEYS) 355 + { 356 + StickyKeys_Update(this); 357 + } 358 + else if (wParam == HSHELL_ACCESSIBILITYSTATE && lParam == ACCESS_MOUSEKEYS) 330 359 { 331 360 MouseKeys_Update(this); 332 361 } ··· 340 369 case WM_NCDESTROY: 341 370 return FALSE; 342 371 372 + case WM_CLOSE: 373 + return DestroyWindow(); 374 + 343 375 case WM_CREATE: 344 376 GetServicesEnabled(); 345 377 InitIcons(); 346 - SetTimer(1, 2000, NULL); 347 378 RegisterShellHookWindow(hWnd); 379 + ConfigurePollTimer(); 348 380 return TRUE; 349 381 350 382 case WM_TIMER: 351 - if (wParam == 1) 383 + if (wParam == POLL_TIMER_ID) 352 384 UpdateIcons(); 353 385 else 354 386 ProcessIconMessage(uMsg, wParam, lParam, lResult); 355 387 return TRUE; 356 388 357 389 case WM_SETTINGCHANGE: 390 + if (wParam == SPI_SETSTICKYKEYS) 391 + StickyKeys_Update(this); 358 392 if (wParam == SPI_SETMOUSEKEYS) 359 - { 360 393 MouseKeys_Update(this); 361 - } 362 394 break; 363 395 364 396 case WM_DESTROY: 365 - KillTimer(1); 397 + KillTimer(POLL_TIMER_ID); 366 398 DeregisterShellHookWindow(hWnd); 367 399 ShutdownIcons(); 368 400 PostQuitMessage(0); ··· 377 409 378 410 return (hr == S_OK); 379 411 } 412 + 413 + void CSysTray::RunDll(PCSTR Dll, PCSTR Parameters) 414 + { 415 + WCHAR buf[400], rundll[MAX_PATH]; 416 + GetSystemDirectory(rundll, _countof(rundll)); 417 + PathAppendW(rundll, L"rundll32.exe"); 418 + 419 + wsprintfW(buf, L"%hs %hs%hs", "shell32.dll,Control_RunDLL", Dll, Parameters); 420 + ShellExecuteW(NULL, NULL, rundll, buf, NULL, SW_SHOW); 421 + } 422 + 423 + void CSysTray::RunAccessCpl(PCSTR Parameters) 424 + { 425 + RunDll("access.cpl", Parameters); 426 + }
+4
dll/shellext/stobject/csystray.h
··· 55 55 56 56 VOID EnableService(DWORD dwServiceFlag, BOOL bEnable); 57 57 BOOL IsServiceEnabled(DWORD dwServiceFlag); 58 + void ConfigurePollTimer(); 59 + 60 + static void RunDll(PCSTR Dll, PCSTR Parameters); 61 + static void RunAccessCpl(PCSTR Parameters); 58 62 59 63 protected: 60 64 BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD dwMsgMapID = 0);
+1 -6
dll/shellext/stobject/hotplug.cpp
··· 154 154 155 155 static void _RunHotplug(CSysTray * pSysTray) 156 156 { 157 - ShellExecuteW(pSysTray->GetHWnd(), 158 - L"open", 159 - L"rundll32.exe", 160 - L"shell32.dll,Control_RunDLL hotplug.dll", 161 - NULL, 162 - SW_SHOWNORMAL); 157 + pSysTray->RunDll("hotplug.dll", ""); 163 158 } 164 159 165 160 static void _ShowContextMenu(CSysTray * pSysTray)
+17
dll/shellext/stobject/mouse.cpp
··· 123 123 124 124 return pSysTray->NotifyIcon(uId, ID_ICON_MOUSE, g_MkStateIcon, L"MouseKeys"); 125 125 } 126 + 127 + HRESULT STDMETHODCALLTYPE MouseKeys_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult) 128 + { 129 + switch (uMsg) 130 + { 131 + case ID_ICON_MOUSE: 132 + switch (lParam) 133 + { 134 + case WM_LBUTTONDBLCLK: 135 + case WM_RBUTTONDBLCLK: 136 + pSysTray->RunAccessCpl(",,4"); 137 + return S_OK; 138 + } 139 + break; 140 + } 141 + return S_FALSE; 142 + }
+1 -1
dll/shellext/stobject/power.cpp
··· 171 171 172 172 static void _RunPower() 173 173 { 174 - ShellExecuteW(NULL, NULL, L"powercfg.cpl", NULL, NULL, SW_SHOWNORMAL); 174 + CSysTray::RunDll("powercfg.cpl", ""); 175 175 } 176 176 177 177 static void _ShowContextMenu(CSysTray * pSysTray)
+9
dll/shellext/stobject/precomp.h
··· 38 38 #define POWER_SERVICE_FLAG 0x00000001 39 39 #define HOTPLUG_SERVICE_FLAG 0x00000002 40 40 #define VOLUME_SERVICE_FLAG 0x00000004 41 + #define SKEYS_SERVICE_FLAG 0x20000000 42 + #define FKEYS_SERVICE_FLAG 0x40000000 43 + #define MOUSE_SERVICE_FLAG 0x80000000 44 + #define STANDALONESERVICEMASK 0xF0000000 41 45 42 46 #include "csystray.h" 43 47 ··· 78 82 extern HRESULT STDMETHODCALLTYPE MouseKeys_Init(_In_ CSysTray * pSysTray); 79 83 extern HRESULT STDMETHODCALLTYPE MouseKeys_Shutdown(_In_ CSysTray * pSysTray); 80 84 extern HRESULT STDMETHODCALLTYPE MouseKeys_Update(_In_ CSysTray * pSysTray); 85 + extern HRESULT STDMETHODCALLTYPE MouseKeys_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult); 81 86 87 + #define StickyKeys_Update(thisptr) (void)0 // TODO 82 88 89 + #define FilterKeys_Update(thisptr) (void)0 // TODO 90 + 91 + #define POLL_TIMER_ID 1 // FIXME: Use callbacks instead of polling with this timer 83 92 #define POWER_TIMER_ID 2 84 93 #define VOLUME_TIMER_ID 3 85 94 #define HOTPLUG_TIMER_ID 4
+1 -1
dll/shellext/stobject/volume.cpp
··· 220 220 221 221 static void _RunMMCpl() 222 222 { 223 - ShellExecuteW(NULL, NULL, L"mmsys.cpl", NULL, NULL, SW_NORMAL); 223 + CSysTray::RunDll("mmsys.cpl", ""); 224 224 } 225 225 226 226 static void _ShowContextMenu(CSysTray * pSysTray)
+12 -1
win32ss/user/ntuser/sysparams.c
··· 101 101 static const WCHAR* KEY_SCRREAD = L"Control Panel\\Accessibility\\Blind Access"; 102 102 static const WCHAR* VAL_ON = L"On"; 103 103 104 + static const WCHAR* KEY_MOUSEKEYS = L"Control Panel\\Accessibility\\MouseKeys"; 105 + static const WCHAR* VAL_MOUSEKEYS_FLAGS = L"Flags"; 106 + static const WCHAR* VAL_MOUSEKEYS_MAX = L"MaximumSpeed"; 107 + static const WCHAR* VAL_MOUSEKEYS_TIMETOMAX = L"TimeToMaximumSpeed"; 108 + 104 109 /** Loading the settings ******************************************************/ 105 110 106 111 static ··· 336 341 gspv.filterkeys.cbSize = sizeof(FILTERKEYS); 337 342 gspv.togglekeys.cbSize = sizeof(TOGGLEKEYS); 338 343 gspv.mousekeys.cbSize = sizeof(MOUSEKEYS); 344 + gspv.mousekeys.dwFlags = SpiLoadInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_FLAGS, 62); 345 + gspv.mousekeys.iMaxSpeed = SpiLoadInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_MAX, 80); 346 + gspv.mousekeys.iTimeToMaxSpeed = SpiLoadInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_TIMETOMAX, 3000); 347 + gspv.mousekeys.iCtrlSpeed = 8; // FIXME 339 348 gspv.stickykeys.cbSize = sizeof(STICKYKEYS); 340 349 gspv.serialkeys.cbSize = sizeof(SERIALKEYS); 341 350 gspv.soundsentry.cbSize = sizeof(SOUNDSENTRYW); ··· 1197 1206 1198 1207 if (fl & SPIF_UPDATEINIFILE) 1199 1208 { 1200 - // FIXME: What to do? 1209 + SpiStoreSzInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_FLAGS, gspv.mousekeys.dwFlags); 1210 + SpiStoreSzInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_MAX, gspv.mousekeys.iMaxSpeed); 1211 + SpiStoreSzInt(KEY_MOUSEKEYS, VAL_MOUSEKEYS_TIMETOMAX, gspv.mousekeys.iTimeToMaxSpeed); 1201 1212 } 1202 1213 return (UINT_PTR)KEY_DESKTOP; 1203 1214 }