mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Immersive dark mode + Theme Listener (#18315)
* C++ impl of immersive dark mode * Stop using the hardcoded value. * Conjured up theme listener based on registry. * Update MainWindow.xaml.cpp * Update expect.txt * Moved themehelpers to the common themes lib. * Ported theme helpers back to .NET * Update expect.txt * Updated C# Theme Listening logic to mimic the one from Windows Community Toolkit. * Replaced unmanaged code for RegisterForImmersiveDarkMode with unmanaged ThemeListener class. * Fix upstream changes * Update ThemeListener.h * Update ThemeListener.h * Proper formatting * Added handler to Keyboard Manager. * Update EditKeyboardWindow.cpp * Added dwmapi.lib to runner, removed condition from additional dependencies. * Update PowerRenameUI.vcxproj * Added new deps for ManagedCommon to Product.wxs * Crude attempts and understanding installer * Removed Microsoft.Win32.Registry.dll from product.wxs. * Updated dictionary * Renamed ThemeListener class file for consistency, removed unused CheckImmersiveDarkMode in theme_helpers. * Update Themes.vcxproj * Update theme_listener.cpp * Removed SupportsImmersiveDarkMode version check * Removed SupportsImmersiveDarkMode version check * Whoops * Update expect.txt
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "microsoft.ui.xaml.window.h"
|
||||
#include <winrt/Microsoft.UI.Interop.h>
|
||||
#include <winrt/Microsoft.UI.Windowing.h>
|
||||
#include <common/Themes/theme_helpers.h>
|
||||
#include <common/Themes/theme_listener.h>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace Windows::UI::Xaml;
|
||||
@@ -35,15 +37,31 @@ HINSTANCE g_hostHInst;
|
||||
|
||||
extern std::vector<std::wstring> g_files;
|
||||
|
||||
// Theming
|
||||
ThemeListener theme_listener{};
|
||||
HWND CurrentWindow;
|
||||
|
||||
void handleTheme() {
|
||||
auto theme = theme_listener.AppTheme;
|
||||
auto isDark = theme == AppTheme::Dark;
|
||||
Logger::info(L"Theme is now {}", isDark ? L"Dark" : L"Light");
|
||||
ThemeHelpers::SetImmersiveDarkMode(CurrentWindow, isDark);
|
||||
}
|
||||
|
||||
namespace winrt::PowerRenameUI::implementation
|
||||
{
|
||||
MainWindow::MainWindow() :
|
||||
m_instance{ nullptr }, m_allSelected{ true }, m_managerEvents{ this }
|
||||
{
|
||||
|
||||
auto windowNative{ this->try_as<::IWindowNative>() };
|
||||
winrt::check_bool(windowNative);
|
||||
windowNative->get_WindowHandle(&m_window);
|
||||
CurrentWindow = m_window;
|
||||
|
||||
// Attach theme handling
|
||||
theme_listener.AddChangedHandler(handleTheme);
|
||||
handleTheme();
|
||||
|
||||
Microsoft::UI::WindowId windowId =
|
||||
Microsoft::UI::GetWindowIdFromWindow(m_window);
|
||||
|
||||
@@ -69,7 +87,6 @@ namespace winrt::PowerRenameUI::implementation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Microsoft::UI::Windowing::AppWindow appWindow =
|
||||
Microsoft::UI::Windowing::AppWindow::GetFromWindowId(windowId);
|
||||
appWindow.SetIcon(PowerRenameUIIco);
|
||||
|
||||
Reference in New Issue
Block a user