WindowFilter.h
1 #pragma once 2 3 #include "VirtualDesktop.h" 4 #include "WindowUtils.h" 5 6 namespace WindowFilter 7 { 8 inline bool FilterPopup(HWND window) 9 { 10 auto style = GetWindowLong(window, GWL_STYLE); 11 bool isPopup = WindowUtils::HasStyle(style, WS_POPUP); 12 bool hasCaption = WindowUtils::HasStyle(style, WS_CAPTION); 13 bool hasMinimizeMaximizeButtons = WindowUtils::HasStyle(style, WS_MINIMIZEBOX) || WindowUtils::HasStyle(style, WS_MAXIMIZEBOX); 14 15 Logger::info("Style for window: {}, {:#x}", reinterpret_cast<void*>(window), style); 16 17 if (isPopup && !(hasCaption || hasMinimizeMaximizeButtons)) 18 { 19 // popup windows we want to snap: e.g. Calculator, Telegram 20 // popup windows we don't want to snap: start menu, notification popup, tray window, etc. 21 // WS_CAPTION, WS_MINIMIZEBOX, WS_MAXIMIZEBOX are used for filtering out menus, 22 // e.g., in Edge "Running as admin" menu when creating a new PowerToys issue. 23 return true; 24 } 25 26 return false; 27 } 28 29 inline bool Filter(HWND window) 30 { 31 auto style = GetWindowLong(window, GWL_STYLE); 32 auto exStyle = GetWindowLong(window, GWL_EXSTYLE); 33 34 if (!WindowUtils::HasStyle(style, WS_VISIBLE)) 35 { 36 return false; 37 } 38 39 if (!IsWindowVisible(window)) 40 { 41 return false; 42 } 43 44 if (WindowUtils::HasStyle(exStyle, WS_EX_TOOLWINDOW)) 45 { 46 return false; 47 } 48 49 if (!WindowUtils::IsRoot(window)) 50 { 51 // child windows such as buttons, combo boxes, etc. 52 return false; 53 } 54 55 if (!VirtualDesktop::instance().IsWindowOnCurrentDesktop(window)) 56 { 57 return false; 58 } 59 60 return true; 61 } 62 }