Revert "[Light Switch] Switch desktop wallpapers with the Light/Dark mode" (#44588)

This uses IVirtualDesktopManagerInternal*, which is an undocumented
Windows Shell internal API.
These interfaces are not stable and can change across Windows updates,
so using them in PowerToys carries some long-term risk
This commit is contained in:
Kai Tao
2026-01-08 10:14:43 +08:00
committed by GitHub
parent 08d4689ec5
commit 9c58574484
25 changed files with 310 additions and 1118 deletions

View File

@@ -24,7 +24,7 @@ static LightSwitchStateManager* g_stateManagerPtr = nullptr;
VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl);
DWORD WINAPI ServiceWorkerThread(LPVOID lpParam);
void ApplyTheme(bool shouldBeLight, bool changeWallpaper);
void ApplyTheme(bool shouldBeLight);
// Entry point for the executable
int _tmain(int argc, TCHAR* argv[])
@@ -125,29 +125,9 @@ VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl)
}
}
void SetWallpaper(bool shouldBeLight)
{
const auto& settings = LightSwitchSettings::settings();
if (settings.wallpaperEnabled)
{
std::wstring const& wallpaperPath = shouldBeLight ? settings.wallpaperPathLight : settings.wallpaperPathDark;
auto style = shouldBeLight ? settings.wallpaperStyleLight : settings.wallpaperStyleDark;
if (auto e = SetDesktopWallpaper(wallpaperPath, style, settings.wallpaperVirtualDesktop) == 0)
{
Logger::info(L"[LightSwitchService] Wallpaper is changed to {}.", wallpaperPath);
}
else
{
Logger::error(L"[LightSwitchService] Failed to set wallpaper, error: {}.", e);
}
}
};
void ApplyTheme(bool shouldBeLight, bool changeWallpaper)
void ApplyTheme(bool shouldBeLight)
{
const auto& s = LightSwitchSettings::settings();
bool somethingChanged = false;
if (s.changeSystem)
{
@@ -156,7 +136,6 @@ void ApplyTheme(bool shouldBeLight, bool changeWallpaper)
{
SetSystemTheme(shouldBeLight);
Logger::info(L"[LightSwitchService] Changed system theme to {}.", shouldBeLight ? L"light" : L"dark");
somethingChanged = true;
}
}
@@ -167,15 +146,6 @@ void ApplyTheme(bool shouldBeLight, bool changeWallpaper)
{
SetAppsTheme(shouldBeLight);
Logger::info(L"[LightSwitchService] Changed apps theme to {}.", shouldBeLight ? L"light" : L"dark");
somethingChanged = true;
}
}
if (somethingChanged)
{
if (changeWallpaper)
{
SetWallpaper(shouldBeLight);
}
}
}
@@ -205,7 +175,7 @@ static void DetectAndHandleExternalThemeChange(LightSwitchStateManager& stateMan
if (s.scheduleMode == ScheduleMode::FollowNightLight)
{
shouldBeLight = !IsNightLightEnabled();
}
}
else
{
shouldBeLight = ShouldBeLight(nowMinutes, effectiveLight, effectiveDark);