diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index aa5f89dcd..0fc023ff3 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -1483,6 +1483,23 @@ bool GetClosestUnusedFileName(std::string &path, const char *extension) return true; } +bool WindowPositionValid(int x, int y) +{ + vector monitors; + GetMonitors(monitors); + + for (auto &monitor : monitors) { + int br_x = monitor.x + monitor.cx; + int br_y = monitor.y + monitor.cy; + + if (x >= monitor.x && x < br_x && + y >= monitor.y && y < br_y) + return true; + } + + return false; +} + static inline bool arg_is(const char *arg, const char *long_form, const char *short_form) { diff --git a/obs/obs-app.hpp b/obs/obs-app.hpp index ae683cb19..8eac175f5 100644 --- a/obs/obs-app.hpp +++ b/obs/obs-app.hpp @@ -147,6 +147,8 @@ 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); + static inline int GetProfilePath(char *path, size_t size, const char *file) { OBSMainWindow *window = reinterpret_cast( diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 771a81728..20eb76511 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -132,6 +132,9 @@ OBSBasic::OBSBasic(QWidget *parent) int posy = config_get_int(App()->GlobalConfig(), "BasicWindow", "posy"); + if (!WindowPositionValid(posx, posy)) + posx = posy = 0; + setGeometry(posx, posy, width, height); }