| 34 | #include <cstdlib> |
| 35 | |
| 36 | void LoadWindowPosition() |
| 37 | { |
| 38 | if (Client::Ref().IsFirstRun()) |
| 39 | { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | auto &prefs = GlobalPrefs::Ref(); |
| 44 | int savedWindowX = prefs.Get("WindowX", INT_MAX); |
| 45 | int savedWindowY = prefs.Get("WindowY", INT_MAX); |
| 46 | |
| 47 | int borderTop, borderLeft; |
| 48 | SDL_GetWindowBordersSize(sdl_window, &borderTop, &borderLeft, nullptr, nullptr); |
| 49 | // Sometimes (Windows), the border size may not be reported for 200+ frames |
| 50 | // So just have a default of 5 to ensure the window doesn't get stuck where it can't be moved |
| 51 | if (borderTop == 0) |
| 52 | borderTop = 5; |
| 53 | |
| 54 | int numDisplays = SDL_GetNumVideoDisplays(); |
| 55 | SDL_Rect displayBounds; |
| 56 | bool ok = false; |
| 57 | for (int i = 0; i < numDisplays; i++) |
| 58 | { |
| 59 | SDL_GetDisplayBounds(i, &displayBounds); |
| 60 | if (savedWindowX + borderTop > displayBounds.x && savedWindowY + borderLeft > displayBounds.y && |
| 61 | savedWindowX + borderTop < displayBounds.x + displayBounds.w && |
| 62 | savedWindowY + borderLeft < displayBounds.y + displayBounds.h) |
| 63 | { |
| 64 | ok = true; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | if (ok) |
| 69 | SDL_SetWindowPosition(sdl_window, savedWindowX + borderLeft, savedWindowY + borderTop); |
| 70 | } |
| 71 | |
| 72 | void SaveWindowPosition() |
| 73 | { |
no test coverage detected