From fed81c8e227f848becb042a5cf326df25f47b5c7 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 4 Dec 2019 17:53:54 +0100 Subject: [PATCH] Improve FancyZones window filtering (#856) Improve FancyZones window filtering and filter out dialog windows --- src/common/hwnd_data_cache.h | 5 ++++- src/modules/fancyzones/dll/dllmain.cpp | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/hwnd_data_cache.h b/src/common/hwnd_data_cache.h index 4a52a73703ed..22cf5aac4658 100644 --- a/src/common/hwnd_data_cache.h +++ b/src/common/hwnd_data_cache.h @@ -24,7 +24,10 @@ class HWNDDataCache { // List of HWNDs that are not interesting - like desktop, cortana, etc std::vector invalid_hwnds = { GetDesktopWindow(), GetShellWindow() }; // List of invalid window basic styles - std::vector invalid_basic_styles = { WS_CHILD, WS_DISABLED }; + std::vector invalid_basic_styles = { WS_CHILD, WS_DISABLED, DS_ABSALIGN, DS_SYSMODAL, DS_LOCALEDIT, + DS_SETFONT, DS_MODALFRAME, DS_NOIDLEMSG, DS_SETFOREGROUND, DS_3DLOOK, + DS_FIXEDSYS, DS_NOFAILCREATE, DS_CONTROL, DS_CENTER, DS_CENTERMOUSE, + DS_CONTEXTHELP, DS_SHELLFONT }; // List of invalid window extended styles std::vector invalid_ext_styles = { WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE }; // List of invalid window classes - things like start menu, etc. diff --git a/src/modules/fancyzones/dll/dllmain.cpp b/src/modules/fancyzones/dll/dllmain.cpp index 6154a6acb7bb..cf08c4380d7c 100644 --- a/src/modules/fancyzones/dll/dllmain.cpp +++ b/src/modules/fancyzones/dll/dllmain.cpp @@ -199,11 +199,25 @@ class FancyZonesModule : public PowertoyModuleIface private: bool IsInterestingWindow(HWND window) { + auto style = GetWindowLongPtr(window, GWL_STYLE); + auto exStyle = GetWindowLongPtr(window, GWL_EXSTYLE); + // Ignore: + if (GetAncestor(window, GA_ROOT) != window || // windows that are not top-level + GetWindow(window, GW_OWNER) != nullptr || // windows that have an owner - like Save As dialogs + (style & WS_CHILD) != 0 || // windows that are child elements of other windows - like buttons + (style & WS_DISABLED) != 0 || // windows that are disabled + (exStyle & WS_EX_TOOLWINDOW) != 0 || // toolbar windows + !IsWindowVisible(window)) // invisible windows + { + return false; + } + // Filter some windows like the Start menu or Cortana auto windowAndPath = get_filtered_base_window_and_path(window); if (windowAndPath.hwnd == nullptr) { return false; } + // Filter out user specified apps CharUpperBuffW(windowAndPath.process_path.data(), (DWORD)windowAndPath.process_path.length()); if (m_settings) { @@ -215,9 +229,7 @@ class FancyZonesModule : public PowertoyModuleIface } } } - // Don't zone child windows and tool window - return (GetWindowLongPtr(window, GWL_STYLE) & WS_CHILD) == 0 && - (GetWindowLongPtr(window, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0; + return true; } void Disable(bool const traceEvent)