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 restoring minimized window in multi-monitor. #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions bitsdojo_window_windows/windows/bitsdojo_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,29 @@ namespace bitsdojo_window {
return monitorInfo.rcWork;
}

RECT getWorkingScreenRectForRect(const RECT& rcWnd) {
MONITORINFO monitorInfo = {};
monitorInfo.cbSize = DWORD(sizeof(MONITORINFO));
auto monitor = MonitorFromRect(&rcWnd, MONITOR_DEFAULTTONEAREST);
GetMonitorInfoW(monitor, static_cast<LPMONITORINFO>(&monitorInfo));
return monitorInfo.rcWork;
}
RECT getWorkingScreenRectForWindowPos(WINDOWPOS* winPos) {
RECT rcWnd = { winPos->x, winPos->y, winPos->x + winPos->cx, winPos->y + winPos->cy };
return getWorkingScreenRectForRect(rcWnd);
}
void adjustPositionOnRestoreByMove(HWND window, WINDOWPOS* winPos) {
if (restore_by_moving == FALSE) return;

auto screenRect = getWorkingScreenRectForWindow(window);
auto screenRect = getWorkingScreenRectForWindowPos(winPos);

if (winPos->y < screenRect.top) {
winPos->y = screenRect.top;
}
}

void adjustMaximizedSize(HWND window, WINDOWPOS* winPos) {
auto screenRect = getWorkingScreenRectForWindow(window);
auto screenRect = getWorkingScreenRectForWindowPos(winPos);
if ((winPos->x < screenRect.left) &&
(winPos->y < screenRect.top) &&
(winPos->cx > (screenRect.right - screenRect.left))
Expand All @@ -253,7 +264,7 @@ namespace bitsdojo_window {
}

void adjustMaximizedRects(HWND window, NCCALCSIZE_PARAMS* params) {
auto screenRect = getWorkingScreenRectForWindow(window);
auto screenRect = getWorkingScreenRectForRect(params->rgrc[0]);
for (int i = 0; i < 3; i++) {
if ((params->rgrc[i].left < screenRect.left) &&
(params->rgrc[i].top < screenRect.top) &&
Expand Down