summaryrefslogtreecommitdiff
path: root/src/PowderToySDL.cpp
diff options
context:
space:
mode:
authormmbob <mmbob+github@outlook.com>2013-05-02 17:00:13 (GMT)
committer mmbob <mmbob+github@outlook.com>2013-05-02 17:00:13 (GMT)
commitdf14a771240ca11c17299d2137d474dee1fb3c6e (patch)
tree57b226db793eec233641f8eb10aa90827303fa28 /src/PowderToySDL.cpp
parent7bc321b17681c7633a6227129adb6dd593c190a2 (diff)
downloadpowder-df14a771240ca11c17299d2137d474dee1fb3c6e.zip
powder-df14a771240ca11c17299d2137d474dee1fb3c6e.tar.gz
LoadWindowPosition has a better default position
LoadWindowPosition now positions the window on the nearest monitor if the window is not inside a monitor.
Diffstat (limited to 'src/PowderToySDL.cpp')
-rw-r--r--src/PowderToySDL.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp
index d5d0949..ab76bdf 100644
--- a/src/PowderToySDL.cpp
+++ b/src/PowderToySDL.cpp
@@ -558,40 +558,47 @@ bool LoadWindowPosition()
int windowW = rcWindow.right - rcWindow.left - 1;
int windowH = rcWindow.bottom - rcWindow.top - 1;
- int windowX = Client::Ref().GetPrefInteger("WindowX", INT_MAX);
- int windowY = Client::Ref().GetPrefInteger("WindowY", INT_MAX);
+ int savedWindowX = Client::Ref().GetPrefInteger("WindowX", INT_MAX);
+ int savedWindowY = Client::Ref().GetPrefInteger("WindowY", INT_MAX);
+
+ // Center the window on the primary desktop by default
+ int newWindowX = (desktopWidth - windowW) / 2;
+ int newWindowY = (desktopHeight - windowH) / 2;
- bool setDefaultPos = true;
+ bool success = false;
- if (windowX != INT_MAX && windowY != INT_MAX)
+ if (savedWindowX != INT_MAX && savedWindowY != INT_MAX)
{
POINT windowPoints[] = {
- {windowX, windowY}, // Top-left
- {windowX + windowW, windowY + windowH} // Bottom-right
+ {savedWindowX, savedWindowY}, // Top-left
+ {savedWindowX + windowW, savedWindowY + windowH} // Bottom-right
};
MONITORINFO monitor;
monitor.cbSize = sizeof(monitor);
- if (GetMonitorInfo(MonitorFromPoint(windowPoints[0], MONITOR_DEFAULTTOPRIMARY), &monitor) != 0)
+ if (GetMonitorInfo(MonitorFromPoint(windowPoints[0], MONITOR_DEFAULTTONEAREST), &monitor) != 0)
{
// Only use the saved window position if it lies inside the visible screen
if (PtInRect(&monitor.rcMonitor, windowPoints[0]) && PtInRect(&monitor.rcMonitor, windowPoints[1]))
{
- SetWindowPos(sysInfo.window, 0, windowX, windowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
+ newWindowX = savedWindowX;
+ newWindowY = savedWindowY;
- setDefaultPos = false;
+ success = true;
+ }
+ else
+ {
+ // Center the window on the nearest monitor
+ newWindowX = monitor.rcMonitor.left + (monitor.rcMonitor.right - monitor.rcMonitor.left - windowW) / 2;
+ newWindowY = monitor.rcMonitor.top + (monitor.rcMonitor.bottom - monitor.rcMonitor.top - windowH) / 2;
}
}
}
- if (setDefaultPos)
- {
- // Center the window on the primary desktop by default
- SetWindowPos(sysInfo.window, 0, (desktopWidth - windowW) / 2, (desktopHeight - windowH) / 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
- }
+ SetWindowPos(sysInfo.window, 0, newWindowX, newWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
// True if we didn't use the default, i.e. the position was valid
- return !setDefaultPos;
+ return success;
}
return false;