From 48f0c73f82a79203c82fa4543e59ae1fb7299d74 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 28 Sep 2016 22:26:28 -0700 Subject: [PATCH] UI: Use rect intersection test for validating position Instead of checking to see if the window's position is valid, check to see if the rectangles of the window and the monitor intersect via a rectangle intersection test. --- UI/obs-app.cpp | 12 +++++++----- UI/obs-app.hpp | 2 +- UI/window-basic-main.cpp | 4 +--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index eba032ae9..e7bb8f643 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 4964f5f9a..9c45803e0 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 c6f2e894b..e7754615c 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,