mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Move window filter to separate function, filter more windows.
This commit is contained in:
committed by
Bartosz Sosnowski
parent
a54e4299aa
commit
487c485911
@@ -31,6 +31,34 @@ std::optional<POINT> get_mouse_pos() {
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user