diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index e5c5d6e31f..f20c394d2b 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -106,7 +106,6 @@ public: void MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept { - _TRACER_; m_windowMoveHandler.MoveSizeEnd(window, ptScreen, m_workAreaHandler.GetWorkAreasByDesktopId(m_currentDesktopId)); } @@ -237,6 +236,7 @@ FancyZones::Run() noexcept m_window = CreateWindowExW(WS_EX_TOOLWINDOW, NonLocalizable::ToolWindowClassName, L"", WS_POPUP, 0, 0, 0, 0, nullptr, nullptr, m_hinstance, this); if (!m_window) { + Logger::error(L"Failed to create FancyZones window"); return; } @@ -333,8 +333,6 @@ std::pair, ZoneIndexSet> FancyZones::GetAppZoneHistory void FancyZones::MoveWindowIntoZone(HWND window, winrt::com_ptr workArea, const ZoneIndexSet& zoneIndexSet) noexcept { - _TRACER_; - if (!AppZoneHistory::instance().IsAnotherWindowOfApplicationInstanceZoned(window, workArea->UniqueId())) { if (workArea) @@ -344,6 +342,10 @@ void FancyZones::MoveWindowIntoZone(HWND window, winrt::com_ptr workA m_windowMoveHandler.MoveWindowIntoZoneByIndexSet(window, zoneIndexSet, workArea); AppZoneHistory::instance().UpdateProcessIdToHandleMap(window, workArea->UniqueId()); } + else + { + Logger::info(L"Window was already zoned"); + } } bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR active, HMONITOR primary) noexcept @@ -806,7 +808,8 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept { - _TRACER_; + Logger::info(L"Display changed, type: {}", changeType); + if (changeType == DisplayChangeType::VirtualDesktop || changeType == DisplayChangeType::Initialization) { @@ -852,7 +855,6 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept void FancyZones::AddWorkArea(HMONITOR monitor, const std::wstring& deviceId) noexcept { - _TRACER_; if (m_workAreaHandler.IsNewWorkArea(m_currentDesktopId, monitor)) { wil::unique_cotaskmem_string virtualDesktopIdStr; @@ -978,7 +980,6 @@ void FancyZones::CycleTabs(bool reverse) noexcept bool FancyZones::OnSnapHotkeyBasedOnZoneNumber(HWND window, DWORD vkCode) noexcept { - _TRACER_; HMONITOR current = WorkAreaKeyFromWindow(window); std::vector monitorInfo = GetMonitorsSorted(); @@ -1213,8 +1214,6 @@ bool FancyZones::ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle void FancyZones::RegisterVirtualDesktopUpdates() noexcept { - _TRACER_; - auto guids = m_virtualDesktop.GetVirtualDesktopIdsFromRegistry(); if (guids.has_value()) { @@ -1367,8 +1366,6 @@ std::vector FancyZones::GetMonitorsSorted() noexcept std::vector> FancyZones::GetRawMonitorData() noexcept { - _TRACER_; - std::vector> monitorInfo; const auto& activeWorkAreaMap = m_workAreaHandler.GetWorkAreasByDesktopId(m_currentDesktopId); for (const auto& [monitor, workArea] : activeWorkAreaMap) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp index 096f824d94..9e5b825285 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp @@ -50,8 +50,6 @@ void AppZoneHistory::LoadData() void AppZoneHistory::SaveData() { - _TRACER_; - bool dirtyFlag = false; std::unordered_map> updatedHistory; if (m_virtualDesktopCheckCallback) @@ -84,8 +82,6 @@ void AppZoneHistory::SaveData() bool AppZoneHistory::SetAppLastZones(HWND window, const FancyZonesDataTypes::DeviceIdData& deviceId, const std::wstring& zoneSetId, const ZoneIndexSet& zoneIndexSet) { - _TRACER_; - if (IsAnotherWindowOfApplicationInstanceZoned(window, deviceId)) { return false; @@ -97,6 +93,8 @@ bool AppZoneHistory::SetAppLastZones(HWND window, const FancyZonesDataTypes::Dev return false; } + Logger::info(L"Add app zone history, device: {}, layout: {}", deviceId.toString(), zoneSetId); + DWORD processId = 0; GetWindowThreadProcessId(window, &processId); @@ -142,7 +140,7 @@ bool AppZoneHistory::SetAppLastZones(HWND window, const FancyZonesDataTypes::Dev bool AppZoneHistory::RemoveAppLastZone(HWND window, const FancyZonesDataTypes::DeviceIdData& deviceId, const std::wstring_view& zoneSetId) { - _TRACER_; + Logger::info(L"Add app zone history, device: {}, layout: {}", deviceId.toString(), zoneSetId); auto processPath = get_process_path(window); if (!processPath.empty()) @@ -302,12 +300,17 @@ ZoneIndexSet AppZoneHistory::GetAppLastZoneIndexSet(HWND window, const FancyZone void AppZoneHistory::SyncVirtualDesktops(GUID currentVirtualDesktopId) { - _TRACER_; // Explorer persists current virtual desktop identifier to registry on a per session basis, // but only after first virtual desktop switch happens. If the user hasn't switched virtual // desktops in this session value in registry will be empty and we will use default GUID in // that case (00000000-0000-0000-0000-000000000000). + auto currentVirtualDesktopStr = FancyZonesUtils::GuidToString(currentVirtualDesktopId); + if (currentVirtualDesktopStr) + { + Logger::info(L"AppZoneHistory Sync virtual desktops: current {}", currentVirtualDesktopStr.value()); + } + bool dirtyFlag = false; for (auto& [path, perDesktopData] : m_history) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppliedLayouts.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppliedLayouts.cpp index c1f6fe9efb..3fb23fe4da 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppliedLayouts.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppliedLayouts.cpp @@ -173,8 +173,6 @@ void AppliedLayouts::LoadData() void AppliedLayouts::SaveData() { - _TRACER_; - bool dirtyFlag = false; TAppliedLayoutsMap updatedMap; if (m_virtualDesktopCheckCallback) @@ -209,12 +207,17 @@ void AppliedLayouts::SetVirtualDesktopCheckCallback(std::function ca void AppliedLayouts::SyncVirtualDesktops(GUID currentVirtualDesktopId) { - _TRACER_; // Explorer persists current virtual desktop identifier to registry on a per session basis, // but only after first virtual desktop switch happens. If the user hasn't switched virtual // desktops in this session value in registry will be empty and we will use default GUID in // that case (00000000-0000-0000-0000-000000000000). + auto currentVirtualDesktopStr = FancyZonesUtils::GuidToString(currentVirtualDesktopId); + if (currentVirtualDesktopStr) + { + Logger::info(L"AppliedLayouts Sync virtual desktops: current {}", currentVirtualDesktopStr.value()); + } + bool dirtyFlag = false; std::vector replaceWithCurrentId{}; diff --git a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp index 5bd41d3876..a583948a72 100644 --- a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp +++ b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp @@ -3,6 +3,8 @@ #include "VirtualDesktop.h" #include "util.h" +#include + winrt::com_ptr MonitorWorkAreaHandler::GetWorkArea(const GUID& desktopId, HMONITOR monitor) { auto desktopIt = workAreaMap.find(desktopId); @@ -83,6 +85,12 @@ void MonitorWorkAreaHandler::AddWorkArea(const GUID& desktopId, HMONITOR monitor if (!workAreaMap.contains(desktopId)) { workAreaMap[desktopId] = {}; + + auto desktopIdStr = FancyZonesUtils::GuidToString(desktopId); + if (desktopIdStr) + { + Logger::info(L"Add work area on the desktop {}", desktopIdStr.value()); + } } auto& perDesktopData = workAreaMap[desktopId]; perDesktopData[monitor] = std::move(workArea); diff --git a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp index 09a33e3370..fb3f2fea95 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp @@ -354,9 +354,15 @@ void WindowMoveHandler::SetWindowTransparency(HWND window) noexcept GWL_EXSTYLE, m_windowTransparencyProperties.draggedWindowExstyle | WS_EX_LAYERED); - GetLayeredWindowAttributes(window, &m_windowTransparencyProperties.draggedWindowCrKey, &m_windowTransparencyProperties.draggedWindowInitialAlpha, &m_windowTransparencyProperties.draggedWindowDwFlags); + if (!GetLayeredWindowAttributes(window, &m_windowTransparencyProperties.draggedWindowCrKey, &m_windowTransparencyProperties.draggedWindowInitialAlpha, &m_windowTransparencyProperties.draggedWindowDwFlags)) + { + Logger::error(L"SetWindowTransparency: GetLayeredWindowAttributes failed, {}", get_last_error_or_default(GetLastError())); + } - SetLayeredWindowAttributes(window, 0, (255 * 50) / 100, LWA_ALPHA); + if (!SetLayeredWindowAttributes(window, 0, (255 * 50) / 100, LWA_ALPHA)) + { + Logger::error(L"SetWindowTransparency: SetLayeredWindowAttributes failed, {}", get_last_error_or_default(GetLastError())); + } } } @@ -364,8 +370,16 @@ void WindowMoveHandler::ResetWindowTransparency() noexcept { if (FancyZonesSettings::settings().makeDraggedWindowTransparent && m_windowTransparencyProperties.draggedWindow != nullptr) { - SetLayeredWindowAttributes(m_windowTransparencyProperties.draggedWindow, m_windowTransparencyProperties.draggedWindowCrKey, m_windowTransparencyProperties.draggedWindowInitialAlpha, m_windowTransparencyProperties.draggedWindowDwFlags); - SetWindowLong(m_windowTransparencyProperties.draggedWindow, GWL_EXSTYLE, m_windowTransparencyProperties.draggedWindowExstyle); + if (!SetLayeredWindowAttributes(m_windowTransparencyProperties.draggedWindow, m_windowTransparencyProperties.draggedWindowCrKey, m_windowTransparencyProperties.draggedWindowInitialAlpha, m_windowTransparencyProperties.draggedWindowDwFlags)) + { + Logger::error(L"ResetWindowTransparency: SetLayeredWindowAttributes failed"); + } + + if (SetWindowLong(m_windowTransparencyProperties.draggedWindow, GWL_EXSTYLE, m_windowTransparencyProperties.draggedWindowExstyle) == 0) + { + Logger::error(L"ResetWindowTransparency: SetWindowLong failed, {}", get_last_error_or_default(GetLastError())); + } + m_windowTransparencyProperties.draggedWindow = nullptr; } } diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp index 2104d548de..3671017930 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp @@ -2,7 +2,9 @@ #include "WindowUtils.h" #include +#include #include +#include #include #include @@ -292,14 +294,20 @@ void FancyZonesWindowUtils::SwitchToWindow(HWND window) noexcept if (IsIconic(window)) { // Show the window since SetForegroundWindow fails on minimized windows - ShowWindow(window, SW_RESTORE); + if (!ShowWindow(window, SW_RESTORE)) + { + Logger::error(L"ShowWindow failed"); + } } // This is a hack to bypass the restriction on setting the foreground window INPUT inputs[1] = { { .type = INPUT_MOUSE } }; SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT)); - SetForegroundWindow(window); + if (!SetForegroundWindow(window)) + { + Logger::error(L"SetForegroundWindow failed"); + } } void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept @@ -338,10 +346,19 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept placement.flags |= WPF_ASYNCWINDOWPLACEMENT; - ::SetWindowPlacement(window, &placement); + auto result = ::SetWindowPlacement(window, &placement); + if (!result) + { + Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError())); + } + // Do it again, allowing Windows to resize the window and set correct scaling // This fixes Issue #365 - ::SetWindowPlacement(window, &placement); + result = ::SetWindowPlacement(window, &placement); + if (!result) + { + Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError())); + } } void FancyZonesWindowUtils::SaveWindowSizeAndOrigin(HWND window) noexcept @@ -390,6 +407,7 @@ void FancyZonesWindowUtils::RestoreWindowSize(HWND window) noexcept { rect.right = rect.left + windowSize[0]; rect.bottom = rect.top + windowSize[1]; + Logger::info("Restore window size"); SizeWindowToRect(window, rect); } @@ -423,6 +441,8 @@ void FancyZonesWindowUtils::RestoreWindowOrigin(HWND window) noexcept rect.right += xOffset; rect.top += yOffset; rect.bottom += yOffset; + + Logger::info("Restore window origin"); SizeWindowToRect(window, rect); } diff --git a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp index ea49ee59ac..7290d9a587 100644 --- a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp @@ -44,7 +44,6 @@ namespace HWND ExtractWindow() { - _TRACER_; std::unique_lock lock(m_mutex); if (m_pool.empty()) @@ -84,7 +83,6 @@ namespace void FreeZonesOverlayWindow(HWND window) { - _TRACER_; Logger::info("Freeing ZonesOverlay window into pool, hWnd = {}", (void*)window); SetWindowLongPtrW(window, GWLP_USERDATA, 0); ShowWindow(window, SW_HIDE); @@ -196,6 +194,7 @@ bool WorkArea::Init(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataT mi.cbSize = sizeof(mi); if (!GetMonitorInfoW(monitor, &mi)) { + Logger::error(L"GetMonitorInfo failed on work area initialization"); return false; } workAreaRect = Rect(mi.rcWork); @@ -212,6 +211,7 @@ bool WorkArea::Init(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataT if (!m_window) { + Logger::error(L"No work area window"); return false; } @@ -508,6 +508,7 @@ void WorkArea::CalculateZoneSet(OverlappingZonesAlgorithm overlappingAlgorithm) } else { + Logger::error(L"CalculateZoneSet: GetMonitorInfo failed"); return; } } diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp b/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp index 5a21d9ee25..41f65325ab 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp +++ b/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -304,6 +305,11 @@ ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const Zo return; } + if (!zoneIds.empty()) + { + Logger::trace(L"Move window into zones {} - {}", zoneIds.front(), zoneIds.back()); + } + // Always clear the info related to SelectManyZones if it's not being used if (!m_inExtendWindow) { @@ -460,6 +466,10 @@ ZoneSet::MoveWindowIntoZoneByDirectionAndPosition(HWND window, HWND workAreaWind } } } + else + { + Logger::error(L"GetWindowRect failed, {}", get_last_error_or_default(GetLastError())); + } return false; } @@ -546,6 +556,10 @@ ZoneSet::ExtendWindowByDirectionAndPosition(HWND window, HWND workAreaWindow, DW return true; } } + else + { + Logger::error(L"GetWindowRect failed, {}", get_last_error_or_default(GetLastError())); + } return false; } @@ -666,12 +680,14 @@ ZoneSet::CalculateZones(RECT workAreaRect, int zoneCount, int spacing) noexcept //invalid work area if (workArea.width() == 0 || workArea.height() == 0) { + Logger::error(L"CalculateZones: invalid work area"); return false; } //invalid zoneCount, may cause division by zero if (zoneCount <= 0 && m_config.LayoutType != FancyZonesDataTypes::ZoneSetLayoutType::Custom) { + Logger::error(L"CalculateZones: invalid zone count"); return false; } diff --git a/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp b/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp index 263d72ef5f..8f11c553ab 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp +++ b/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include namespace { @@ -83,7 +83,7 @@ ZonesOverlay::ZonesOverlay(HWND window) // Obtain the size of the drawing area. if (!GetClientRect(window, &m_clientRect)) { - Logger::error("couldn't initialize ZonesOverlay: GetClientRect failed"); + Logger::error(L"couldn't initialize ZonesOverlay: GetClientRect failed"); return; } @@ -102,7 +102,7 @@ ZonesOverlay::ZonesOverlay(HWND window) if (!SUCCEEDED(hr)) { - Logger::error("couldn't initialize ZonesOverlay: CreateHwndRenderTarget failed with {}", hr); + Logger::error(L"couldn't initialize ZonesOverlay: CreateHwndRenderTarget failed with {}", hr); return; } @@ -217,7 +217,6 @@ void ZonesOverlay::RenderLoop() void ZonesOverlay::Hide() { - _TRACER_; bool shouldHideWindow = true; { std::unique_lock lock(m_mutex); @@ -234,7 +233,6 @@ void ZonesOverlay::Hide() void ZonesOverlay::Show() { - _TRACER_; bool shouldShowWindow = true; { std::unique_lock lock(m_mutex); @@ -262,7 +260,6 @@ void ZonesOverlay::Show() void ZonesOverlay::Flash() { - _TRACER_; bool shouldShowWindow = true; { std::unique_lock lock(m_mutex); @@ -285,7 +282,6 @@ void ZonesOverlay::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones, const Colors::ZoneColors& colors, const bool showZoneText) { - _TRACER_; std::unique_lock lock(m_mutex); m_sceneRects = {}; diff --git a/src/modules/fancyzones/FancyZonesLib/util.cpp b/src/modules/fancyzones/FancyZonesLib/util.cpp index 216b768f46..1bc541a1ef 100644 --- a/src/modules/fancyzones/FancyZonesLib/util.cpp +++ b/src/modules/fancyzones/FancyZonesLib/util.cpp @@ -2,6 +2,7 @@ #include "util.h" #include +#include #include #include #include @@ -49,6 +50,8 @@ namespace FancyZonesUtils { ++displayDeviceIdxMap[device]; + Logger::info(L"Get display device: {}", displayDevice.DeviceID); + // Only take active monitors (presented as being "on" by the respective GDI view) and monitors that don't // represent a pseudo device used to mirror application drawing. if (WI_IsFlagSet(displayDevice.StateFlags, DISPLAY_DEVICE_ACTIVE) && @@ -61,6 +64,7 @@ namespace FancyZonesUtils if (deviceId.empty()) { + Logger::info(L"Didn't find display device, set default"); deviceId = GetSystemMetrics(SM_REMOTESESSION) ? L"\\\\?\\DISPLAY#REMOTEDISPLAY#" : L"\\\\?\\DISPLAY#LOCALDISPLAY#";