mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpigui] Ensure window will be initially visible (#3256)
Only set the initial window position if the window X/Y postion is within one of the connected monitor work areas.
This commit is contained in:
@@ -213,7 +213,23 @@ bool gui::Initialize(const char* title, int width, int height) {
|
||||
|
||||
// Update window settings
|
||||
if (gContext->xPos != -1 && gContext->yPos != -1) {
|
||||
glfwSetWindowPos(gContext->window, gContext->xPos, gContext->yPos);
|
||||
// check to make sure the position isn't off-screen
|
||||
bool found = false;
|
||||
int monCount;
|
||||
GLFWmonitor** monitors = glfwGetMonitors(&monCount);
|
||||
for (int i = 0; i < monCount; ++i) {
|
||||
int monXPos, monYPos, monWidth, monHeight;
|
||||
glfwGetMonitorWorkarea(monitors[i], &monXPos, &monYPos, &monWidth,
|
||||
&monHeight);
|
||||
if (gContext->xPos >= monXPos && gContext->xPos < (monXPos + monWidth) &&
|
||||
gContext->yPos >= monYPos && gContext->yPos < (monYPos + monHeight)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
glfwSetWindowPos(gContext->window, gContext->xPos, gContext->yPos);
|
||||
}
|
||||
glfwShowWindow(gContext->window);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user