UI: Check to ensure window starts up inside a monitor

Fixes an issue where the main window would load off-screen if its last
saved position was inside a monitor that no longer exists.
master
jp9000 2016-05-05 15:31:35 -07:00
parent 0157d02564
commit 8932bd39d1
3 changed files with 22 additions and 0 deletions

View File

@ -1483,6 +1483,23 @@ bool GetClosestUnusedFileName(std::string &path, const char *extension)
return true;
}
bool WindowPositionValid(int x, int y)
{
vector<MonitorInfo> 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)
{

View File

@ -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<OBSMainWindow*>(

View File

@ -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);
}