|
1 | 1 | #include "pch.h"
|
2 | 2 | #include "common.h"
|
3 |
| -#include "hwnd_data_cache.h" |
4 | 3 | #include <dwmapi.h>
|
5 | 4 | #pragma comment(lib, "dwmapi.lib")
|
6 | 5 | #include <strsafe.h>
|
@@ -34,12 +33,66 @@ std::optional<POINT> get_mouse_pos() {
|
34 | 33 | }
|
35 | 34 | }
|
36 | 35 |
|
| 36 | +// Test if a window is part of the shell or the task bar. |
| 37 | +// We compare the HWND against HWND of the desktop and shell windows, |
| 38 | +// we also filter out some window class names know to belong to |
| 39 | +// the taskbar. |
| 40 | +static bool is_system_window(HWND hwnd, const char* class_name) { |
| 41 | + static auto system_classes = { "SysListView32", "WorkerW", "Shell_TrayWnd", "Shell_SecondaryTrayWnd", "Progman" }; |
| 42 | + static auto system_hwnds = { GetDesktopWindow(), GetShellWindow() }; |
| 43 | + for (auto system_hwnd : system_hwnds) { |
| 44 | + if (hwnd == system_hwnd) { |
| 45 | + return true; |
| 46 | + } |
| 47 | + } |
| 48 | + for (const auto& system_class : system_classes) { |
| 49 | + if (strcmp(system_class, class_name) == 0) { |
| 50 | + return true; |
| 51 | + } |
| 52 | + } |
| 53 | + return false; |
| 54 | +} |
| 55 | + |
37 | 56 | WindowAndProcPath get_filtered_base_window_and_path(HWND window) {
|
38 |
| - return hwnd_cache.get_window_and_path(window); |
| 57 | + WindowAndProcPath result; |
| 58 | + auto root = GetAncestor(window, GA_ROOT); |
| 59 | + if (!IsWindowVisible(root)) { |
| 60 | + return result; |
| 61 | + } |
| 62 | + auto style = GetWindowLong(root, GWL_STYLE); |
| 63 | + auto exStyle = GetWindowLong(root, GWL_EXSTYLE); |
| 64 | + // WS_POPUP need to have a border or minimize/maximize buttons, |
| 65 | + // otherwise the window is "not interesting" |
| 66 | + if ((style & WS_POPUP) == WS_POPUP && |
| 67 | + (style & WS_THICKFRAME) == 0 && |
| 68 | + (style & WS_MINIMIZEBOX) == 0 && |
| 69 | + (style & WS_MAXIMIZEBOX) == 0) { |
| 70 | + return result; |
| 71 | + } |
| 72 | + if ((style & WS_CHILD) == WS_CHILD || |
| 73 | + (style & WS_DISABLED) == WS_DISABLED || |
| 74 | + (exStyle & WS_EX_TOOLWINDOW) == WS_EX_TOOLWINDOW || |
| 75 | + (exStyle & WS_EX_NOACTIVATE) == WS_EX_NOACTIVATE) { |
| 76 | + return result; |
| 77 | + } |
| 78 | + std::array<char, 256> class_name; |
| 79 | + GetClassNameA(root, class_name.data(), static_cast<int>(class_name.size())); |
| 80 | + if (is_system_window(root, class_name.data())) { |
| 81 | + return result; |
| 82 | + } |
| 83 | + auto process_path = get_process_path(root); |
| 84 | + // Check for Cortana: |
| 85 | + if (strcmp(class_name.data(), "Windows.UI.Core.CoreWindow") == 0 && |
| 86 | + process_path.ends_with(L"SearchUI.exe")) { |
| 87 | + return result; |
| 88 | + } |
| 89 | + result.hwnd = root; |
| 90 | + result.process_path = std::move(process_path); |
| 91 | + return result; |
39 | 92 | }
|
40 | 93 |
|
41 | 94 | HWND get_filtered_active_window() {
|
42 |
| - return hwnd_cache.get_window(GetForegroundWindow()); |
| 95 | + return get_filtered_base_window_and_path(GetForegroundWindow()).hwnd; |
43 | 96 | }
|
44 | 97 |
|
45 | 98 | int width(const RECT& rect) {
|
|
0 commit comments