From 5576c7b23f4764c0ce2b5f4aead984d5bbb58db5 Mon Sep 17 00:00:00 2001 From: seraphima Date: Sat, 13 Jul 2024 21:07:37 +0200 Subject: [PATCH] clean up --- .../ProjectsSnapshotTool/SnapshotUtils.cpp | 5 +++++ .../Projects/projects-common/WindowFilter.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp b/src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp index 3cfc9992f5..b252768ac1 100644 --- a/src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp +++ b/src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp @@ -201,6 +201,11 @@ namespace SnapshotUtils } } + if (WindowFilter::FilterPopup(window)) + { + continue; + } + auto data = Utils::Apps::GetApp(processPath, installedApps); if (!data.has_value() || data->name.empty()) { diff --git a/src/modules/Projects/projects-common/WindowFilter.h b/src/modules/Projects/projects-common/WindowFilter.h index 76c60e5621..a5c542a2b2 100644 --- a/src/modules/Projects/projects-common/WindowFilter.h +++ b/src/modules/Projects/projects-common/WindowFilter.h @@ -38,4 +38,23 @@ namespace WindowFilter return true; } + + inline bool FilterPopup(HWND window) + { + auto style = GetWindowLong(window, GWL_STYLE); + bool isPopup = WindowUtils::HasStyle(style, WS_POPUP); + bool hasThickFrame = WindowUtils::HasStyle(style, WS_THICKFRAME); + bool hasCaption = WindowUtils::HasStyle(style, WS_CAPTION); + bool hasMinimizeMaximizeButtons = WindowUtils::HasStyle(style, WS_MINIMIZEBOX) || WindowUtils::HasStyle(style, WS_MAXIMIZEBOX); + if (isPopup && !(hasThickFrame && (hasCaption || hasMinimizeMaximizeButtons))) + { + // popup windows we want to snap: e.g. Calculator, Telegram + // popup windows we don't want to snap: start menu, notification popup, tray window, etc. + // WS_CAPTION, WS_MINIMIZEBOX, WS_MAXIMIZEBOX are used for filtering out menus, + // e.g., in Edge "Running as admin" menu when creating a new PowerToys issue. + return true; + } + + return false; + } }