Skip to content

Commit

Permalink
added hacks to survive Win+D
Browse files Browse the repository at this point in the history
ported corresponding code from old clock, seems still relevant

closes #3
  • Loading branch information
Kolcha committed Sep 7, 2024
1 parent a3b3f71 commit 9887c83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ void Application::createWindows()
}

std::ranges::for_each(_windows, [](auto& w) { w->show(); });
#if defined(Q_OS_WINDOWS)
if (!_cfg->global().getStayOnTop())
std::ranges::for_each(_windows, [](auto& w) { w->surviveWinDHack(); });
#endif
}

void Application::initUpdater()
Expand Down
1 change: 1 addition & 0 deletions app/gui/clock_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public slots:
#endif
#if defined(Q_OS_WINDOWS)
void runStayOnTopHacks();
void surviveWinDHack();
#endif
void setFullscreenDetect(bool en) { _detect_fullscreen = en; }

Expand Down
15 changes: 15 additions & 0 deletions app/platform/win/clock_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ void ClockWindow::runStayOnTopHacks()
if (!isActiveWindow()) raise();
}
}

// should be called once if stay on top is disabled
// window must be visible when this is called
void ClockWindow::surviveWinDHack()
{
// keep window visible after Win+D (show desktop)
// https://stackoverflow.com/questions/35045060/how-to-keep-window-visible-at-all-times-but-not-force-it-to-be-on-top
HWND hWndTmp = FindWindowEx(NULL, NULL, L"Progman", NULL);
if (hWndTmp) {
hWndTmp = FindWindowEx(hWndTmp, NULL, L"SHELLDLL_DefView", NULL);
if (hWndTmp) {
SetWindowLongPtr((HWND)this->winId(), GWLP_HWNDPARENT, (LONG_PTR)hWndTmp);
}
}
}

0 comments on commit 9887c83

Please sign in to comment.