diff --git a/README.md b/README.md index e6c6b361..bf5d2dad 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ GLFW bundles a number of dependencies in the `deps/` directory. - Added `glfwCreateCursor`, `glfwDestroyCursor` and `glfwSetCursor` for managing custom system cursors - Added `GLFWimage` struct for passing 32-bit RGBA images - - Added native monitor handle access to native API + - Added monitor and adapter identifier access to native API - Added `glfwSetDropCallback` and `GLFWdropfun` for receiving dropped files - Added `glfwPostEmptyEvent` for allowing secondary threads to cause `glfwWaitEvents` to return diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index c00d57c7..881f5049 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -108,9 +108,9 @@ extern "C" { *************************************************************************/ #if defined(GLFW_EXPOSE_NATIVE_WIN32) -/*! @brief Returns the display device name of the specified monitor. +/*! @brief Returns the adapter device name of the specified monitor. * - * @return The UTF-8 encoded display device name (`DISPLAY_DEVICE.DeviceName`) + * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) * of the specified monitor, or `NULL` if an [error](@ref error_handling) * occurred. * @@ -122,6 +122,22 @@ extern "C" { * * @ingroup native */ +GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); + +/*! @brief Returns the display device name of the specified monitor. + * + * @return The UTF-8 encoded display device name (for example + * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @par Thread Safety + * This function may be called from any thread. Access is not synchronized. + * + * @par History + * Added in GLFW 3.1. + * + * @ingroup native + */ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); /*! @brief Returns the `HWND` of the specified window. @@ -222,6 +238,21 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); */ GLFWAPI Display* glfwGetX11Display(void); +/*! @brief Returns the `RRCrtc` of the specified monitor. + * + * @return The `RRCrtc` of the specified monitor, or `None` if an + * [error](@ref error_handling) occurred. + * + * @par Thread Safety + * This function may be called from any thread. Access is not synchronized. + * + * @par History + * Added in GLFW 3.1. + * + * @ingroup native + */ +GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); + /*! @brief Returns the `RROutput` of the specified monitor. * * @return The `RROutput` of the specified monitor, or `None` if an diff --git a/src/win32_monitor.c b/src/win32_monitor.c index ee44d5d3..0690dc1f 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -160,10 +160,16 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) wcscpy(monitors[found]->win32.adapterName, adapter.DeviceName); wcscpy(monitors[found]->win32.displayName, display.DeviceName); + WideCharToMultiByte(CP_UTF8, 0, + adapter.DeviceName, -1, + monitors[found]->win32.publicAdapterName, + sizeof(monitors[found]->win32.publicAdapterName), + NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, display.DeviceName, -1, - monitors[found]->win32.nativeName, - sizeof(monitors[found]->win32.nativeName), + monitors[found]->win32.publicDisplayName, + sizeof(monitors[found]->win32.publicDisplayName), NULL, NULL); if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE && @@ -326,10 +332,17 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) ////// GLFW native API ////// ////////////////////////////////////////////////////////////////////////// +GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* handle) +{ + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + return monitor->win32.publicAdapterName; +} + GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return monitor->win32.nativeName; + return monitor->win32.publicDisplayName; } diff --git a/src/win32_platform.h b/src/win32_platform.h index 465e487d..5eb61d37 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -205,7 +205,8 @@ typedef struct _GLFWmonitorWin32 // This size matches the static size of DISPLAY_DEVICE.DeviceName WCHAR adapterName[32]; WCHAR displayName[32]; - char nativeName[64]; + char publicAdapterName[64]; + char publicDisplayName[64]; GLboolean modeChanged; } _GLFWmonitorWin32; diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 36d914d6..fb6b0ef6 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -465,6 +465,13 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) ////// GLFW native API ////// ////////////////////////////////////////////////////////////////////////// +GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* handle) +{ + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(None); + return monitor->x11.crtc; +} + GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle;