From b121a4c9d649ea45d932df023a7192e24d61d06c Mon Sep 17 00:00:00 2001 From: Nir Lichtman Date: Sun, 14 Jan 2024 09:22:53 +0200 Subject: [PATCH] Dont manage hanging and debugged windows --- src/dwm-win32.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/dwm-win32.c b/src/dwm-win32.c index c6ba327..7c0c133 100644 --- a/src/dwm-win32.c +++ b/src/dwm-win32.c @@ -114,6 +114,7 @@ struct Client { bool ignoreborder; bool border; bool wasvisible; + bool ishanging; bool isfixed, isurgent; // XXX: useless? bool iscloaked; // WinStore apps Client *next; @@ -640,13 +641,19 @@ getclienttitle(HWND hwnd) { return buf; } +HANDLE +getclientprocess(HWND hwnd) { + DWORD processid = 0; + GetWindowThreadProcessId(hwnd, &processid); + HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processid); + return hProc; +} + LPWSTR getclientprocessname(HWND hwnd) { - DWORD processid = 0; DWORD buf_size = MAX_PATH; static wchar_t buf[MAX_PATH]; - GetWindowThreadProcessId(hwnd, &processid); - HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processid); + HANDLE hProc = getclientprocess(hwnd); if (hProc) { if (QueryFullProcessImageNameW(hProc, 0, buf, &buf_size)) { CloseHandle(hProc); @@ -658,6 +665,18 @@ getclientprocessname(HWND hwnd) { return NULL; } +BOOL +isclientdebugged(HWND hwnd) { + BOOL debuggerPresent = false; + HANDLE hProc = getclientprocess(hwnd); + if (!CheckRemoteDebuggerPresent(hProc, &debuggerPresent)) { + CloseHandle(hProc); + return false; + } + + CloseHandle(hProc); + return debuggerPresent; +} HWND getroot(HWND hwnd) { @@ -697,6 +716,10 @@ ismanageable(HWND hwnd) { return false; } + if (isclientdebugged(hwnd)) { + return false; + } + if (getclient(hwnd)) return true; @@ -1344,6 +1367,19 @@ void showhide(Client *c) { if (!c) return; + + if (isclientdebugged(c->hwnd)) { + c->ishanging = true; + unmanage(c); + return; + } + + if (IsHungAppWindow(c->hwnd)) { + c->ishanging = true; + unmanage(c); + return; + } + /* XXX: is the order of showing / hidding important? */ if (!ISVISIBLE(c)) { if (IsWindowVisible(c->hwnd)) { @@ -1517,9 +1553,11 @@ writelog(const Arg *arg) { void unmanage(Client *c) { debug(L" unmanage %s\n", getclienttitle(c->hwnd)); - if (c->wasvisible) + + // Don't want to touch Window related functions on hanging windows + if (c->wasvisible && !c->ishanging) setvisibility(c->hwnd, true); - if (!c->isfloating) + if (!c->isfloating && !c->ishanging) setborder(c, true); detach(c); detachstack(c);