[FancyZones] Update primary desktop data on virtual desktop switch#7994
Conversation
| // First fallback scenario is to try obtaining virtual desktop id through IVirtualDesktopManager | ||
| // interface. Use foreground window (the window with which the user is currently working) to determine | ||
| // current virtual desktop. | ||
| else if (GetWindowDesktopId(GetForegroundWindow(), desktopId)) |
There was a problem hiding this comment.
@enricogior @stefansjfw One possible option, that we should consider is when window is created (FancyZones::WindowCreated callback) we do the check if we still have zeroed GUID, and if that is the case we migrate it based on IVirtualDesktopManager::GetWindowDesktopId and HWND of that newly created window. Creation of new window is something that will happen right as system is started, which means we would migrate primary desktop data quite quickly. Example:
// IFancyZonesCallback
IFACEMETHODIMP_(void)
FancyZones::WindowCreated(HWND window) noexcept
{
auto& fancyZonesData = FancyZonesDataInstance();
if (!fancyZonesData.HasValidPrimaryDesktopId())
{
GUID desktopId{};
if (VirtualDesktopUtils::GetWindowDesktopId(window, &desktopId))
{
fancyZonesData.UpdatePrimaryDesktopData(desktopId);
}
}
...
}
I'm aware that this method is called quite often, however check HasValidPrimaryDesktopId is fairly simple, and code within if statement will be called only once.
|
@vldmr11080 to |
enricogior
left a comment
There was a problem hiding this comment.
Did some testing and the changes work as expected.
Summary of the Pull Request
IVirtualDesktopManager::GetWindowDesktopIdonGetForegroundWindowduring initialization. If PowerToys start right away when system starts,GetForegroundWindowmight not contain valid HWND, and we could end up with zeroed-GUID.PR Checklist
Validation Steps Performed