Skip to content

Commit

Permalink
[FancyZones] Popup behavior fix (#18270)
Browse files Browse the repository at this point in the history
* virtual desktop check

* refactoring

* unified check
  • Loading branch information
SeraphimaZykova committed May 20, 2022
1 parent be1ed8c commit 251ea6d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src/modules/fancyzones/FancyZonesLib/FancyZones.cpp
Expand Up @@ -17,6 +17,7 @@
#include <FancyZonesLib/FancyZonesData/CustomLayouts.h>
#include <FancyZonesLib/FancyZonesData/LayoutHotkeys.h>
#include <FancyZonesLib/FancyZonesData/LayoutTemplates.h>
#include <FancyZonesLib/FancyZonesWindowProcessing.h>
#include <FancyZonesLib/FancyZonesWindowProperties.h>
#include <FancyZonesLib/FancyZonesWinHookEventIDs.h>
#include <FancyZonesLib/MonitorUtils.h>
Expand Down Expand Up @@ -376,28 +377,12 @@ void FancyZones::WindowCreated(HWND window) noexcept
return;
}

auto desktopId = VirtualDesktop::instance().GetDesktopId(window);
if (desktopId.has_value() && *desktopId != VirtualDesktop::instance().GetCurrentVirtualDesktopId())
{
// Switch between virtual desktops results with posting same windows messages that also indicate
// creation of new window. We need to check if window being processed is on currently active desktop.
return;
}

// Avoid processing splash screens, already stamped (zoned) windows, or those windows
// that belong to excluded applications list.
const bool isSplashScreen = FancyZonesWindowUtils::IsSplashScreen(window);
if (isSplashScreen)
{
return;
}

const bool windowMinimized = IsIconic(window);
if (windowMinimized)
if (!FancyZonesWindowProcessing::IsProcessable(window))
{
return;
}

// Avoid already stamped (zoned) windows
const bool isZoned = !FancyZonesWindowProperties::RetrieveZoneIndexProperty(window).empty();
if (isZoned)
{
Expand Down Expand Up @@ -1245,6 +1230,12 @@ void FancyZones::UpdateZoneSets() noexcept
bool FancyZones::ShouldProcessSnapHotkey(DWORD vkCode) noexcept
{
auto window = GetForegroundWindow();

if (!FancyZonesWindowProcessing::IsProcessable(window))
{
return false;
}

if (FancyZonesSettings::settings().overrideSnapHotkeys && FancyZonesWindowUtils::IsCandidateForZoning(window))
{
HMONITOR monitor = WorkAreaKeyFromWindow(window);
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/FancyZonesLib/FancyZonesLib.vcxproj
Expand Up @@ -43,6 +43,7 @@
<ClInclude Include="FancyZonesData\Layout.h" />
<ClInclude Include="FancyZonesData\LayoutDefaults.h" />
<ClInclude Include="FancyZonesData\LayoutTemplates.h" />
<ClInclude Include="FancyZonesWindowProcessing.h" />
<ClInclude Include="FancyZonesWinHookEventIDs.h" />
<ClInclude Include="GenericKeyHook.h" />
<ClInclude Include="FancyZonesData.h" />
Expand Down
Expand Up @@ -129,6 +129,9 @@
<ClInclude Include="LayoutConfigurator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FancyZonesWindowProcessing.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand Down
34 changes: 34 additions & 0 deletions src/modules/fancyzones/FancyZonesLib/FancyZonesWindowProcessing.h
@@ -0,0 +1,34 @@
#pragma once

#include <FancyZonesLib/VirtualDesktop.h>
#include <FancyZonesLib/WindowUtils.h>

namespace FancyZonesWindowProcessing
{
inline bool IsProcessable(HWND window) noexcept
{
const bool isSplashScreen = FancyZonesWindowUtils::IsSplashScreen(window);
if (isSplashScreen)
{
return false;
}

const bool windowMinimized = IsIconic(window);
if (windowMinimized)
{
return false;
}

// Switch between virtual desktops results with posting same windows messages that also indicate
// creation of new window. We need to check if window being processed is on currently active desktop.
// For windows that FancyZones shouldn't process (start menu, tray, popup menus)
// VirtualDesktopManager is unable to retrieve virtual desktop id and returns an error.
auto desktopId = VirtualDesktop::instance().GetDesktopId(window);
if (!desktopId.has_value() || (desktopId.has_value() && *desktopId != VirtualDesktop::instance().GetCurrentVirtualDesktopId()))
{
return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp
Expand Up @@ -201,7 +201,7 @@ std::optional<GUID> VirtualDesktop::GetDesktopId(HWND window) const
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 && id != GUID_NULL)
if (m_vdManager->GetWindowDesktopId(window, &id) == S_OK)
{
return id;
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp
Expand Up @@ -10,6 +10,7 @@
#include "FancyZonesData/AppZoneHistory.h"
#include "Settings.h"
#include "WorkArea.h"
#include <FancyZonesLib/FancyZonesWindowProcessing.h>
#include <FancyZonesLib/WindowUtils.h>

// Non-Localizable strings
Expand Down Expand Up @@ -60,6 +61,11 @@ WindowMoveHandler::WindowMoveHandler(const std::function<void()>& keyUpdateCallb

void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map<HMONITOR, winrt::com_ptr<IWorkArea>>& workAreaMap) noexcept
{
if (!FancyZonesWindowProcessing::IsProcessable(window))
{
return;
}

if (!FancyZonesWindowUtils::IsCandidateForZoning(window) || WindowMoveHandlerUtils::IsCursorTypeIndicatingSizeEvent())
{
return;
Expand Down

0 comments on commit 251ea6d

Please sign in to comment.