Fix counting screen bottom point when restoring geometry

This commit is contained in:
Ilya Fedin 2021-06-30 01:25:43 +04:00 committed by John Preston
parent f07ee7f590
commit 7e6439e4f8

View file

@ -532,28 +532,30 @@ void MainWindow::initSize() {
if (position.w > w) position.w = w; if (position.w > w) position.w = w;
if (position.h > h) position.h = h; if (position.h > h) position.h = h;
const auto rightPoint = position.x + position.w; const auto rightPoint = position.x + position.w;
if (rightPoint > w) { const auto screenRightPoint = x + w;
const auto distance = rightPoint - w; if (rightPoint > screenRightPoint) {
const auto distance = rightPoint - screenRightPoint;
const auto newXPos = position.x - distance; const auto newXPos = position.x - distance;
if (newXPos >= x) { if (newXPos >= x) {
position.x = newXPos; position.x = newXPos;
} else { } else {
position.x = x; position.x = x;
const auto newRightPoint = position.x + position.w; const auto newRightPoint = position.x + position.w;
const auto newDistance = newRightPoint - w; const auto newDistance = newRightPoint - screenRightPoint;
position.w -= newDistance; position.w -= newDistance;
} }
} }
const auto bottomPoint = position.y + position.h; const auto bottomPoint = position.y + position.h;
if (bottomPoint > h) { const auto screenBottomPoint = y + h;
const auto distance = bottomPoint - h; if (bottomPoint > screenBottomPoint) {
const auto distance = bottomPoint - screenBottomPoint;
const auto newYPos = position.y - distance; const auto newYPos = position.y - distance;
if (newYPos >= y) { if (newYPos >= y) {
position.y = newYPos; position.y = newYPos;
} else { } else {
position.y = y; position.y = y;
const auto newBottomPoint = position.y + position.h; const auto newBottomPoint = position.y + position.h;
const auto newDistance = newBottomPoint - h; const auto newDistance = newBottomPoint - screenBottomPoint;
position.h -= newDistance; position.h -= newDistance;
} }
} }