https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c0eb40713051eab0c38c6663c9d762e0505ac863

commit c0eb40713051eab0c38c6663c9d762e0505ac863
Author:     Jose Carlos Jesus <zecarlos1...@hotmail.com>
AuthorDate: Fri Dec 31 12:27:42 2021 +0000
Commit:     Stanislav Motylkov <x86co...@gmail.com>
CommitDate: Tue Oct 25 23:54:28 2022 +0300

    [ACCESS][MAIN] Fix setting cursor/caret blinking rate
    
    - Save uCaretBlinkTime to CursorBlinkRate registry key
    - Also fix blinking rate never reaching None
    
    CORE-17929
---
 dll/cpl/access/display.c | 52 ++++++++++++++++++++++++++++++++++++++---
 dll/cpl/main/keyboard.c  | 61 +++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 107 insertions(+), 6 deletions(-)

diff --git a/dll/cpl/access/display.c b/dll/cpl/access/display.c
index 843e4a1024e..03e1959b6ea 100644
--- a/dll/cpl/access/display.c
+++ b/dll/cpl/access/display.c
@@ -13,6 +13,31 @@
 
 #define ID_BLINK_TIMER 346
 
+static VOID
+UpdateCaretBlinkTimeReg(
+    _In_ UINT uCaretBlinkTime)
+{
+    HKEY hKey;
+    WCHAR szBuffer[12];
+
+    if (RegOpenKeyExW(HKEY_CURRENT_USER,
+                      L"Control Panel\\Desktop",
+                      0, KEY_SET_VALUE,
+                      &hKey) != ERROR_SUCCESS)
+    {
+         return;
+    }
+
+    wsprintf(szBuffer, L"%d", uCaretBlinkTime);
+
+    RegSetValueExW(hKey, L"CursorBlinkRate",
+                   0, REG_SZ,
+                   (CONST BYTE*)szBuffer,
+                   (wcslen(szBuffer) + 1) * sizeof(WCHAR));
+
+    RegCloseKey(hKey);
+}
+
 static VOID
 FillColorSchemeComboBox(HWND hwnd)
 {
@@ -164,7 +189,16 @@ DisplayPageProc(HWND hwndDlg,
             SendDlgItemMessage(hwndDlg, IDC_CURSOR_WIDTH_TRACK, TBM_SETPOS, 
(WPARAM)TRUE, (LPARAM)(pGlobalData->uCaretWidth - 1));
 
             /* Start the blink timer */
-            SetTimer(hwndDlg, ID_BLINK_TIMER, pGlobalData->uCaretBlinkTime, 
NULL);
+            pGlobalData->uCaretBlinkTime = pGlobalData->uCaretBlinkTime >= 
1200 ? -1 : pGlobalData->uCaretBlinkTime;
+            if ((INT)pGlobalData->uCaretBlinkTime > 0)
+            {
+                SetTimer(hwndDlg, ID_BLINK_TIMER, 
pGlobalData->uCaretBlinkTime, NULL);
+            }
+            else
+            {
+                PostMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
+            }
+
             return TRUE;
 
         case WM_COMMAND:
@@ -196,7 +230,15 @@ DisplayPageProc(HWND hwndDlg,
                     i = SendDlgItemMessage(hwndDlg, IDC_CURSOR_BLINK_TRACK, 
TBM_GETPOS, 0, 0);
                     pGlobalData->uCaretBlinkTime = (12 - (UINT)i) * 100;
                     KillTimer(hwndDlg, ID_BLINK_TIMER);
-                    SetTimer(hwndDlg, ID_BLINK_TIMER, 
pGlobalData->uCaretBlinkTime, NULL);
+                    pGlobalData->uCaretBlinkTime = 
pGlobalData->uCaretBlinkTime >= 1200 ? -1 : pGlobalData->uCaretBlinkTime;
+                    if ((INT)pGlobalData->uCaretBlinkTime > 0)
+                    {
+                        SetTimer(hwndDlg, ID_BLINK_TIMER, 
pGlobalData->uCaretBlinkTime, NULL);
+                    }
+                    else if (pGlobalData->fShowCaret)
+                    {
+                        SendMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
+                    }
                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                     break;
 
@@ -243,7 +285,11 @@ DisplayPageProc(HWND hwndDlg,
             lppsn = (LPPSHNOTIFY)lParam;
             if (lppsn->hdr.code == PSN_APPLY)
             {
-                SetCaretBlinkTime(pGlobalData->uCaretBlinkTime);
+                if (SetCaretBlinkTime(pGlobalData->uCaretBlinkTime))
+                {
+                    UpdateCaretBlinkTimeReg(pGlobalData->uCaretBlinkTime);
+                }
+
                 SystemParametersInfo(SPI_SETCARETWIDTH,
                                      0,
                                      IntToPtr(pGlobalData->uCaretWidth),
diff --git a/dll/cpl/main/keyboard.c b/dll/cpl/main/keyboard.c
index c3f7b1ce69c..59af3bb8cb0 100644
--- a/dll/cpl/main/keyboard.c
+++ b/dll/cpl/main/keyboard.c
@@ -39,6 +39,31 @@ typedef struct _SPEED_DATA
     RECT rcCursor;
 } SPEED_DATA, *PSPEED_DATA;
 
+static VOID
+UpdateCaretBlinkTimeReg(
+    _In_ UINT uCaretBlinkTime)
+{
+    HKEY hKey;
+    WCHAR szBuffer[12];
+
+    if (RegOpenKeyExW(HKEY_CURRENT_USER,
+                      L"Control Panel\\Desktop",
+                      0, KEY_SET_VALUE,
+                      &hKey) != ERROR_SUCCESS)
+    {
+         return;
+    }
+
+    wsprintf(szBuffer, L"%d", uCaretBlinkTime);
+
+    RegSetValueExW(hKey, L"CursorBlinkRate",
+                   0, REG_SZ,
+                   (CONST BYTE*)szBuffer,
+                   (wcslen(szBuffer) + 1) * sizeof(WCHAR));
+
+    RegCloseKey(hKey);
+}
+
 /* Property page dialog callback */
 static INT_PTR CALLBACK
 KeyboardSpeedProc(IN HWND hwndDlg,
@@ -97,7 +122,16 @@ KeyboardSpeedProc(IN HWND hwndDlg,
             SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_SETPOS, 
(WPARAM)TRUE, (LPARAM)(12 - (pSpeedData->uCaretBlinkTime / 100)));
 
             /* Start the blink timer */
-            SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, 
NULL);
+            pSpeedData->uCaretBlinkTime = pSpeedData->uCaretBlinkTime >= 1200 
? -1 : pSpeedData->uCaretBlinkTime;
+            if ((INT)pSpeedData->uCaretBlinkTime > 0)
+            {
+                SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, 
NULL);
+            }
+            else
+            {
+                PostMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
+            }
+
             break;
 
         case WM_HSCROLL:
@@ -172,7 +206,15 @@ KeyboardSpeedProc(IN HWND hwndDlg,
                         case TB_ENDTRACK:
                             pSpeedData->uCaretBlinkTime = (12 - 
(UINT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_GETPOS, 0, 0)) * 
100;
                             KillTimer(hwndDlg, ID_BLINK_TIMER);
-                            SetTimer(hwndDlg, ID_BLINK_TIMER, 
pSpeedData->uCaretBlinkTime, NULL);
+                            pSpeedData->uCaretBlinkTime = 
pSpeedData->uCaretBlinkTime >= 1200 ? -1 : pSpeedData->uCaretBlinkTime;
+                            if ((INT)pSpeedData->uCaretBlinkTime > 0)
+                            {
+                                SetTimer(hwndDlg, ID_BLINK_TIMER, 
pSpeedData->uCaretBlinkTime, NULL);
+                            }
+                            else if (pSpeedData->fShowCursor)
+                            {
+                                SendMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 
0);
+                            }
                             SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
                             PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                             break;
@@ -180,7 +222,15 @@ KeyboardSpeedProc(IN HWND hwndDlg,
                         case TB_THUMBTRACK:
                             pSpeedData->uCaretBlinkTime = (12 - 
(UINT)HIWORD(wParam)) * 100;
                             KillTimer(hwndDlg, ID_BLINK_TIMER);
-                            SetTimer(hwndDlg, ID_BLINK_TIMER, 
pSpeedData->uCaretBlinkTime, NULL);
+                            pSpeedData->uCaretBlinkTime = 
pSpeedData->uCaretBlinkTime >= 1200 ? -1 : pSpeedData->uCaretBlinkTime;
+                            if ((INT)pSpeedData->uCaretBlinkTime > 0)
+                            {
+                                SetTimer(hwndDlg, ID_BLINK_TIMER, 
pSpeedData->uCaretBlinkTime, NULL);
+                            }
+                            else if (pSpeedData->fShowCursor)
+                            {
+                                SendMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 
0);
+                            }
                             SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
                             PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                             break;
@@ -215,6 +265,11 @@ KeyboardSpeedProc(IN HWND hwndDlg,
             {
                 case PSN_APPLY:
                     /* Set the new keyboard settings */
+                    if (pSpeedData->uOrigCaretBlinkTime != 
pSpeedData->uCaretBlinkTime)
+                    {
+                        UpdateCaretBlinkTimeReg(pSpeedData->uCaretBlinkTime);
+                    }
+
                     SystemParametersInfo(SPI_SETKEYBOARDDELAY,
                                          pSpeedData->nKeyboardDelay,
                                          0,

Reply via email to