Skip to content

Commit

Permalink
Fix stability issue (prabirshrestha#5)
Browse files Browse the repository at this point in the history
* Do not manage non responding windows

* Dont manage hanging and debugged windows

---------

Co-authored-by: Nir Lichtman <[email protected]>
  • Loading branch information
2 people authored and zelleb committed Jun 13, 2024
1 parent 5bc6db1 commit a1a6e90
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions src/dwm-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -666,13 +667,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);
Expand All @@ -684,6 +691,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) {
Expand Down Expand Up @@ -719,6 +738,14 @@ ismanageable(HWND hwnd) {
if (hwnd == 0)
return false;

if (IsHungAppWindow(hwnd)) {
return false;
}

if (isclientdebugged(hwnd)) {
return false;
}

if (getclient(hwnd))
return true;

Expand Down Expand Up @@ -1380,6 +1407,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)) {
Expand Down Expand Up @@ -1566,9 +1606,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);
Expand Down

0 comments on commit a1a6e90

Please sign in to comment.