1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2020-2021 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /// helper class for the Windows 10 dark mode
24 /// note: we use undocumented APIs here, so be careful!
28 static DarkModeHelper
& Instance();
30 enum class IMMERSIVE_HC_CACHE_MODE
32 IHCM_USE_CACHED_VALUE
,
35 enum class PreferredAppMode
43 enum class WINDOWCOMPOSITIONATTRIB
46 WCA_NCRENDERING_ENABLED
= 1,
47 WCA_NCRENDERING_POLICY
= 2,
48 WCA_TRANSITIONS_FORCEDISABLED
= 3,
49 WCA_ALLOW_NCPAINT
= 4,
50 WCA_CAPTION_BUTTON_BOUNDS
= 5,
51 WCA_NONCLIENT_RTL_LAYOUT
= 6,
52 WCA_FORCE_ICONIC_REPRESENTATION
= 7,
53 WCA_EXTENDED_FRAME_BOUNDS
= 8,
54 WCA_HAS_ICONIC_BITMAP
= 9,
55 WCA_THEME_ATTRIBUTES
= 10,
56 WCA_NCRENDERING_EXILED
= 11,
57 WCA_NCADORNMENTINFO
= 12,
58 WCA_EXCLUDED_FROM_LIVEPREVIEW
= 13,
59 WCA_VIDEO_OVERLAY_ACTIVE
= 14,
60 WCA_FORCE_ACTIVEWINDOW_APPEARANCE
= 15,
61 WCA_DISALLOW_PEEK
= 16,
64 WCA_ACCENT_POLICY
= 19,
65 WCA_FREEZE_REPRESENTATION
= 20,
66 WCA_EVER_UNCLOAKED
= 21,
67 WCA_VISUAL_OWNER
= 22,
69 WCA_EXCLUDED_FROM_DDA
= 24,
70 WCA_PASSIVEUPDATEMODE
= 25,
71 WCA_USEDARKMODECOLORS
= 26,
75 struct WINDOWCOMPOSITIONATTRIBDATA
77 WINDOWCOMPOSITIONATTRIB Attrib
;
82 bool CanHaveDarkMode() const;
83 void AllowDarkModeForApp(BOOL allow
) const;
84 void AllowDarkModeForWindow(HWND hwnd
, BOOL allow
) const;
85 BOOL
ShouldAppsUseDarkMode() const;
86 BOOL
IsDarkModeAllowedForWindow(HWND hwnd
) const;
87 BOOL
IsDarkModeAllowedForApp() const;
88 BOOL
ShouldSystemUseDarkMode() const;
89 void RefreshImmersiveColorPolicyState() const;
90 BOOL
GetIsImmersiveColorUsingHighContrast(IMMERSIVE_HC_CACHE_MODE mode
) const;
91 void FlushMenuThemes() const;
92 BOOL
SetWindowCompositionAttribute(HWND hWnd
, WINDOWCOMPOSITIONATTRIBDATA
* data
) const;
93 void RefreshTitleBarThemeColor(HWND hWnd
, BOOL dark
) const;
99 DarkModeHelper(const DarkModeHelper
& t
) = delete;
100 DarkModeHelper
& operator=(const DarkModeHelper
& t
) = delete;
102 using AllowDarkModeForAppFPN
= void(WINAPI
*)(BOOL allow
);
103 using SetPreferredAppModeFPN
= PreferredAppMode(WINAPI
*)(PreferredAppMode appMode
);
104 using AllowDarkModeForWindowFPN
= void(WINAPI
*)(HWND hwnd
, BOOL allow
);
105 using ShouldAppsUseDarkModeFPN
= BOOL(WINAPI
*)();
106 using IsDarkModeAllowedForWindowFPN
= BOOL(WINAPI
*)(HWND hwnd
);
107 using IsDarkModeAllowedForAppFPN
= BOOL(WINAPI
*)();
108 using ShouldSystemUseDarkModeFPN
= BOOL(WINAPI
*)();
109 using RefreshImmersiveColorPolicyStateFN
= void(WINAPI
*)();
110 using GetIsImmersiveColorUsingHighContrastFN
= BOOL(WINAPI
*)(IMMERSIVE_HC_CACHE_MODE mode
);
111 using FlushMenuThemesFN
= void(WINAPI
*)();
112 using OpenNcThemeDataFPN
= HTHEME(WINAPI
*)(HWND hWnd
, LPCWSTR pszClassList
);
113 using SetWindowCompositionAttributeFPN
= BOOL(WINAPI
*)(HWND hwnd
, WINDOWCOMPOSITIONATTRIBDATA
* data
);
115 AllowDarkModeForAppFPN m_pAllowDarkModeForApp
= nullptr;
116 SetPreferredAppModeFPN m_pSetPreferredAppMode
= nullptr;
117 AllowDarkModeForWindowFPN m_pAllowDarkModeForWindow
= nullptr;
118 ShouldAppsUseDarkModeFPN m_pShouldAppsUseDarkMode
= nullptr;
119 IsDarkModeAllowedForWindowFPN m_pIsDarkModeAllowedForWindow
= nullptr;
120 IsDarkModeAllowedForAppFPN m_pIsDarkModeAllowedForApp
= nullptr;
121 ShouldSystemUseDarkModeFPN m_pShouldSystemUseDarkMode
= nullptr;
122 RefreshImmersiveColorPolicyStateFN m_pRefreshImmersiveColorPolicyState
= nullptr;
123 GetIsImmersiveColorUsingHighContrastFN m_pGetIsImmersiveColorUsingHighContrast
= nullptr;
124 FlushMenuThemesFN m_pFlushMenuThemes
= nullptr;
125 SetWindowCompositionAttributeFPN m_pSetWindowCompositionAttribute
= nullptr;
126 HMODULE m_hUxthemeLib
= nullptr;
127 bool m_bCanHaveDarkMode
= false;