[EXPLORER] Notification area icon improvements (#6169)
authorCarl J. Bialorucki <cbialo2@outlook.com>
Sat, 23 Dec 2023 20:21:12 +0000 (13:21 -0700)
committerGitHub <noreply@github.com>
Sat, 23 Dec 2023 20:21:12 +0000 (21:21 +0100)
Automatically adjusts the spacing of the tray icons according to the small
or large taskbar icons setting. Also, a minor bug fix to the clock spacing
when switching between taskbar icon sizes.

CORE-19380

Update the ROS-specific CompactTrayIcons registry value from a binary
yes/no to have three states. The three states are as follows:

  0 (default) - Automatic. When small taskbar icons are used, the
  notification area will use compact tray icon spacing. When large
  taskbar icons are used, the notification area will use larger tray
  icon spacing. While no version of Windows behaves this way, I believe
  this is a smart default choice for ReactOS since users wanting large
  taskbar icons will generally expect larger tray icon spacing, while
  users with small taskbar icons may want more compact spacing.

  1 - Never Compact. Regardless of the taskbar icon size setting, the
  notification area will always use the larger spacing. This follows
  the behavior of Windows 7 and newer versions.

  2 - Always Compact. Regardless of the taskbar icon size setting, the
  notification area will always use the compact spacing. This follows
  the behavior of Windows Vista and older versions.

Fix a clock spacing bug that occurs when changing the taskbar size
before advancing to the next minute. The taskbar clock now adjusts
its spacing when the size of the taskbar changes.

base/shell/explorer/precomp.h
base/shell/explorer/settings.cpp
base/shell/explorer/syspager.cpp
base/shell/explorer/trayclock.cpp

index ecc36ca..8a2dfd0 100644 (file)
@@ -184,6 +184,14 @@ TrayMessageLoop(IN OUT ITrayWindow *Tray);
  * settings.c
  */
 
+enum TrayIconsMode
+{
+    TIM_Default,
+    TIM_NeverCompact,
+    TIM_AlwaysCompact,
+    TIM_Max = TIM_AlwaysCompact
+};
+
 typedef struct _TW_STUCKRECTS2
 {
     DWORD cbSize;
@@ -212,12 +220,24 @@ struct TaskbarSettings
     BOOL bPreferDate;
     BOOL bHideInactiveIcons;
     BOOL bSmallIcons;
-    BOOL bCompactTrayIcons;
+    TrayIconsMode eCompactTrayIcons;
     BOOL bShowDesktopButton;
     TW_STRUCKRECTS2 sr;
 
     BOOL Load();
     BOOL Save();
+    inline BOOL UseCompactTrayIcons()
+    {
+        switch (eCompactTrayIcons)
+        {
+            case TIM_NeverCompact:
+                return FALSE;
+            case TIM_AlwaysCompact:
+                return TRUE;
+            default:
+                return bSmallIcons;
+        }
+    }
 };
 
 extern TaskbarSettings g_TaskbarSettings;
index 62ac29b..f5932ef 100644 (file)
@@ -32,7 +32,6 @@ BOOL TaskbarSettings::Save()
     SHSetValueW(hkExplorer, L"Advanced", L"TaskbarSizeMove", REG_DWORD, &bAllowSizeMove, sizeof(bAllowSizeMove));
     sr.cbSize = sizeof(sr);
     SHSetValueW(hkExplorer, L"Advanced", L"TaskbarSmallIcons", REG_DWORD, &bSmallIcons, sizeof(bSmallIcons));
-    SHSetValueW(hkExplorer, L"Advanced", L"CompactTrayIcons", REG_DWORD, &bCompactTrayIcons, sizeof(bCompactTrayIcons));
     SHSetValueW(hkExplorer, L"Advanced", L"TaskbarSd", REG_DWORD, &bShowDesktopButton, sizeof(bShowDesktopButton));
     SHSetValueW(hkExplorer, L"StuckRects2", L"Settings", REG_BINARY, &sr, sizeof(sr));
 
@@ -64,7 +63,10 @@ BOOL TaskbarSettings::Load()
     bSmallIcons = (dwRet == ERROR_SUCCESS) ? (dwValue != 0) : TRUE;
 
     dwRet = SHGetValueW(hkExplorer, L"Advanced", L"CompactTrayIcons", NULL, &dwValue, &cbSize);
-    bCompactTrayIcons = (dwRet == ERROR_SUCCESS) ? (dwValue != 0) : bSmallIcons;
+    if (dwRet == ERROR_SUCCESS && dwValue <= TIM_Max)
+        eCompactTrayIcons = static_cast<TrayIconsMode>(dwValue);
+    else
+        eCompactTrayIcons = TIM_Default;
 
     dwRet = SHGetValueW(hkExplorer, L"Advanced", L"TaskbarSd", NULL, &dwValue, &cbSize);
     bShowDesktopButton = (dwRet == ERROR_SUCCESS) ? (dwValue != 0) : TRUE;
index b039f18..22063a1 100644 (file)
@@ -165,6 +165,7 @@ public:
     BOOL RemoveButton(IN CONST NOTIFYICONDATA *iconData);
     VOID ResizeImagelist();
     bool SendNotifyCallback(InternalIconData* notifyItem, UINT uMsg);
+    void RefreshToolbarMetrics(BOOL bForceRefresh);
 
 private:
     LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -1250,24 +1251,34 @@ void CNotifyToolbar::Initialize(HWND hWndParent, CBalloonQueue * queue)
     m_ImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 0, 1000);
     SetImageList(m_ImageList);
 
