Merged PR 4271163: [Git2Git] Remove use of private theme APIs
References MSFT:24418178
This commit is contained in:
parent
eb480b6bbb
commit
bc7eb96110
|
@ -32,6 +32,8 @@ namespace Microsoft::Console::Internal
|
|||
|
||||
[[nodiscard]] HRESULT CheckIntegrityLevelPolicy(const HANDLE hOtherToken,
|
||||
bool& fIsWrongWayBlocked) noexcept;
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace EdpPolicy
|
||||
|
@ -39,4 +41,8 @@ namespace Microsoft::Console::Internal
|
|||
void AuditClipboard(const std::wstring_view destinationName) noexcept;
|
||||
}
|
||||
|
||||
namespace Theming
|
||||
{
|
||||
[[nodiscard]] HRESULT TrySetDarkMode(HWND hwnd) noexcept;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
<ClCompile Include="..\WindowIo.cpp" />
|
||||
<ClCompile Include="..\WindowMetrics.cpp" />
|
||||
<ClCompile Include="..\WindowProc.cpp" />
|
||||
<ClCompile Include="..\windowtheme.cpp" />
|
||||
<ClCompile Include="..\windowUiaProvider.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -59,7 +58,6 @@
|
|||
<ClInclude Include="..\WindowIme.hpp" />
|
||||
<ClInclude Include="..\WindowMetrics.hpp" />
|
||||
<ClInclude Include="..\WindowIo.hpp" />
|
||||
<ClInclude Include="..\windowtheme.hpp" />
|
||||
<ClInclude Include="..\windowUiaProvider.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup>
|
||||
|
|
|
@ -66,9 +66,6 @@
|
|||
<ClCompile Include="..\InputServices.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\windowtheme.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\windowUiaProvider.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -131,9 +128,6 @@
|
|||
<ClInclude Include="..\InputServices.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\windowtheme.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\windowUiaProvider.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -56,7 +56,6 @@ SOURCES = \
|
|||
..\windowio.cpp \
|
||||
..\WindowMetrics.cpp \
|
||||
..\windowproc.cpp \
|
||||
..\windowtheme.cpp \
|
||||
..\windowUiaProvider.cpp \
|
||||
|
||||
INCLUDES = \
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include "windowio.hpp"
|
||||
#include "windowdpiapi.hpp"
|
||||
#include "windowmetrics.hpp"
|
||||
#include "windowtheme.hpp"
|
||||
|
||||
#include "..\..\inc\conint.h"
|
||||
|
||||
#include "..\..\host\globals.h"
|
||||
#include "..\..\host\dbcs.h"
|
||||
|
@ -349,12 +350,7 @@ void Window::_UpdateSystemMetrics() const
|
|||
siAttached.PostUpdateWindowSize();
|
||||
|
||||
// Locate window theming modules and try to set the dark mode.
|
||||
try
|
||||
{
|
||||
WindowTheme theme;
|
||||
LOG_IF_FAILED(theme.TrySetDarkMode(_hWnd));
|
||||
}
|
||||
CATCH_LOG();
|
||||
LOG_IF_FAILED(Microsoft::Console::Internal::Theming::TrySetDarkMode(_hWnd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
#include "..\inc\ServiceLocator.hpp"
|
||||
|
||||
#include "..\interactivity\win32\windowtheme.hpp"
|
||||
#include "..\..\inc\conint.h"
|
||||
|
||||
#include "..\interactivity\win32\CustomWindowMessages.h"
|
||||
|
||||
#include "..\interactivity\win32\windowUiaProvider.hpp"
|
||||
|
@ -336,13 +337,7 @@ using namespace Microsoft::Console::Types;
|
|||
|
||||
case WM_SETTINGCHANGE:
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowTheme theme;
|
||||
LOG_IF_FAILED(theme.TrySetDarkMode(hWnd));
|
||||
}
|
||||
CATCH_LOG();
|
||||
|
||||
LOG_IF_FAILED(Microsoft::Console::Internal::Theming::TrySetDarkMode(hWnd));
|
||||
gci.GetCursorBlinker().SettingsChanged();
|
||||
}
|
||||
__fallthrough;
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
#include "windowtheme.hpp"
|
||||
|
||||
#include <dwmapi.h>
|
||||
|
||||
#ifdef __INSIDE_WINDOWS
|
||||
#include <dwmapip.h>
|
||||
#endif
|
||||
|
||||
using namespace Microsoft::Console::Interactivity::Win32;
|
||||
|
||||
#define DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 19
|
||||
|
||||
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
|
||||
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
|
||||
#endif
|
||||
|
||||
#define DARK_MODE_STRING_NAME L"DarkMode_Explorer"
|
||||
#define UXTHEME_DLL_NAME L"uxtheme.dll"
|
||||
#define UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL 132
|
||||
|
||||
// Routine Description:
|
||||
// - Constructs window theme class (holding module references for function lookups)
|
||||
WindowTheme::WindowTheme()
|
||||
{
|
||||
// NOTE: Use LoadLibraryExW with LOAD_LIBRARY_SEARCH_SYSTEM32 flag below to avoid unneeded directory traversal.
|
||||
// This has triggered CPG boot IO warnings in the past.
|
||||
_module.reset(LoadLibraryExW(UXTHEME_DLL_NAME, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32));
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - Attempts to set the dark mode on the given HWND.
|
||||
// - Will check the system for user preferences and high contrast to see if it's a good idea
|
||||
// before setting it.
|
||||
// Arguments:
|
||||
// - hwnd - Window to apply dark mode to
|
||||
// Return Value:
|
||||
// - S_OK or suitable HRESULT from theming or DWM engines.
|
||||
[[nodiscard]] HRESULT WindowTheme::TrySetDarkMode(HWND hwnd) const noexcept
|
||||
{
|
||||
// I have to be a big B BOOL or DwnSetWindowAttribute will be upset (E_INVALIDARG) when I am passed in.
|
||||
const BOOL isDarkMode = !!_IsDarkMode();
|
||||
|
||||
if (isDarkMode)
|
||||
{
|
||||
RETURN_IF_FAILED(SetWindowTheme(hwnd, DARK_MODE_STRING_NAME, nullptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
RETURN_IF_FAILED(SetWindowTheme(hwnd, L"", nullptr));
|
||||
}
|
||||
|
||||
if (FAILED(DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &isDarkMode, sizeof(isDarkMode))))
|
||||
{
|
||||
RETURN_IF_FAILED(DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &isDarkMode, sizeof(isDarkMode)));
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - Logical determination of if we should use the dark mode or not.
|
||||
// - Combines user preferences and high contrast accessibility settings.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - TRUE if dark mode is allowed. FALSE if it is not.
|
||||
bool WindowTheme::_IsDarkMode() const noexcept
|
||||
{
|
||||
if (_ShouldAppsUseDarkMode() && !_IsHighContrast())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - Looks up the high contrast state of the system.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - True if the system is in high contrast (shouldn't change theme further.) False otherwise.
|
||||
bool WindowTheme::_IsHighContrast() const noexcept
|
||||
{
|
||||
BOOL fHighContrast = FALSE;
|
||||
HIGHCONTRAST hc = { sizeof(hc) };
|
||||
if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0))
|
||||
{
|
||||
fHighContrast = (HCF_HIGHCONTRASTON & hc.dwFlags);
|
||||
}
|
||||
return fHighContrast;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - Looks up the user preference for dark mode.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - True if the user chose dark mode in settings. False otherwise.
|
||||
bool WindowTheme::_ShouldAppsUseDarkMode() const noexcept
|
||||
{
|
||||
if (_module.get() != nullptr)
|
||||
{
|
||||
typedef bool(WINAPI * PfnShouldAppsUseDarkMode)();
|
||||
|
||||
static bool tried = false;
|
||||
static PfnShouldAppsUseDarkMode pfn = nullptr;
|
||||
|
||||
if (!tried)
|
||||
{
|
||||
pfn = (PfnShouldAppsUseDarkMode)GetProcAddress(_module.get(), MAKEINTRESOURCEA(UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL));
|
||||
}
|
||||
|
||||
tried = true;
|
||||
|
||||
if (pfn != nullptr)
|
||||
{
|
||||
return pfn();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) Microsoft Corporation
|
||||
Licensed under the MIT license.
|
||||
|
||||
Module Name:
|
||||
- windowtheme.hpp
|
||||
|
||||
Abstract:
|
||||
- This module is used for abstracting calls to set window themes.
|
||||
|
||||
Author(s):
|
||||
- Michael Niksa (MiNiksa) Oct-2018
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
namespace Microsoft::Console::Interactivity::Win32
|
||||
{
|
||||
class WindowTheme final
|
||||
{
|
||||
public:
|
||||
WindowTheme();
|
||||
|
||||
[[nodiscard]] HRESULT TrySetDarkMode(HWND hwnd) const noexcept;
|
||||
|
||||
private:
|
||||
bool _IsDarkMode() const noexcept;
|
||||
|
||||
bool _IsHighContrast() const noexcept;
|
||||
bool _ShouldAppsUseDarkMode() const noexcept;
|
||||
|
||||
wil::unique_hmodule _module;
|
||||
};
|
||||
}
|
|
@ -24,3 +24,8 @@ using namespace Microsoft::Console::Internal;
|
|||
void EdpPolicy::AuditClipboard(const std::wstring_view /*destinationName*/) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] HRESULT Theming::TrySetDarkMode(HWND /*hwnd*/) noexcept
|
||||
{
|
||||
return S_FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue