From 3a6dd45741c16b97c6e92758367bcfbcc0b3e261 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 4 Nov 2021 16:53:36 +0000 Subject: [PATCH] [Telemetry] Add basic interaction events to FZ (#12793) * [Telemetry] Add basic interaction events to FZ Adds some basic interaction events to FancyZones, such as: - Starting the drag Window movement. - A newly created window snapping to a zone. - Using the Keyboard to snap or extend to a zone. * Update src/modules/fancyzones/FancyZonesLib/FancyZones.cpp Co-authored-by: Seraphima Zykova * Update trace.cpp * Rename EventSnapNewWindowIntoZone * Adjust event names according to PR feedback Co-authored-by: Seraphima Zykova --- .../fancyzones/FancyZonesLib/FancyZones.cpp | 40 +++++++++++-- .../fancyzones/FancyZonesLib/WorkArea.cpp | 3 +- .../fancyzones/FancyZonesLib/trace.cpp | 56 +++++++++++++++++-- src/modules/fancyzones/FancyZonesLib/trace.h | 5 +- 4 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index 39e5ad66a5..284aa890bd 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -330,6 +330,10 @@ void FancyZones::MoveWindowIntoZone(HWND window, winrt::com_ptr zoneW auto& fancyZonesData = FancyZonesDataInstance(); if (!fancyZonesData.IsAnotherWindowOfApplicationInstanceZoned(window, zoneWindow->UniqueId())) { + if (zoneWindow) + { + Trace::FancyZones::SnapNewWindowIntoZone(zoneWindow->ActiveZoneSet()); + } m_windowMoveHandler.MoveWindowIntoZoneByIndexSet(window, zoneIndexSet, zoneWindow); fancyZonesData.UpdateProcessIdToHandleMap(window, zoneWindow->UniqueId()); } @@ -966,8 +970,10 @@ bool FancyZones::OnSnapHotkeyBasedOnZoneNumber(HWND window, DWORD vkCode) noexce auto currMonitorInfo = std::find(std::begin(monitorInfo), std::end(monitorInfo), current); do { - if (m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, false /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, *currMonitorInfo))) + auto zoneWindow = m_workAreaHandler.GetWorkArea(m_currentDesktopId, *currMonitorInfo); + if (m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, false /* cycle through zones */, zoneWindow)) { + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); return true; } // We iterated through all zones in current monitor zone layout, move on to next one (or previous depending on direction). @@ -991,20 +997,30 @@ bool FancyZones::OnSnapHotkeyBasedOnZoneNumber(HWND window, DWORD vkCode) noexce } else { + auto zoneWindow = m_workAreaHandler.GetWorkArea(m_currentDesktopId, current); // Single monitor environment, or combined multi-monitor environment. if (m_settings->GetSettings()->restoreSize) { - bool moved = m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, false /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current)); + bool moved = m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, false /* cycle through zones */, zoneWindow); if (!moved) { FancyZonesUtils::RestoreWindowOrigin(window); FancyZonesUtils::RestoreWindowSize(window); } - return true; + else + { + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); + } + return moved; } else { - return m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, true /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current)); + bool moved = m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, true /* cycle through zones */, zoneWindow); + if (moved) + { + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); + } + return moved; } } @@ -1078,6 +1094,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept // Moving to another monitor succeeded const auto& [trueZoneIdx, zoneWindow] = zoneRectsInfo[chosenIdx]; m_windowMoveHandler.MoveWindowIntoZoneByIndexSet(window, { trueZoneIdx }, zoneWindow); + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); return true; } @@ -1122,6 +1139,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept // Moving to another monitor succeeded const auto& [trueZoneIdx, zoneWindow] = zoneRectsInfo[chosenIdx]; m_windowMoveHandler.MoveWindowIntoZoneByIndexSet(window, { trueZoneIdx }, zoneWindow); + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); return true; } else @@ -1157,11 +1175,21 @@ bool FancyZones::ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle // Check whether Alt is used in the shortcut key combination if (GetAsyncKeyState(VK_MENU) & 0x8000) { - return m_windowMoveHandler.ExtendWindowByDirectionAndPosition(window, vkCode, zoneWindow); + bool result = m_windowMoveHandler.ExtendWindowByDirectionAndPosition(window, vkCode, zoneWindow); + if (result) + { + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); + } + return result; } else { - return m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, cycle, zoneWindow); + bool result = m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, cycle, zoneWindow); + if (result) + { + Trace::FancyZones::KeyboardSnapWindowToZone(zoneWindow->ActiveZoneSet()); + } + return result; } } diff --git a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp index 160d380b6c..995dcaeb06 100644 --- a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp @@ -234,6 +234,7 @@ IFACEMETHODIMP WorkArea::MoveSizeEnter(HWND window) noexcept m_highlightZone = {}; m_initialHighlightZone = {}; ShowZoneWindow(); + Trace::WorkArea::MoveOrResizeStarted(m_activeZoneSet); return S_OK; } @@ -299,7 +300,7 @@ IFACEMETHODIMP WorkArea::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcep SaveWindowProcessToZoneIndex(window); } } - Trace::WorkArea::MoveSizeEnd(m_activeZoneSet); + Trace::WorkArea::MoveOrResizeEnd(m_activeZoneSet); HideZoneWindow(); m_windowMoveSize = nullptr; diff --git a/src/modules/fancyzones/FancyZonesLib/trace.cpp b/src/modules/fancyzones/FancyZonesLib/trace.cpp index 8cb3619bcb..13e06c6d8c 100644 --- a/src/modules/fancyzones/FancyZonesLib/trace.cpp +++ b/src/modules/fancyzones/FancyZonesLib/trace.cpp @@ -15,7 +15,10 @@ #define EventSettingsKey "FancyZones_Settings" #define EventDesktopChangedKey "FancyZones_VirtualDesktopChanged" #define EventZoneWindowKeyUpKey "FancyZones_ZoneWindowKeyUp" -#define EventMoveSizeEndKey "FancyZones_MoveSizeEnd" +#define EventSnapNewWindowIntoZone "FancyZones_SnapNewWindowIntoZone" +#define EventKeyboardSnapWindowToZone "FancyZones_KeyboardSnapWindowToZone" +#define EventMoveOrResizeStartedKey "FancyZones_MoveOrResizeStarted" +#define EventMoveOrResizeEndedKey "FancyZones_MoveOrResizeEnded" #define EventCycleActiveZoneSetKey "FancyZones_CycleActiveZoneSet" #define EventQuickLayoutSwitchKey "FancyZones_QuickLayoutSwitch" @@ -78,7 +81,8 @@ struct ZoneSetInfo size_t NumberOfWindows = 0; }; -ZoneSetInfo GetZoneSetInfo(_In_opt_ winrt::com_ptr set) noexcept + +ZoneSetInfo GetZoneSetInfo(_In_opt_ IZoneSet* set) noexcept { ZoneSetInfo info; if (set) @@ -97,6 +101,11 @@ ZoneSetInfo GetZoneSetInfo(_In_opt_ winrt::com_ptr set) noexcept return info; } +ZoneSetInfo GetZoneSetInfo(_In_opt_ winrt::com_ptr set) noexcept +{ + return GetZoneSetInfo(set.get()); +} + void Trace::RegisterProvider() noexcept { TraceLoggingRegister(g_hProvider); @@ -247,6 +256,32 @@ void Trace::FancyZones::QuickLayoutSwitched(bool shortcutUsed) noexcept TraceLoggingBoolean(shortcutUsed, QuickLayoutSwitchedWithShortcutUsed)); } +void Trace::FancyZones::SnapNewWindowIntoZone(IZoneSet* activeSet) noexcept +{ + auto const zoneInfo = GetZoneSetInfo(activeSet); + TraceLoggingWrite( + g_hProvider, + EventSnapNewWindowIntoZone, + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), + TraceLoggingValue(reinterpret_cast(activeSet), ActiveSetKey), + TraceLoggingValue(zoneInfo.NumberOfZones, NumberOfZonesKey), + TraceLoggingValue(zoneInfo.NumberOfWindows, NumberOfWindowsKey)); +} + +void Trace::FancyZones::KeyboardSnapWindowToZone(IZoneSet* activeSet) noexcept +{ + auto const zoneInfo = GetZoneSetInfo(activeSet); + TraceLoggingWrite( + g_hProvider, + EventKeyboardSnapWindowToZone, + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), + TraceLoggingValue(reinterpret_cast(activeSet), ActiveSetKey), + TraceLoggingValue(zoneInfo.NumberOfZones, NumberOfZonesKey), + TraceLoggingValue(zoneInfo.NumberOfWindows, NumberOfWindowsKey)); +} + static std::wstring HotKeyToString(const PowerToysSettings::HotkeyObject& hotkey) { return L"alt:" + std::to_wstring(hotkey.alt_pressed()) @@ -316,12 +351,25 @@ void Trace::WorkArea::KeyUp(WPARAM wParam) noexcept TraceLoggingValue(wParam, KeyboardValueKey)); } -void Trace::WorkArea::MoveSizeEnd(_In_opt_ winrt::com_ptr activeSet) noexcept +void Trace::WorkArea::MoveOrResizeStarted(_In_opt_ winrt::com_ptr activeSet) noexcept { auto const zoneInfo = GetZoneSetInfo(activeSet); TraceLoggingWrite( g_hProvider, - EventMoveSizeEndKey, + EventMoveOrResizeStartedKey, + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), + TraceLoggingValue(reinterpret_cast(activeSet.get()), ActiveSetKey), + TraceLoggingValue(zoneInfo.NumberOfZones, NumberOfZonesKey), + TraceLoggingValue(zoneInfo.NumberOfWindows, NumberOfWindowsKey)); +} + +void Trace::WorkArea::MoveOrResizeEnd(_In_opt_ winrt::com_ptr activeSet) noexcept +{ + auto const zoneInfo = GetZoneSetInfo(activeSet); + TraceLoggingWrite( + g_hProvider, + EventMoveOrResizeEndedKey, ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), TraceLoggingValue(reinterpret_cast(activeSet.get()), ActiveSetKey), diff --git a/src/modules/fancyzones/FancyZonesLib/trace.h b/src/modules/fancyzones/FancyZonesLib/trace.h index 9291b76ea9..9435bdcc9f 100644 --- a/src/modules/fancyzones/FancyZonesLib/trace.h +++ b/src/modules/fancyzones/FancyZonesLib/trace.h @@ -18,6 +18,8 @@ public: static void EditorLaunched(int value) noexcept; static void Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept; static void QuickLayoutSwitched(bool shortcutUsed) noexcept; + static void SnapNewWindowIntoZone(IZoneSet* activeSet) noexcept; + static void KeyboardSnapWindowToZone(IZoneSet* activeSet) noexcept; }; static void SettingsTelemetry(const Settings& settings) noexcept; @@ -33,7 +35,8 @@ public: }; static void KeyUp(WPARAM wparam) noexcept; - static void MoveSizeEnd(_In_opt_ winrt::com_ptr activeSet) noexcept; + static void MoveOrResizeStarted(_In_opt_ winrt::com_ptr activeSet) noexcept; + static void MoveOrResizeEnd(_In_opt_ winrt::com_ptr activeSet) noexcept; static void CycleActiveZoneSet(_In_opt_ winrt::com_ptr activeSet, InputMode mode) noexcept; }; };