From 2d2eaa3eff7f83a7a950da636608a2e791f635a7 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 21 Mar 2021 12:39:33 -0700 Subject: [PATCH] [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. --- wpigui/src/main/native/cpp/wpigui.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wpigui/src/main/native/cpp/wpigui.cpp b/wpigui/src/main/native/cpp/wpigui.cpp index 9deb9e7206..3843522e55 100644 --- a/wpigui/src/main/native/cpp/wpigui.cpp +++ b/wpigui/src/main/native/cpp/wpigui.cpp @@ -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); }