Skip to content

Commit

Permalink
Improve FancyZones window filtering (#856)
Browse files Browse the repository at this point in the history
Improve FancyZones window filtering and filter out dialog windows
  • Loading branch information
bzoz authored Dec 4, 2019
1 parent 3a65d5c commit fed81c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/common/hwnd_data_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class HWNDDataCache {
// List of HWNDs that are not interesting - like desktop, cortana, etc
std::vector<HWND> invalid_hwnds = { GetDesktopWindow(), GetShellWindow() };
// List of invalid window basic styles
std::vector<LONG> invalid_basic_styles = { WS_CHILD, WS_DISABLED };
std::vector<LONG> 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<LONG> invalid_ext_styles = { WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE };
// List of invalid window classes - things like start menu, etc.
Expand Down
18 changes: 15 additions & 3 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit fed81c8

Please sign in to comment.