diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index eba032ae9d09777ee8560aa9c0e6a7a1c357a316..e7bb8f6431350443298472181804be6f41e03569 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -1518,17 +1518,19 @@ bool GetClosestUnusedFileName(std::string &path, const char *extension) return true; } -bool WindowPositionValid(int x, int y) +bool WindowPositionValid(QRect rect) { vector monitors; GetMonitors(monitors); for (auto &monitor : monitors) { - int br_x = monitor.x + monitor.cx; - int br_y = monitor.y + monitor.cy; + int left = int(monitor.x); + int top = int(monitor.y); + int right = left + int(monitor.cx); + int bottom = top + int(monitor.cy); - if (x >= monitor.x && x < br_x && - y >= monitor.y && y < br_y) + if ((rect.left() - right) < 0 && (left - rect.right()) < 0 && + (rect.top() - bottom) < 0 && (top - rect.bottom()) < 0) return true; } diff --git a/UI/obs-app.hpp b/UI/obs-app.hpp index 4964f5f9a81fc81f7532cb8b8386d475b3d8b7c9..9c45803e0b2c6c6a594f23fb3dd5bd936b79ef28 100644 --- a/UI/obs-app.hpp +++ b/UI/obs-app.hpp @@ -166,7 +166,7 @@ inline const char *Str(const char *lookup) {return App()->GetString(lookup);} bool GetFileSafeName(const char *name, std::string &file); bool GetClosestUnusedFileName(std::string &path, const char *extension); -bool WindowPositionValid(int x, int y); +bool WindowPositionValid(QRect rect); static inline int GetProfilePath(char *path, size_t size, const char *file) { diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index c6f2e894b1a1fd998cd4eb42d7daeb5c4fa14f85..e7754615cf614b3bf5600e376e939da0e5746b89 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -137,9 +137,7 @@ OBSBasic::OBSBasic(QWidget *parent) restoreGeometry(byteArray); QRect windowGeometry = normalGeometry(); - int posx = windowGeometry.x(); - int posy = windowGeometry.y(); - if (!WindowPositionValid(posx, posy)) { + if (!WindowPositionValid(windowGeometry)) { QRect rect = App()->desktop()->availableGeometry(); setGeometry(QStyle::alignedRect( Qt::LeftToRight,