-    TBMETRICS tbm = {sizeof(tbm)};
-    tbm.dwMask = TBMF_BARPAD | TBMF_BUTTONSPACING | TBMF_PAD;
-    tbm.cxPad = 1;
-    tbm.cyPad = 1;
-    if (!g_TaskbarSettings.bCompactTrayIcons)
-    {
-        tbm.cxPad = GetSystemMetrics(SM_CXSMICON) / 2;
-        tbm.cyPad = GetSystemMetrics(SM_CYSMICON) / 2;
-    }
-    tbm.cxBarPad = 1;
-    tbm.cyBarPad = 1;
-    tbm.cxButtonSpacing = 1;
-    tbm.cyButtonSpacing = 1;
-    SetMetrics(&tbm);
+    RefreshToolbarMetrics(TRUE);
 
     SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
 }
 
+void CNotifyToolbar::RefreshToolbarMetrics(BOOL bForceRefresh = FALSE)
+{
+    // Toolbar metrics only needs to be refreshed for the automatic setting and first launch
+    if (g_TaskbarSettings.eCompactTrayIcons == TrayIconsMode::TIM_Default ||
+        bForceRefresh)
+    {
+        TBMETRICS tbm = {sizeof(tbm)};
+        tbm.dwMask = TBMF_BARPAD | TBMF_BUTTONSPACING | TBMF_PAD;
+        tbm.cxPad = 1;
+        tbm.cyPad = 1;
+        if (!g_TaskbarSettings.UseCompactTrayIcons())
+        {
+            tbm.cxPad = GetSystemMetrics(SM_CXSMICON) / 2;
+            tbm.cyPad = GetSystemMetrics(SM_CYSMICON) / 2;
+        }
+        tbm.cxBarPad = 1;
+        tbm.cyBarPad = 1;
+        tbm.cxButtonSpacing = 1;
+        tbm.cyButtonSpacing = 1;
+        SetMetrics(&tbm);
+    }
+}
+
 /*
  * SysPagerWnd
  */
@@ -1404,7 +1415,7 @@ void CSysPagerWnd::GetSize(IN BOOL IsHorizontal, IN PSIZE size)
     INT columns = 0;
     INT cyButton = GetSystemMetrics(SM_CYSMICON) + 2;
     INT cxButton = GetSystemMetrics(SM_CXSMICON) + 2;
-    if (!g_TaskbarSettings.bCompactTrayIcons)
+    if (!g_TaskbarSettings.UseCompactTrayIcons())
     {
         cyButton = MulDiv(GetSystemMetrics(SM_CYSMICON), 3, 2);
         cxButton = MulDiv(GetSystemMetrics(SM_CXSMICON), 3, 2);
@@ -1413,7 +1424,7 @@ void CSysPagerWnd::GetSize(IN BOOL IsHorizontal, IN PSIZE size)
 
     if (IsHorizontal)
     {
-        if (!g_TaskbarSettings.bCompactTrayIcons)
+        if (!g_TaskbarSettings.UseCompactTrayIcons())
             rows = max(size->cy / MulDiv(cyButton, 3, 2), 1);
         else
             rows = max(size->cy / cyButton, 1);
@@ -1522,6 +1533,7 @@ LRESULT CSysPagerWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
         INT yOff = (szClient.cy - szBar.cy) / 2;
 
         Toolbar.SetWindowPos(NULL, xOff, yOff, szBar.cx, szBar.cy, SWP_NOZORDER);
+        Toolbar.RefreshToolbarMetrics();
     }
     return Ret;
 }
index f25c63d..4411d34 100644 (file)
@@ -572,7 +572,7 @@ VOID CTrayClockWnd::PaintLine(IN HDC hDC, IN OUT RECT *rcClient, IN UINT LineNum
         return;
 
     INT HShift = ((IsHorizontal && (VisibleLines <= 1 ||
-                   g_TaskbarSettings.bCompactTrayIcons)) ? 0 : TRAY_CLOCK_WND_SPACING_X);
+                   g_TaskbarSettings.UseCompactTrayIcons())) ? 0 : TRAY_CLOCK_WND_SPACING_X);
 
     TextOut(hDC,
             ((rcClient->right - LineSizes[szLinesIndex].cx) / 2) + HShift,
@@ -684,7 +684,7 @@ LRESULT CTrayClockWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
     VisibleLines = GetMinimumSize(IsHorizontal, &szClient);
     CurrentSize = szClient;
 
-    InvalidateRect(NULL, TRUE);
+    UpdateWnd();
     return TRUE;
 }