Skip to content

Commit

Permalink
BODGY fix for newer builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Apr 28, 2021
1 parent 84c1bd9 commit 24bfbe6
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/cascadia/WindowsTerminal/VirtualDesktopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// Shamelessly copied from microsoft/PowerToys, at
// https://github.com/microsoft/PowerToys/blob/master/src/modules/fancyzones/lib/VirtualDesktopUtils.cpp
//
// The code style is left untouched, as to make contributions from/to the
// upstream source easier.
// The code style is left (relatively) untouched, as to make contributions
// from/to the upstream source easier. `NewGetCurrentDesktopId` was added in
// April 2021.

#include "pch.h"

Expand All @@ -22,6 +23,25 @@ namespace NonLocalizable

namespace VirtualDesktopUtils
{
// Look for the guid stored as the value `CurrentVirtualDesktop` under the
// key
// `HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops`
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<BYTE*>(&value), &size) == ERROR_SUCCESS)
{
*desktopId = value;
return true;
}
}
return false;
}

bool GetDesktopIdFromCurrentSession(GUID* desktopId)
{
DWORD sessionId;
Expand Down Expand Up @@ -120,6 +140,14 @@ namespace VirtualDesktopUtils

bool GetCurrentVirtualDesktopId(GUID* desktopId)
{
// BODGY
// 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.
Expand Down

1 comment on commit 24bfbe6

@github-actions

This comment was marked as resolved.

Please sign in to comment.