Move window filter to separate function, filter more windows.

This commit is contained in:
Bartosz Sosnowski
2019-09-17 13:45:49 +02:00
committed by Bartosz Sosnowski
parent a54e4299aa
commit 487c485911
4 changed files with 32 additions and 21 deletions

View File

@@ -32,6 +32,34 @@ std::optional<POINT> get_mouse_pos() {
} }
} }
HWND get_filtered_active_window() {
static auto desktop = GetDesktopWindow();
static auto shell = GetShellWindow();
auto active_window = GetForegroundWindow();
active_window = GetAncestor(active_window, GA_ROOT);
if (active_window == desktop || active_window == shell) {
return nullptr;
}
auto window_styles = GetWindowLong(active_window, GWL_STYLE);
if ((window_styles & WS_CHILD) || (window_styles & WS_DISABLED)) {
return nullptr;
}
window_styles = GetWindowLong(active_window, GWL_EXSTYLE);
if ((window_styles & WS_EX_TOOLWINDOW) ||(window_styles & WS_EX_NOACTIVATE)) {
return nullptr;
}
char class_name[256] = "";
GetClassNameA(active_window, class_name, 256);
if (strcmp(class_name, "SysListView32") == 0 ||
strcmp(class_name, "WorkerW") == 0 ||
strcmp(class_name, "Shell_TrayWnd") == 0 ||
strcmp(class_name, "Shell_SecondaryTrayWnd") == 0 ||
strcmp(class_name, "Progman") == 0) {
return nullptr;
}
return active_window;
}
int width(const RECT& rect) { int width(const RECT& rect) {
return rect.right - rect.left; return rect.right - rect.left;
} }

View File

@@ -9,6 +9,9 @@ std::optional<RECT> get_button_pos(HWND hwnd);
std::optional<RECT> get_window_pos(HWND hwnd); std::optional<RECT> get_window_pos(HWND hwnd);
// Gets mouse postion. // Gets mouse postion.
std::optional<POINT> get_mouse_pos(); std::optional<POINT> get_mouse_pos();
// Gets active window, filtering out all "non standard" windows like the taskbar, etc.
HWND get_filtered_active_window();
// Calculate sizes // Calculate sizes
int width(const RECT& rect); int width(const RECT& rect);
int height(const RECT& rect); int height(const RECT& rect);

View File

@@ -81,8 +81,6 @@ void OverlayWindow::enable() {
winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value)/100.0f); winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value)/100.0f);
target_state = new TargetState(pressTime.value); target_state = new TargetState(pressTime.value);
winkey_popup->initialize(); winkey_popup->initialize();
desktop = GetDesktopWindow();
shell = GetShellWindow();
} }
_enabled = true; _enabled = true;
} }
@@ -119,23 +117,7 @@ intptr_t OverlayWindow::signal_event(const wchar_t * name, intptr_t data) {
} }
void OverlayWindow::on_held() { void OverlayWindow::on_held() {
auto active_window = GetForegroundWindow(); auto active_window = get_filtered_active_window();
active_window = GetAncestor(active_window, GA_ROOT);
if (active_window == desktop || active_window == shell) {
active_window = nullptr;
}
auto window_styles = active_window ? GetWindowLong(active_window, GWL_STYLE) : 0;
if ((window_styles & WS_CHILD) || (window_styles & WS_DISABLED)) {
active_window = nullptr;
}
char class_name[256] = "";
GetClassNameA(active_window, class_name, 256);
if (strcmp(class_name, "SysListView32") == 0 ||
strcmp(class_name, "WorkerW") == 0 ||
strcmp(class_name, "Shell_TrayWnd") == 0 ||
strcmp(class_name, "Shell_SecondaryTrayWnd") == 0) {
active_window = nullptr;
}
winkey_popup->show(active_window); winkey_popup->show(active_window);
} }

View File

@@ -29,8 +29,6 @@ public:
private: private:
TargetState* target_state; TargetState* target_state;
D2DOverlayWindow *winkey_popup; D2DOverlayWindow *winkey_popup;
HWND desktop, shell;
HWND active_window;
bool _enabled = false; bool _enabled = false;
void init_settings(); void init_settings();