Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stability issue #5

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -693,6 +712,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 @@ -1340,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)) {
Expand Down Expand Up @@ -1513,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);
Expand Down