From bdedc02ea5af186565150f76089c521b61ce04e4 Mon Sep 17 00:00:00 2001 From: Leonardo Farias Bona Date: Tue, 17 Jun 2025 00:49:31 -0300 Subject: [PATCH] [CropAndLock] theme (#38044) ## Summary of the Pull Request Theme aware cropped windows. ## PR Checklist - [x] **Closes:** #28348 - [ ] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments Added a Theme aware implementation that was already found on other components, the only difference is that we are dealing with multiple windows. It will follow the Power Toys application theme, (windows too in case PowerToys follows the System). I decided to change the scope of a variable to not create a second control of croppedWindows, this may need to be taken into consideration. ## Validation Steps Performed Using Crop (Win + Ctrl + Shift +R) Crop one or multiple windows. All of them have the same theme as the application. Went to windows theme settings, change to light theme, the app changes accordingly. Same behavior was tested with Thumbnail (Win + Ctrl + Shift + T) Closing windows and changing the theme again. --- .../CropAndLock/CropAndLock.vcxproj | 3 +++ src/modules/CropAndLock/CropAndLock/main.cpp | 25 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/CropAndLock/CropAndLock/CropAndLock.vcxproj b/src/modules/CropAndLock/CropAndLock/CropAndLock.vcxproj index f3ce71829f..859bbc3116 100644 --- a/src/modules/CropAndLock/CropAndLock/CropAndLock.vcxproj +++ b/src/modules/CropAndLock/CropAndLock/CropAndLock.vcxproj @@ -154,6 +154,9 @@ {8f021b46-362b-485c-bfba-ccf83e820cbd} + + {98537082-0fdb-40de-abd8-0dc5a4269bab} + diff --git a/src/modules/CropAndLock/CropAndLock/main.cpp b/src/modules/CropAndLock/CropAndLock/main.cpp index 79d26fc8c1..5aeea262a4 100644 --- a/src/modules/CropAndLock/CropAndLock/main.cpp +++ b/src/modules/CropAndLock/CropAndLock/main.cpp @@ -17,6 +17,9 @@ #include +#include +#include + #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") namespace winrt @@ -35,6 +38,23 @@ namespace util const std::wstring instanceMutexName = L"Local\\PowerToys_CropAndLock_InstanceMutex"; bool m_running = true; +// Theming +ThemeListener theme_listener{}; +// Keep a list of our cropped windows +std::vector> croppedWindows; + +void handleTheme() +{ + auto theme = theme_listener.AppTheme; + auto isDark = theme == Theme::Dark; + Logger::info(L"Theme is now {}", isDark ? L"Dark" : L"Light"); + for (auto&& croppedWindow : croppedWindows) + { + ThemeHelpers::SetImmersiveDarkMode(croppedWindow->Handle(), isDark); + } +} + + int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _In_ int) { // Initialize COM @@ -42,6 +62,8 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I Trace::CropAndLock::RegisterProvider(); + theme_listener.AddChangedHandler(handleTheme); + Shared::Trace::ETWTrace trace; trace.UpdateState(true); @@ -107,8 +129,6 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I // Create our overlay window std::unique_ptr overlayWindow; - // Keep a list of our cropped windows - std::vector> croppedWindows; // Handles and thread for the events sent from runner HANDLE m_reparent_event_handle; @@ -167,6 +187,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I croppedWindow->CropAndLock(targetWindow, cropRect); croppedWindow->OnClosed(removeWindowCallback); croppedWindows.push_back(croppedWindow); + handleTheme(); }; overlayWindow.reset();