[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 <zykovas91@gmail.com>

* Update trace.cpp

* Rename EventSnapNewWindowIntoZone

* Adjust event names according to PR feedback

Co-authored-by: Seraphima Zykova <zykovas91@gmail.com>
This commit is contained in:
Jaime Bernardo 2021-11-04 16:53:36 +00:00 committed by GitHub
parent e19ecd2ba1
commit 3a6dd45741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 12 deletions

View File

@ -330,6 +330,10 @@ void FancyZones::MoveWindowIntoZone(HWND window, winrt::com_ptr<IWorkArea> 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;
}
}

View File

@ -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;

View File

@ -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<IZoneSet> set) noexcept
ZoneSetInfo GetZoneSetInfo(_In_opt_ IZoneSet* set) noexcept
{
ZoneSetInfo info;
if (set)
@ -97,6 +101,11 @@ ZoneSetInfo GetZoneSetInfo(_In_opt_ winrt::com_ptr<IZoneSet> set) noexcept
return info;
}
ZoneSetInfo GetZoneSetInfo(_In_opt_ winrt::com_ptr<IZoneSet> 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<void*>(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<void*>(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<IZoneSet> activeSet) noexcept
void Trace::WorkArea::MoveOrResizeStarted(_In_opt_ winrt::com_ptr<IZoneSet> activeSet) noexcept
{
auto const zoneInfo = GetZoneSetInfo(activeSet);
TraceLoggingWrite(
g_hProvider,
EventMoveSizeEndKey,
EventMoveOrResizeStartedKey,
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), ActiveSetKey),
TraceLoggingValue(zoneInfo.NumberOfZones, NumberOfZonesKey),
TraceLoggingValue(zoneInfo.NumberOfWindows, NumberOfWindowsKey));
}
void Trace::WorkArea::MoveOrResizeEnd(_In_opt_ winrt::com_ptr<IZoneSet> activeSet) noexcept
{
auto const zoneInfo = GetZoneSetInfo(activeSet);
TraceLoggingWrite(
g_hProvider,
EventMoveOrResizeEndedKey,
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), ActiveSetKey),

View File

@ -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<IZoneSet> activeSet) noexcept;
static void MoveOrResizeStarted(_In_opt_ winrt::com_ptr<IZoneSet> activeSet) noexcept;
static void MoveOrResizeEnd(_In_opt_ winrt::com_ptr<IZoneSet> activeSet) noexcept;
static void CycleActiveZoneSet(_In_opt_ winrt::com_ptr<IZoneSet> activeSet, InputMode mode) noexcept;
};
};