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
parent
0157d02564
commit
8932bd39d1
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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*>(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue