diff --git a/src/modules/fancyzones/lib/VirtualDesktopUtils.cpp b/src/modules/fancyzones/lib/VirtualDesktopUtils.cpp index 50491529b6..136eaa0d61 100644 --- a/src/modules/fancyzones/lib/VirtualDesktopUtils.cpp +++ b/src/modules/fancyzones/lib/VirtualDesktopUtils.cpp @@ -51,6 +51,23 @@ namespace VirtualDesktopUtils return SUCCEEDED(CLSIDFromString(virtualDesktopId.c_str(), desktopId)); } + bool NewGetCurrentDesktopId(GUID* desktopId) + { + wil::unique_hkey key{}; + if (RegOpenKeyExW(HKEY_CURRENT_USER, NonLocalizable::RegKeyVirtualDesktops, 0, KEY_ALL_ACCESS, &key) == ERROR_SUCCESS) + { + GUID value{}; + DWORD size = sizeof(GUID); + if (RegQueryValueExW(key.get(), NonLocalizable::RegCurrentVirtualDesktop, 0, nullptr, reinterpret_cast(&value), &size) == ERROR_SUCCESS) + { + *desktopId = value; + return true; + } + } + + return false; + } + bool GetDesktopIdFromCurrentSession(GUID* desktopId) { DWORD sessionId; @@ -76,11 +93,19 @@ namespace VirtualDesktopUtils return true; } } + return false; } bool GetCurrentVirtualDesktopId(GUID* desktopId) { + // On newer Windows builds, the current virtual desktop is persisted to + // a totally different reg key. Look there first. + if (NewGetCurrentDesktopId(desktopId)) + { + return true; + } + // Explorer persists current virtual desktop identifier to registry on a per session basis, but only // after first virtual desktop switch happens. If the user hasn't switched virtual desktops in this // session, value in registry will be empty.