From ee5f30ea8ff17c3d61dae41c5a89679718768986 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 Jan 2013 19:10:17 +0100 Subject: [PATCH] Replaced glfwGetMonitorParam with glfwGetMonitor*. Having one way to retrieve the cursor position and another (more verbose) way to retrieve the monitor position is inconsistent. Having them both work the same way is the least surprising thing. The expected glfwGetMonitorSize function gets an added Physical in its name so users won't confuse it with glfwGetVideoMode. --- README.md | 4 ++-- include/GL/glfw3.h | 31 ++++++++++++------------------- src/monitor.c | 33 +++++++++++++++++++-------------- tests/events.c | 10 ++++++---- tests/modes.c | 11 +++++------ 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index fc678895..a32dcebc 100644 --- a/README.md +++ b/README.md @@ -226,8 +226,8 @@ GLFW. handle * Added `glfwGetMonitors` and `glfwGetPrimaryMonitor` for enumerating available monitors - * Added `glfwGetMonitorParam` and `glfwGetMonitorName` for retrieving monitor - properties + * Added `glfwGetMonitorPos`, `glfwGetMonitorPhysicalSize` and + `glfwGetMonitorName` for retrieving monitor properties * Added `glfwSetMonitorCallback` and `GLFWmonitorfun` for notification of changes in the set of available monitors * Added `GLFWwindow` and updated window-related functions and callbacks to take diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 91f2188a..e6dc60b2 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -539,11 +539,6 @@ extern "C" { #define GLFW_GAMMA_RAMP_SIZE 256 -#define GLFW_MONITOR_WIDTH_MM 0x00060001 -#define GLFW_MONITOR_HEIGHT_MM 0x00060002 -/* reuse GLFW_POSITION_X */ -/* reuse GLFW_POSITION_Y */ - #define GLFW_CONNECTED 0x00061000 #define GLFW_DISCONNECTED 0x00061001 @@ -841,23 +836,21 @@ GLFWAPI GLFWmonitor** glfwGetMonitors(int* count); */ GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void); -/*! @brief Returns a property of the specified monitor. +/*! @brief Returns the position of the monitor's viewport on the virtual screen. * @param[in] monitor The monitor to query. - * @param[in] param The property whose value to return. - * @return The value of the property, or zero if an error occurred. + * @param[out] xpos The monitor x-coordinate. + * @param[out] ypos The monitor y-coordinate. * @ingroup monitor - * - * @par Monitor properties - * - * The @ref GLFW_MONITOR_WIDTH_MM and @ref GLFW_MONITOR_HEIGHT_MM properties - * indicate the physical with, in mm, of the monitor. - * - * The @ref GLFW_POSITION_X and @ref GLFW_POSITION_Y properties indiciate the - * position, in virtual screen coordinates, of the monitor's viewport. - * - * @sa glfwGetVideoMode, glfwGetVideoModes, glfwGetMonitorName */ -GLFWAPI int glfwGetMonitorParam(GLFWmonitor* monitor, int param); +GLFWAPI void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos); + +/*! @brief Returns the physical size of the monitor. + * @param[in] monitor The monitor to query. + * @param[out] width The width, in mm, of the monitor's display + * @param[out] height The height, in mm, of the monitor's display. + * @ingroup monitor + */ +GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height); /*! @brief Returns the name of the specified monitor. * @param[in] monitor The monitor to query. diff --git a/src/monitor.c b/src/monitor.c index 168c3987..e3a5ce33 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -312,31 +312,36 @@ GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) return (GLFWmonitor*) primary; } -GLFWAPI int glfwGetMonitorParam(GLFWmonitor* handle, int param) +GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; if (!_glfwInitialized) { _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; + return; } - switch (param) + if (xpos) + *xpos = monitor->positionX; + if (ypos) + *ypos = monitor->positionY; +} + +GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* height) +{ + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + + if (!_glfwInitialized) { - case GLFW_MONITOR_WIDTH_MM: - return monitor->widthMM; - case GLFW_MONITOR_HEIGHT_MM: - return monitor->heightMM; - case GLFW_POSITION_X: - return monitor->positionX; - case GLFW_POSITION_Y: - return monitor->positionY; + _glfwInputError(GLFW_NOT_INITIALIZED, NULL); + return; } - _glfwInputError(GLFW_INVALID_ENUM, - "glfwGetMonitorParam: Invalid enum value for 'param' parameter"); - return 0; + if (width) + *width = monitor->widthMM; + if (height) + *height = monitor->heightMM; } GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) diff --git a/tests/events.c b/tests/events.c index 0bea0064..19716891 100644 --- a/tests/events.c +++ b/tests/events.c @@ -344,17 +344,19 @@ void monitor_callback(GLFWmonitor* monitor, int event) { if (event == GLFW_CONNECTED) { + int x, y, widthMM, heightMM; GLFWvidmode mode = glfwGetVideoMode(monitor); + glfwGetMonitorPos(monitor, &x, &y); + glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); + printf("%08x at %0.3f: Monitor %s (%ix%i at %ix%i, %ix%i mm) was connected\n", counter++, glfwGetTime(), glfwGetMonitorName(monitor), mode.width, mode.height, - glfwGetMonitorParam(monitor, GLFW_POSITION_X), - glfwGetMonitorParam(monitor, GLFW_POSITION_Y), - glfwGetMonitorParam(monitor, GLFW_MONITOR_WIDTH_MM), - glfwGetMonitorParam(monitor, GLFW_MONITOR_HEIGHT_MM)); + x, y, + widthMM, heightMM); } else { diff --git a/tests/modes.c b/tests/modes.c index 64c63b0e..d43afadf 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -92,20 +92,19 @@ static void key_callback(GLFWwindow* window, int key, int action) static void list_modes(GLFWmonitor* monitor) { - int count, widthMM, heightMM, dpi, i; + int count, x, y, widthMM, heightMM, dpi, i; GLFWvidmode mode = glfwGetVideoMode(monitor); const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); + glfwGetMonitorPos(monitor, &x, &y); + glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); + printf("Name: %s (%s)\n", glfwGetMonitorName(monitor), glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary"); printf("Current mode: %s\n", format_mode(&mode)); - printf("Virtual position: %i %i\n", - glfwGetMonitorParam(monitor, GLFW_POSITION_X), - glfwGetMonitorParam(monitor, GLFW_POSITION_Y)); + printf("Virtual position: %i %i\n", x, y); - widthMM = glfwGetMonitorParam(monitor, GLFW_MONITOR_WIDTH_MM); - heightMM = glfwGetMonitorParam(monitor, GLFW_MONITOR_HEIGHT_MM); dpi = (int) ((float) mode.width * 25.4f / (float) widthMM); printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi);