From 78a94aecb965a7c10ded273a1227da3e2259b341 Mon Sep 17 00:00:00 2001 From: Seraphima Zykova Date: Mon, 23 Oct 2023 16:13:24 +0200 Subject: [PATCH 01/20] [FancyZones]Fix moving windows on other virtual desktops (#29059) * clean up obsolete vd check * clean up * replace virtual desktop id usage * check current vd --- .../fancyzones/FancyZonesLib/FancyZones.cpp | 35 +++--- .../FancyZonesData/AppZoneHistory.cpp | 27 +--- .../FancyZonesLib/VirtualDesktop.cpp | 115 +----------------- .../fancyzones/FancyZonesLib/VirtualDesktop.h | 14 +-- 4 files changed, 25 insertions(+), 166 deletions(-) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index 4524f90842..960f797f72 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -156,9 +156,9 @@ private: void SyncVirtualDesktops() noexcept; void UpdateHotkey(int hotkeyId, const PowerToysSettings::HotkeyObject& hotkeyObject, bool enable) noexcept; - - bool MoveToAppLastZone(HWND window, HMONITOR monitor) noexcept; + bool MoveToAppLastZone(HWND window, HMONITOR monitor, GUID currentVirtualDesktop) noexcept; + void RefreshLayouts() noexcept; bool ShouldProcessSnapHotkey(DWORD vkCode) noexcept; void ApplyQuickLayout(int key) noexcept; @@ -257,7 +257,6 @@ FancyZones::Run() noexcept } }); - VirtualDesktop::instance().UpdateVirtualDesktopId(); SyncVirtualDesktops(); // id format of applied-layouts and app-zone-history was changed in 0.60 @@ -332,7 +331,7 @@ void FancyZones::MoveSizeEnd() } } -bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR monitor) noexcept +bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR monitor, GUID currentVirtualDesktop) noexcept { const auto& workAreas = m_workAreaConfiguration.GetAllWorkAreas(); WorkArea* workArea{ nullptr }; @@ -343,7 +342,7 @@ bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR monitor) noexcept if (workAreas.contains(monitor)) { workArea = workAreas.at(monitor).get(); - if (workArea) + if (workArea && workArea->UniqueId().virtualDesktopId == currentVirtualDesktop) { indexes = AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workArea->UniqueId(), workArea->GetLayoutId()); } @@ -357,7 +356,7 @@ bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR monitor) noexcept { for (const auto& [_, secondaryWorkArea] : workAreas) { - if (secondaryWorkArea) + if (secondaryWorkArea && secondaryWorkArea->UniqueId().virtualDesktopId == currentVirtualDesktop) { indexes = AppZoneHistory::instance().GetAppLastZoneIndexSet(window, secondaryWorkArea->UniqueId(), secondaryWorkArea->GetLayoutId()); workArea = secondaryWorkArea.get(); @@ -412,27 +411,28 @@ void FancyZones::WindowCreated(HWND window) noexcept } bool windowMovedToZone = false; + auto currentVirtualDesktop = VirtualDesktop::instance().GetCurrentVirtualDesktopIdFromRegistry(); if (moveToAppLastZone) { if (FancyZonesSettings::settings().spanZonesAcrossMonitors) { - windowMovedToZone = MoveToAppLastZone(window, nullptr); + windowMovedToZone = MoveToAppLastZone(window, nullptr, currentVirtualDesktop); } else { // Search application history on currently active monitor. - windowMovedToZone = MoveToAppLastZone(window, active); + windowMovedToZone = MoveToAppLastZone(window, active, currentVirtualDesktop); if (!windowMovedToZone && primary != active) { // Search application history on primary monitor. - windowMovedToZone = MoveToAppLastZone(window, primary); + windowMovedToZone = MoveToAppLastZone(window, primary, currentVirtualDesktop); } if (!windowMovedToZone) { // Search application history on remaining monitors. - windowMovedToZone = MoveToAppLastZone(window, nullptr); + windowMovedToZone = MoveToAppLastZone(window, nullptr, currentVirtualDesktop); } } } @@ -641,12 +641,10 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa } else if (message == WM_PRIV_INIT) { - VirtualDesktop::instance().UpdateVirtualDesktopId(); OnDisplayChange(DisplayChangeType::Initialization); } else if (message == WM_PRIV_VD_SWITCH) { - VirtualDesktop::instance().UpdateVirtualDesktopId(); OnDisplayChange(DisplayChangeType::VirtualDesktop); } else if (message == WM_PRIV_EDITOR) @@ -745,10 +743,10 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept bool FancyZones::AddWorkArea(HMONITOR monitor, const FancyZonesDataTypes::WorkAreaId& id) noexcept { - wil::unique_cotaskmem_string virtualDesktopIdStr; - if (!SUCCEEDED(StringFromCLSID(VirtualDesktop::instance().GetCurrentVirtualDesktopId(), &virtualDesktopIdStr))) + auto virtualDesktopIdStr = FancyZonesUtils::GuidToString(id.virtualDesktopId); + if (virtualDesktopIdStr) { - Logger::debug(L"Add new work area on virtual desktop {}", virtualDesktopIdStr.get()); + Logger::debug(L"Add new work area on virtual desktop {}", virtualDesktopIdStr.value()); } FancyZonesUtils::Rect rect{}; @@ -794,11 +792,12 @@ void FancyZones::UpdateWorkAreas(bool updateWindowPositions) noexcept Logger::debug(L"Update work areas, update windows positions: {}", updateWindowPositions); m_workAreaConfiguration.Clear(); + auto currentVirtualDesktop = VirtualDesktop::instance().GetCurrentVirtualDesktopIdFromRegistry(); if (FancyZonesSettings::settings().spanZonesAcrossMonitors) { FancyZonesDataTypes::WorkAreaId workAreaId; - workAreaId.virtualDesktopId = VirtualDesktop::instance().GetCurrentVirtualDesktopId(); + workAreaId.virtualDesktopId = currentVirtualDesktop; workAreaId.monitorId = { .deviceId = { .id = ZonedWindowProperties::MultiMonitorName, .instanceId = ZonedWindowProperties::MultiMonitorInstance } }; AddWorkArea(nullptr, workAreaId); @@ -809,7 +808,7 @@ void FancyZones::UpdateWorkAreas(bool updateWindowPositions) noexcept for (const auto& monitor : monitors) { FancyZonesDataTypes::WorkAreaId workAreaId; - workAreaId.virtualDesktopId = VirtualDesktop::instance().GetCurrentVirtualDesktopId(); + workAreaId.virtualDesktopId = currentVirtualDesktop; workAreaId.monitorId = monitor; AddWorkArea(monitor.monitor, workAreaId); @@ -906,7 +905,7 @@ void FancyZones::SyncVirtualDesktops() noexcept // that case (00000000-0000-0000-0000-000000000000). auto lastUsed = LastUsedVirtualDesktop::instance().GetId(); - auto current = VirtualDesktop::instance().GetCurrentVirtualDesktopId(); + auto current = VirtualDesktop::instance().GetCurrentVirtualDesktopIdFromRegistry(); auto guids = VirtualDesktop::instance().GetVirtualDesktopIdsFromRegistry(); if (current != lastUsed) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp index c633f0c0f7..98c0c92eaa 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp @@ -278,32 +278,7 @@ void AppZoneHistory::LoadData() void AppZoneHistory::SaveData() { - bool dirtyFlag = false; - std::unordered_map> updatedHistory; - - for (const auto& [path, dataVector] : m_history) - { - auto updatedVector = dataVector; - for (auto& data : updatedVector) - { - if (!VirtualDesktop::instance().IsVirtualDesktopIdSavedInRegistry(data.workAreaId.virtualDesktopId)) - { - data.workAreaId.virtualDesktopId = GUID_NULL; - dirtyFlag = true; - } - } - - updatedHistory.insert(std::make_pair(path, updatedVector)); - } - - if (dirtyFlag) - { - json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(updatedHistory)); - } - else - { - json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(m_history)); - } + json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(m_history)); } void AppZoneHistory::AdjustWorkAreaIds(const std::vector& ids) diff --git a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp index dbd1511d5a..06ca30719e 100644 --- a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp +++ b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp @@ -96,14 +96,14 @@ VirtualDesktop& VirtualDesktop::instance() return self; } -std::optional VirtualDesktop::GetCurrentVirtualDesktopIdFromRegistry() const +GUID VirtualDesktop::GetCurrentVirtualDesktopIdFromRegistry() const { // On newer Windows builds, the current virtual desktop is persisted to // a totally different reg key. Look there first. std::optional desktopId = NewGetCurrentDesktopId(); if (desktopId.has_value()) { - return desktopId; + return desktopId.value(); } // Explorer persists current virtual desktop identifier to registry on a per session basis, but only @@ -112,7 +112,7 @@ std::optional VirtualDesktop::GetCurrentVirtualDesktopIdFromRegistry() con desktopId = GetDesktopIdFromCurrentSession(); if (desktopId.has_value()) { - return desktopId; + return desktopId.value(); } // Fallback scenario is to get array of virtual desktops stored in registry, but not kept per session. @@ -128,7 +128,7 @@ std::optional VirtualDesktop::GetCurrentVirtualDesktopIdFromRegistry() con } } - return std::nullopt; + return GUID_NULL; } std::optional> VirtualDesktop::GetVirtualDesktopIdsFromRegistry(HKEY hKey) const @@ -169,25 +169,6 @@ std::optional> VirtualDesktop::GetVirtualDesktopIdsFromRegistr return GetVirtualDesktopIdsFromRegistry(GetVirtualDesktopsRegKey()); } -bool VirtualDesktop::IsVirtualDesktopIdSavedInRegistry(GUID id) const -{ - auto ids = GetVirtualDesktopIdsFromRegistry(); - if (!ids.has_value()) - { - return false; - } - - for (const auto& regId : *ids) - { - if (regId == id) - { - return true; - } - } - - return false; -} - bool VirtualDesktop::IsWindowOnCurrentDesktop(HWND window) const { BOOL isWindowOnCurrentDesktop = false; @@ -199,47 +180,6 @@ bool VirtualDesktop::IsWindowOnCurrentDesktop(HWND window) const return isWindowOnCurrentDesktop; } -std::optional VirtualDesktop::GetDesktopId(HWND window) const -{ - GUID id; - BOOL isWindowOnCurrentDesktop = false; - if (m_vdManager && m_vdManager->IsWindowOnCurrentVirtualDesktop(window, &isWindowOnCurrentDesktop) == S_OK && isWindowOnCurrentDesktop) - { - // Filter windows such as Windows Start Menu, Task Switcher, etc. - if (m_vdManager->GetWindowDesktopId(window, &id) == S_OK) - { - return id; - } - } - - return std::nullopt; -} - -std::vector> VirtualDesktop::GetWindowsRelatedToDesktops() const -{ - using result_t = std::vector; - result_t windows; - - auto callback = [](HWND window, LPARAM data) -> BOOL { - result_t& result = *reinterpret_cast(data); - result.push_back(window); - return TRUE; - }; - EnumWindows(callback, reinterpret_cast(&windows)); - - std::vector> result; - for (auto window : windows) - { - auto desktop = GetDesktopId(window); - if (desktop.has_value()) - { - result.push_back({ window, *desktop }); - } - } - - return result; -} - std::vector VirtualDesktop::GetWindowsFromCurrentDesktop() const { using result_t = std::vector; @@ -263,49 +203,4 @@ std::vector VirtualDesktop::GetWindowsFromCurrentDesktop() const } return result; -} - -GUID VirtualDesktop::GetCurrentVirtualDesktopId() const noexcept -{ - return m_currentVirtualDesktopId; -} - -void VirtualDesktop::UpdateVirtualDesktopId() noexcept -{ - auto currentVirtualDesktopId = GetCurrentVirtualDesktopIdFromRegistry(); - if (currentVirtualDesktopId.has_value()) - { - m_currentVirtualDesktopId = currentVirtualDesktopId.value(); - } - else - { - m_currentVirtualDesktopId = GUID_NULL; - } - - Trace::VirtualDesktopChanged(); -} - -std::optional VirtualDesktop::GetDesktopIdByTopLevelWindows() const -{ - using result_t = std::vector; - result_t windows; - - auto callback = [](HWND window, LPARAM data) -> BOOL { - result_t& result = *reinterpret_cast(data); - result.push_back(window); - return TRUE; - }; - EnumWindows(callback, reinterpret_cast(&windows)); - - for (const auto window : windows) - { - std::optional id = GetDesktopId(window); - if (id.has_value()) - { - // Otherwise keep checking other windows - return *id; - } - } - - return std::nullopt; -} +} \ No newline at end of file diff --git a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h index 4c25518ce8..338e801d38 100644 --- a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h +++ b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h @@ -5,29 +5,19 @@ class VirtualDesktop public: static VirtualDesktop& instance(); - // saved values - GUID GetCurrentVirtualDesktopId() const noexcept; - void UpdateVirtualDesktopId() noexcept; - // IVirtualDesktopManager bool IsWindowOnCurrentDesktop(HWND window) const; - std::optional GetDesktopId(HWND window) const; - std::optional GetDesktopIdByTopLevelWindows() const; - std::vector> GetWindowsRelatedToDesktops() const; std::vector GetWindowsFromCurrentDesktop() const; // registry - std::optional GetCurrentVirtualDesktopIdFromRegistry() const; + GUID GetCurrentVirtualDesktopIdFromRegistry() const; std::optional> GetVirtualDesktopIdsFromRegistry() const; - bool IsVirtualDesktopIdSavedInRegistry(GUID id) const; - + private: VirtualDesktop(); ~VirtualDesktop(); IVirtualDesktopManager* m_vdManager{nullptr}; - GUID m_currentVirtualDesktopId{}; - std::optional> GetVirtualDesktopIdsFromRegistry(HKEY hKey) const; }; From ec4033b778f5ad5d29baa38a4ec3b67c34fc78d4 Mon Sep 17 00:00:00 2001 From: Laszlo Nemeth <57342539+donlaci@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:14:17 +0200 Subject: [PATCH 02/20] [Settings]Fixes in Dashboard based on review comments (#29370) * Fixes in Dashboard based on review comments. * Text corrections --- .../NegativeBoolToVisibilityConverter.cs | 37 ------------------- .../Settings.UI/PowerToys.Settings.csproj | 9 ----- .../Settings.UI/Strings/en-us/Resources.resw | 4 +- 3 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 src/settings-ui/Settings.UI/Converters/NegativeBoolToVisibilityConverter.cs diff --git a/src/settings-ui/Settings.UI/Converters/NegativeBoolToVisibilityConverter.cs b/src/settings-ui/Settings.UI/Converters/NegativeBoolToVisibilityConverter.cs deleted file mode 100644 index df9f02eca7..0000000000 --- a/src/settings-ui/Settings.UI/Converters/NegativeBoolToVisibilityConverter.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Globalization; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Data; - -namespace Microsoft.PowerToys.Settings.UI.Converters -{ - public class NegativeBoolToVisibilityConverter : IValueConverter - { - object IValueConverter.Convert(object value, Type targetType, object parameter, string language) - { - if ((bool)value) - { - return Visibility.Collapsed; - } - - return Visibility.Visible; - } - - object IValueConverter.ConvertBack(object value, Type targetType, object parameter, string language) - { - if (value is Visibility) - { - if ((Visibility)value == Visibility.Visible) - { - return false; - } - } - - return true; - } - } -} diff --git a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj index e7dad2c2e6..98be30ec56 100644 --- a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj +++ b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj @@ -21,9 +21,6 @@ PowerToys.Settings.pri - - - @@ -127,11 +124,5 @@ Always - - - - $(DefaultXamlRuntime) - - diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index f8c52f1320..5be16768b9 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -3022,7 +3022,7 @@ Activate by holding the key for the character you want to add an accent to, then Find the mouse - Select Image Resizer in the right-click context menu + Resize images from right-click context menu Highlight clicks @@ -3043,7 +3043,7 @@ Activate by holding the key for the character you want to add an accent to, then Quick and easy previewer - Select Power Rename in right-click context menu + Rename files and folders from right-click context menu A quick launcher From f718bef45c42e7e193c44e0261192a724aa914f9 Mon Sep 17 00:00:00 2001 From: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:14:56 +0200 Subject: [PATCH 03/20] [EnvVar]Do not allow Edit/Remove system var if not running elevated (#29333) --- .../EnvironmentVariablesXAML/Views/MainPage.xaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/Views/MainPage.xaml b/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/Views/MainPage.xaml index 08400e5478..fc6c2a5c8a 100644 --- a/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/Views/MainPage.xaml +++ b/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/Views/MainPage.xaml @@ -53,7 +53,10 @@ -