microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
110.6k stars 6.52k forks source link

[FancyZones] Improve handling of current virtual desktop identifier #2160

Closed vldmr11080 closed 4 years ago

vldmr11080 commented 4 years ago

In order to get current virtual desktop id we are parsing data from registry Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\<session-id>\\VirtualDesktops. When system is first started and only one (virtual) desktop exists there is no virtual desktop id in mentioned registry key (value is empty), so we use GUID 00000000-0000-0000-0000-000000000000.

After creating new virtual desktop, both of them get assigned with valid GUID, and 00000000-0000-0000-0000-000000000000 is never used latter on. Having GUID of primary desktop changing from empty (all zeros) was cause of several issues in the past, and handling it is tricky. Using https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ivirtualdesktopmanager and method GetWindowDesktopId could help us to bypass this problem and have valid GUID for all desktops at any point.

Modify ZoneWindow class to use this API for it's virtual desktop id, and check all other places handling virtual desktop id if it can be simplified. This might be good opportunity to replace unique identifier (Format: <device-id>_<resolution>_<virtual-desktop-id>) and instead of string use object.

enricogior commented 4 years ago

This is an important fix because it solves one of the most annoying problem we had in FZ with regard to Virtual Desktops.