diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 1f0fd344..f973b33f 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -1060,14 +1060,13 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count); * on whether it is focused. * * @param[in] monitor The monitor to query. - * @return The current mode of the monitor, or a struct cleared to all zeroes - * if an error occurred. + * @return The current mode of the monitor, or `NULL` if an error occurred. * * @sa glfwGetVideoModes * * @ingroup monitor */ -GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* monitor); +GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor); /*! @brief Generates a gamma ramp and sets it for the specified monitor. * diff --git a/src/internal.h b/src/internal.h index 8554a6a3..63559ccb 100644 --- a/src/internal.h +++ b/src/internal.h @@ -248,6 +248,7 @@ struct _GLFWmonitor GLFWvidmode* modes; int modeCount; + GLFWvidmode currentMode; GLFWgammaramp originalRamp; GLFWgammaramp currentRamp; diff --git a/src/monitor.c b/src/monitor.c index 9bdcc186..dab71d87 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -322,14 +322,13 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) return monitor->modes; } -GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* handle) +GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - GLFWvidmode mode = { 0, 0, 0, 0, 0 }; - _GLFW_REQUIRE_INIT_OR_RETURN(mode); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - _glfwPlatformGetVideoMode(monitor, &mode); - return mode; + _glfwPlatformGetVideoMode(monitor, &monitor->currentMode); + return &monitor->currentMode; } diff --git a/tests/events.c b/tests/events.c index aa27530a..096e2807 100644 --- a/tests/events.c +++ b/tests/events.c @@ -371,7 +371,7 @@ void monitor_callback(GLFWmonitor* monitor, int event) if (event == GLFW_CONNECTED) { int x, y, widthMM, heightMM; - GLFWvidmode mode = glfwGetVideoMode(monitor); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwGetMonitorPos(monitor, &x, &y); glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); @@ -380,7 +380,7 @@ void monitor_callback(GLFWmonitor* monitor, int event) counter++, glfwGetTime(), glfwGetMonitorName(monitor), - mode.width, mode.height, + mode->width, mode->height, x, y, widthMM, heightMM); } diff --git a/tests/gamma.c b/tests/gamma.c index 6a2cda5f..5e52859f 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -127,9 +127,9 @@ int main(int argc, char** argv) if (monitor) { - GLFWvidmode mode = glfwGetVideoMode(monitor); - width = mode.width; - height = mode.height; + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + width = mode->width; + height = mode->height; } else { diff --git a/tests/iconify.c b/tests/iconify.c index 68b28523..7f61cda0 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -117,9 +117,9 @@ int main(int argc, char** argv) if (monitor) { - GLFWvidmode mode = glfwGetVideoMode(monitor); - width = mode.width; - height = mode.height; + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + width = mode->width; + height = mode->height; } else { diff --git a/tests/modes.c b/tests/modes.c index 17d9fa0e..6bb50893 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -82,7 +82,7 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods) static void list_modes(GLFWmonitor* monitor) { int count, x, y, widthMM, heightMM, dpi, i; - GLFWvidmode mode = glfwGetVideoMode(monitor); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); glfwGetMonitorPos(monitor, &x, &y); @@ -91,10 +91,10 @@ static void list_modes(GLFWmonitor* monitor) printf("Name: %s (%s)\n", glfwGetMonitorName(monitor), glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary"); - printf("Current mode: %s\n", format_mode(&mode)); + printf("Current mode: %s\n", format_mode(mode)); printf("Virtual position: %i %i\n", x, y); - dpi = (int) ((float) mode.width * 25.4f / (float) widthMM); + dpi = (int) ((float) mode->width * 25.4f / (float) widthMM); printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi); printf("Modes:\n");