From f50e43d47a282ba12fe8e76f5252566b8383befb Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 01:32:12 -0400 Subject: [PATCH 01/20] Moved variable definition to the function beginning. --- src/input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/input.c b/src/input.c index 04c835a4..983a05ee 100644 --- a/src/input.c +++ b/src/input.c @@ -191,6 +191,8 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset) GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode) { + int centerPosX; + int centerPosY; _GLFWwindow* window = (_GLFWwindow*) handle; if (!_glfwInitialized) @@ -210,8 +212,8 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode) if (window->cursorMode == mode) return; - int centerPosX = window->width / 2; - int centerPosY = window->height / 2; + centerPosX = window->width / 2; + centerPosY = window->height / 2; if (mode == GLFW_CURSOR_CAPTURED) { From 71af8b190ffc2dd8c6056d4ad507c374ea2717e6 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 01:40:36 -0400 Subject: [PATCH 02/20] Renamed or implemented missing methods for cursor specific features. --- src/win32_window.c | 52 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 1bfef9f5..dbeffe20 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -33,6 +33,8 @@ #include #include +void showMouseCursor(_GLFWwindow* window); +void captureMouseCursor(_GLFWwindow* window); //======================================================================== // Convert BPP to RGB bits based on "best guess" @@ -1850,18 +1852,11 @@ void _glfwPlatformWaitEvents(void) // Hide mouse cursor (lock it) //======================================================================== -void _glfwPlatformHideMouseCursor(_GLFWwindow* window) +void hideMouseCursor(_GLFWwindow* window) { - RECT ClipWindowRect; - ShowCursor(FALSE); - // Clip cursor to the window - if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) - ClipCursor(&ClipWindowRect); - - // Capture cursor to user window - SetCapture(window->Win32.handle); + captureMouseCursor(window); } @@ -1869,7 +1864,7 @@ void _glfwPlatformHideMouseCursor(_GLFWwindow* window) // Show mouse cursor (unlock it) //======================================================================== -void _glfwPlatformShowMouseCursor(_GLFWwindow* window) +void showMouseCursor(_GLFWwindow* window) { // Un-capture cursor ReleaseCapture(); @@ -1880,6 +1875,22 @@ void _glfwPlatformShowMouseCursor(_GLFWwindow* window) ShowCursor(TRUE); } +//======================================================================== +// Capture mouse cursor +//======================================================================== + +static void captureMouseCursor(_GLFWwindow* window) +{ + RECT ClipWindowRect; + + // Clip cursor to the window + if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) + ClipCursor(&ClipWindowRect); + + // Capture cursor to user window + SetCapture(window->Win32.handle); +} + //======================================================================== // Set physical mouse cursor position @@ -1897,3 +1908,24 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) SetCursorPos(pos.x, pos.y); } +//======================================================================== +// Set physical mouse cursor mode +//======================================================================== + +void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) +{ + switch (mode) + { + case GLFW_CURSOR_NORMAL: + showMouseCursor(window); + break; + case GLFW_CURSOR_HIDDEN: + hideMouseCursor(window); + break; + case GLFW_CURSOR_CAPTURED: + captureMouseCursor(window); + break; + } +} + + From d5def558d39e739f69c3a1091eb989ad21573a1e Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 01:48:42 -0400 Subject: [PATCH 03/20] Renamed struct member to match x11 naming. --- src/win32_platform.h | 2 +- src/win32_window.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index db5b82ae..6b61cb77 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -251,7 +251,7 @@ typedef struct _GLFWwindowWin32 // Various platform specific internal variables int desiredRefreshRate; // Desired vertical monitor refresh rate - GLboolean mouseMoved; + GLboolean cursorCentered; int oldMouseX, oldMouseY; } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index dbeffe20..b9a6a6a3 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1763,7 +1763,7 @@ void _glfwPlatformPollEvents(void) window = _glfwLibrary.activeWindow; if (window) { - window->Win32.mouseMoved = GL_FALSE; + window->Win32.cursorCentered = GL_TRUE; window->Win32.oldMouseX = window->width / 2; window->Win32.oldMouseY = window->height / 2; } From 021ce1f7f4c511d84f2edf2dae74dca1ad6af503 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 01:49:35 -0400 Subject: [PATCH 04/20] Added windows build intermediate files to .gitignore. --- .gitignore | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bccab087..e3cefe05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,40 @@ +*.a +CMakeCache.txt CMakeFiles cmake_install.cmake -CMakeCache.txt -Makefile cmake_uninstall.cmake -src/config.h -src/x11/libglfw.pc -src/win32/libglfw.pc -src/cocoa/libglfw.pc +*.dll +examples/boing +examples/gears +examples/heightmap +examples/splitview +examples/triangle +examples/wave +*.exe +*.exp +*.ilk +*.lib +libglfw.pc +Makefile +*.manifest +*.pdb +*.res +*.resource.txt *.so -*.a +src/config.h +*.swp +tests/accuracy +tests/defaults +tests/events +tests/fsaa +tests/fsfocus +tests/gamma +tests/iconify +tests/joysticks +tests/listmodes +tests/peter +tests/reopen +tests/sharing +tests/tearing +tests/version +tests/windows From 3cb4dea453a8e564b1e92f4753b7f597d7ab6f4a Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Fri, 18 Feb 2011 22:59:40 -0500 Subject: [PATCH 05/20] Fixed implementation on win32 platform for iteration of video modes. --- src/internal.h | 1 + src/win32_fullscreen.c | 99 ++++++++++++++++++------------------------ 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/internal.h b/src/internal.h index 83559ecc..c8bdb9aa 100644 --- a/src/internal.h +++ b/src/internal.h @@ -328,6 +328,7 @@ void _glfwFree(void* ptr); // Fullscren management (fullscreen.c) void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); +int _glfwCompareVideoModes(const void* firstPtr, const void* secondPtr); // Error handling (error.c) void _glfwSetError(int error, const char* description); diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index de3d898b..f8cc0dbc 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -184,69 +184,56 @@ void _glfwRestoreVideoMode(void) int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) { - int count, success, mode, i, j; - int m1, m2, bpp, r, g, b; - DEVMODE dm; + DEVMODE deviceMode; + DWORD deviceModeNum; - // Loop through all video modes and extract all the UNIQUE modes - count = 0; - mode = 0; + GLFWvidmode* vidModes; + int vidModesCount; + GLFWvidmode vidMode; - do + deviceMode.dmSize = sizeof(DEVMODE); + deviceModeNum = 0; + + vidModes = NULL; + vidModesCount = 0; + + while (EnumDisplaySettings(NULL, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) { - // Get video mode properties - dm.dmSize = sizeof(DEVMODE); - success = EnumDisplaySettings(NULL, mode, &dm); + deviceModeNum++; - // Is it a valid mode? (only list depths >= 15 bpp) - if (success && dm.dmBitsPerPel >= 15) + if (deviceMode.dmBitsPerPel < 15) { - // Convert to RGB, and back to bpp ("mask out" alpha bits etc) - _glfwSplitBPP(dm.dmBitsPerPel, &r, &g, &b); - bpp = r + g + b; - - // Mode "code" for this mode - m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight); - - // Insert mode in list (sorted), and avoid duplicates - for (i = 0; i < count; i++) - { - // Mode "code" for already listed mode - bpp = list[i].redBits + list[i].greenBits + list[i].blueBits; - m2 = (bpp << 25) | (list[i].width * list[i].height); - if (m1 <= m2) - break; - } - - // New entry at the end of the list? - if (i >= count) - { - list[count].width = dm.dmPelsWidth; - list[count].height = dm.dmPelsHeight; - list[count].redBits = r; - list[count].greenBits = g; - list[count].blueBits = b; - count ++; - } - // Insert new entry in the list? - else if (m1 < m2) - { - for (j = count; j > i; j--) - list[j] = list[j - 1]; - - list[i].width = dm.dmPelsWidth; - list[i].height = dm.dmPelsHeight; - list[i].redBits = r; - list[i].greenBits = g; - list[i].blueBits = b; - count++; - } + continue; } - mode++; - } - while (success && (count < maxcount)); - return count; + vidMode.height = deviceMode.dmPelsHeight; + vidMode.width = deviceMode.dmPelsWidth; + // Convert to RGB, and back to bpp ("mask out" alpha bits etc) + _glfwSplitBPP(deviceMode.dmBitsPerPel, + &vidMode.redBits, + &vidMode.greenBits, + &vidMode.blueBits); + + // skip duplicates. + if (vidModes && bsearch(&vidMode, vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes)) + { + continue; + } + + vidModes = realloc(vidModes, sizeof(GLFWvidmode) * ++vidModesCount); + memcpy(vidModes + (vidModesCount - 1), &vidMode, sizeof(GLFWvidmode)); + + qsort(vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes); + } + + if (list && maxcount) + { + memcpy(list, vidModes, sizeof(GLFWvidmode) * min(vidModesCount, maxcount)); + } + + free(vidModes); + + return vidModesCount; } From b7d1d35c208e82769098d06c9edb64b7c67d18ae Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Fri, 18 Feb 2011 23:01:15 -0500 Subject: [PATCH 06/20] Added library search for math and realtime library in test and example projects for x11 platform. --- examples/CMakeLists.txt | 8 +++++++- tests/CMakeLists.txt | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 345631cc..292db1ce 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,8 +1,14 @@ # This line is used to link with static libraries # Note that the library list should be updated to be obtained from -# the main CMakeLists.txt +# the main CMakeLists.txt link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) +if (UNIX AND NOT APPLE AND NOT CYGWIN) + find_library(MATH_LIBRARY m) + find_library(REALTIME_LIBRARY rt) + link_libraries(${MATH_LIBRARY} ${REALTIME_LIBRARY}) +endif (UNIX AND NOT APPLE AND NOT CYGWIN) + include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ef07acc..f4c99bb2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,12 @@ link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) +if (UNIX AND NOT APPLE AND NOT CYGWIN) + find_library(MATH_LIBRARY m) + find_library(REALTIME_LIBRARY rt) + link_libraries(${MATH_LIBRARY} ${REALTIME_LIBRARY}) +endif (UNIX AND NOT APPLE AND NOT CYGWIN) + include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) From beacbb3447e53395f29275b1589a6cf58b10da03 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 7 May 2011 10:53:50 +0200 Subject: [PATCH 07/20] Implemented display iteration for x11. Added attributes and queries for physical size, name and logical position. Updated test executable. --- include/GL/glfw3.h | 30 ++++++++++- src/CMakeLists.txt | 6 +-- src/display.c | 111 +++++++++++++++++++++++++++++++++++++++++ src/fullscreen.c | 2 +- src/internal.h | 21 ++++++++ src/x11_display.c | 121 +++++++++++++++++++++++++++++++++++++++++++++ src/x11_init.c | 4 ++ src/x11_platform.h | 4 ++ tests/listmodes.c | 30 ++++++++--- 9 files changed, 316 insertions(+), 13 deletions(-) create mode 100644 src/display.c create mode 100644 src/x11_display.c diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 1f52e742..887540ac 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -539,8 +539,36 @@ GLFWAPI int glfwGetError(void); GLFWAPI const char* glfwErrorString(int error); GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun); +/* Display constants */ +#define GLFW_DISPLAY_INVALID_HANDLE (NULL) +#define GLFW_DISPLAY_CONNECTED 0 +#define GLFW_DISPLAY_DISCONNECTED 1 +#define GLFW_DISPLAY_PARAM_S_NAME 0 +#define GLFW_DISPLAY_PARAM_I_PHYS_WIDTH 1 +#define GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT 2 +#define GLFW_DISPLAY_PARAM_I_SCREEN_X_POS 3 +#define GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS 4 +#define GLFW_DISPLAY_PARAM_S_NAME_LEN 30 + +/* Display types */ +typedef struct _GLFWdisplay* GLFWdisplay; +typedef void (* GLFWdisplaydevicefun)(GLFWdisplay,int); /* connect / disconnect */ + +/* Display callback registration */ +GLFWAPI void glfwSetDisplayDeviceCallback(GLFWdisplaydevicefun cbfun); + +/* Display attributes */ +GLFWAPI void glfwSetDisplayUserPointer(GLFWdisplay display, void* pointer); +GLFWAPI void* glfwGetDisplayUserPointer(GLFWdisplay display); +GLFWAPI int glfwGetDisplayIntegerParam(GLFWdisplay display, int param); +GLFWAPI const char* glfwGetDisplayStringParam(GLFWdisplay display, int param); + +/* Display discovery */ +GLFWAPI GLFWdisplay glfwGetNextDisplay(GLFWdisplay iterator); + + /* Video mode functions */ -GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount); +GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount); GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); /* Gamma ramp functions */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd50b41d..4d13379c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${GLFW_INCLUDE_DIR}) -set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c +set(common_SOURCES display.c enable.c error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) @@ -43,8 +43,8 @@ elseif(_GLFW_WIN32_WGL) win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) elseif(_GLFW_X11_GLX) - set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c - x11_gamma.c x11_init.c x11_joystick.c + set(libglfw_SOURCES ${common_SOURCES} x11_display.c x11_enable.c + x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) else() diff --git a/src/display.c b/src/display.c new file mode 100644 index 00000000..beb6f5d4 --- /dev/null +++ b/src/display.c @@ -0,0 +1,111 @@ +//======================================================================== +// GLFW - An OpenGL framework +// Platform: Any +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + + +//======================================================================== +// Get a list of connected displays +//======================================================================== + +GLFWAPI GLFWdisplay glfwGetNextDisplay(GLFWdisplay iterator) +{ + GLFWdisplay result = GLFW_DISPLAY_INVALID_HANDLE; + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return result; + } + + if (iterator == GLFW_DISPLAY_INVALID_HANDLE) + { + result = _glfwLibrary.displayListHead; + } + else + { + result = iterator->next; + } + return result; +} + +GLFWAPI int glfwGetDisplayIntegerParam(GLFWdisplay display, int param) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return 0; + } + + if (display == GLFW_DISPLAY_INVALID_HANDLE) + { + _glfwSetError(GLFW_INVALID_VALUE, "Display handle is invalid."); + return 0; + } + + switch(param) + { + case GLFW_DISPLAY_PARAM_I_PHYS_WIDTH: + return display->physicalWidth; + case GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT: + return display->physicalHeight; + case GLFW_DISPLAY_PARAM_I_SCREEN_X_POS: + return display->screenXPosition; + case GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS: + return display->screenYPosition; + default: + _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid integer display attribute."); + return 0; + } +} + +GLFWAPI const char* glfwGetDisplayStringParam(GLFWdisplay display, int param) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return NULL; + } + + if (display == GLFW_DISPLAY_INVALID_HANDLE) + { + _glfwSetError(GLFW_INVALID_VALUE, "display handle is invalid."); + return NULL; + } + + switch(param) + { + case GLFW_DISPLAY_PARAM_S_NAME: + return display->deviceName; + default: + _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid string display attribute."); + return NULL; + } +} + diff --git a/src/fullscreen.c b/src/fullscreen.c index 7cc96bb7..f6cda247 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -100,7 +100,7 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) // Get a list of available video modes //======================================================================== -GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount) +GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) { int count; diff --git a/src/internal.h b/src/internal.h index c8bdb9aa..e757aaee 100644 --- a/src/internal.h +++ b/src/internal.h @@ -76,6 +76,7 @@ typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWfbconfig _GLFWfbconfig; typedef struct _GLFWwindow _GLFWwindow; typedef struct _GLFWlibrary _GLFWlibrary; +typedef struct _GLFWdisplay _GLFWdisplay; //------------------------------------------------------------------------ @@ -215,6 +216,24 @@ struct _GLFWwindow }; +//------------------------------------------------------------------------ +// Display structure +//------------------------------------------------------------------------ +struct _GLFWdisplay +{ + struct _GLFWdisplay* next; + + void* userPointer; + + char deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN+1]; + // physical dimensions in millimeters. + int physicalWidth; + int physicalHeight; + // logical orientation of the screen on the desktop + int screenXPosition; + int screenYPosition; +}; + //------------------------------------------------------------------------ // Library global data //------------------------------------------------------------------------ @@ -225,6 +244,8 @@ struct _GLFWlibrary _GLFWwindow* windowListHead; _GLFWwindow* currentWindow; _GLFWwindow* activeWindow; + _GLFWwindow* cursorLockWindow; + _GLFWdisplay* displayListHead; GLFWwindowsizefun windowSizeCallback; GLFWwindowclosefun windowCloseCallback; diff --git a/src/x11_display.c b/src/x11_display.c new file mode 100644 index 00000000..bd4a90a4 --- /dev/null +++ b/src/x11_display.c @@ -0,0 +1,121 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11 (Unix) +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +_GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) +{ + *current = _glfwMalloc(sizeof(_GLFWdisplay)); + memset(*current, 0, sizeof(_GLFWdisplay)); + + (*current)->physicalWidth = outputInfo->mm_width; + (*current)->physicalHeight = outputInfo->mm_height; + + memcpy((*current)->deviceName, outputInfo->name, GLFW_DISPLAY_PARAM_S_NAME_LEN+1); + (*current)->deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN] = '\0'; + + (*current)->screenXPosition = crtcInfo->x; + (*current)->screenYPosition = crtcInfo->y; + return &((*current)->next); +} + +_GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display) +{ + _GLFWdisplay* result; + + result = display->next; + + _glfwFree(display); + + return result; +} + +void _glfwInitDisplays(void) +{ + if(_glfwLibrary.X11.RandR.available == GL_TRUE) + { + XRRScreenResources* resources; + int outputIDX; + _GLFWdisplay** curDisplay; + + curDisplay = &_glfwLibrary.displayListHead; + + resources = XRRGetScreenResources(_glfwLibrary.X11.display, + _glfwLibrary.X11.root); + + for(outputIDX = 0; outputIDX < resources->noutput; outputIDX++) + { + // physical device + XRROutputInfo* outputInfo = NULL; + // logical surface + XRRCrtcInfo* crtcInfo = NULL; + int crtcIDX; + + outputInfo = XRRGetOutputInfo(_glfwLibrary.X11.display, + resources, + resources->outputs[outputIDX]); + + if(outputInfo->connection == RR_Connected) + { + for(crtcIDX = 0; crtcIDX < outputInfo->ncrtc; crtcIDX++) + { + if(outputInfo->crtc == outputInfo->crtcs[crtcIDX]) + { + crtcInfo = XRRGetCrtcInfo(_glfwLibrary.X11.display, + resources, + outputInfo->crtcs[crtcIDX]); + break; + } + } + + curDisplay = _glfwCreateDisplay(curDisplay, outputInfo, crtcInfo); + + XRRFreeCrtcInfo(crtcInfo); + } + + XRRFreeOutputInfo(outputInfo); + } + } +} + +void _glfwTerminateDisplays(void) +{ + while(_glfwLibrary.displayListHead) + _glfwLibrary.displayListHead = _glfwDestroyDisplay(_glfwLibrary.displayListHead); +} + diff --git a/src/x11_init.c b/src/x11_init.c index 2b8e3e35..a9124435 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -577,6 +577,8 @@ int _glfwPlatformInit(void) _glfwInitJoysticks(); + _glfwInitDisplays(); + // Start the timer _glfwInitTimer(); @@ -598,6 +600,8 @@ int _glfwPlatformTerminate(void) terminateDisplay(); + _glfwTerminateDisplays(); + _glfwTerminateJoysticks(); // Unload libGL.so if necessary diff --git a/src/x11_platform.h b/src/x11_platform.h index 70a57b84..ed730566 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -261,6 +261,10 @@ void _glfwRestoreVideoMode(int screen); void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); +// Displays +void _glfwInitDisplays(void); +void _glfwTerminateDisplays(void); + // Unicode support long _glfwKeySym2Unicode(KeySym keysym); diff --git a/tests/listmodes.c b/tests/listmodes.c index a4648ef6..39edad86 100644 --- a/tests/listmodes.c +++ b/tests/listmodes.c @@ -18,6 +18,7 @@ static void print_mode(GLFWvidmode* mode) int main(void) { + GLFWdisplay displayHandle; GLFWvidmode dtmode, modes[400]; int modecount, i; @@ -32,15 +33,28 @@ int main(void) printf("Desktop mode: "); print_mode(&dtmode); - // List available video modes - modecount = glfwGetVideoModes(modes, sizeof(modes) / sizeof(GLFWvidmode)); - printf("Available modes:\n"); - for (i = 0; i < modecount; i++) - { - printf("%3i: ", i); - print_mode(modes + i); - } + displayHandle = GLFW_DISPLAY_INVALID_HANDLE; + while( GLFW_DISPLAY_INVALID_HANDLE != ( displayHandle = glfwGetNextDisplay( displayHandle ))) + { + printf( "Display name: %s\n" + "Physical dimensions: %dmm x %dmm\n" + "Logical position: (%d,%d)\n", + glfwGetDisplayStringParam( displayHandle, GLFW_DISPLAY_PARAM_S_NAME ), + glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_PHYS_WIDTH ), + glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT ), + glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_SCREEN_X_POS ), + glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS ) + ); + // List available video modes + modecount = glfwGetVideoModes(displayHandle, modes, sizeof(modes) / sizeof(GLFWvidmode)); + printf( "Available modes:\n" ); + for( i = 0; i < modecount; i ++ ) + { + printf("%3i: ", i); + print_mode(modes + i); + } + } glfwTerminate(); exit(EXIT_SUCCESS); } From 4634c334eabc968882319d79ecb7b0818cd6b8aa Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 10:42:07 -0400 Subject: [PATCH 08/20] Renamed compare video modes function to internal interface conventions. --- src/fullscreen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fullscreen.c b/src/fullscreen.c index f6cda247..6814bcac 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -37,7 +37,7 @@ // Lexical comparison function for GLFW video modes, used by qsort //======================================================================== -static int compareVideoModes(const void* firstPtr, const void* secondPtr) +int _glfwCompareVideoModes(const void* firstPtr, const void* secondPtr) { int firstBPP, secondBPP, firstSize, secondSize; GLFWvidmode* first = (GLFWvidmode*) firstPtr; @@ -118,7 +118,7 @@ GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcou count = _glfwPlatformGetVideoModes(list, maxcount); if (count > 0) - qsort(list, count, sizeof(GLFWvidmode), compareVideoModes); + qsort(list, count, sizeof(GLFWvidmode), _glfwCompareVideoModes); return count; } From a905e671b38d013648f8c977e1aa12021e48aed6 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sat, 1 Oct 2011 13:42:59 -0400 Subject: [PATCH 09/20] Implemented display iteration for win32 platform. --- src/CMakeLists.txt | 2 +- src/win32_display.c | 115 +++++++++++++++++++++++++++++++++++++++++++ src/win32_init.c | 4 ++ src/win32_platform.h | 4 ++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/win32_display.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d13379c..e87fcc7e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,7 +41,7 @@ elseif(_GLFW_WIN32_WGL) set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c win32_gamma.c win32_init.c win32_joystick.c win32_opengl.c win32_time.c win32_window.c - win32_dllmain.c) + win32_dllmain.c win32_display.c) elseif(_GLFW_X11_GLX) set(libglfw_SOURCES ${common_SOURCES} x11_display.c x11_enable.c x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c diff --git a/src/win32_display.c b/src/win32_display.c new file mode 100644 index 00000000..31b48cef --- /dev/null +++ b/src/win32_display.c @@ -0,0 +1,115 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11 (Unix) +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +_GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapter, DISPLAY_DEVICE* monitor, DEVMODE* setting) +{ + HDC dc = NULL; + + *current = _glfwMalloc(sizeof(_GLFWdisplay)); + memset(*current, 0, sizeof(_GLFWdisplay)); + + dc = CreateDC("DISPLAY", monitor->DeviceString, NULL, NULL); + + (*current)->physicalWidth = GetDeviceCaps(dc, HORZSIZE); + (*current)->physicalHeight = GetDeviceCaps(dc, VERTSIZE); + + DeleteDC(dc); + + memcpy((*current)->deviceName, monitor->DeviceName, GLFW_DISPLAY_PARAM_S_NAME_LEN+1); + (*current)->deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN] = '\0'; + + (*current)->screenXPosition = setting->dmPosition.x; + (*current)->screenYPosition = setting->dmPosition.y; + return &((*current)->next); +} + +_GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display) +{ + _GLFWdisplay* result; + + result = display->next; + + _glfwFree(display); + + return result; +} + +void _glfwInitDisplays(void) +{ + _GLFWdisplay** curDisplay; + + DISPLAY_DEVICE adapter; + DWORD adapterNum; + + DISPLAY_DEVICE monitor; + + DEVMODE setting; + DWORD settingNum; + + curDisplay = &_glfwLibrary.displayListHead; + + adapter.cb = sizeof(DISPLAY_DEVICE); + adapterNum = 0; + + monitor.cb = sizeof(DISPLAY_DEVICE); + setting.dmSize = sizeof(DEVMODE); + settingNum = 0; + + while(EnumDisplayDevices(NULL, adapterNum++, &adapter, 0)) + { + if(adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) + { + continue; + } + + EnumDisplaySettingsEx(adapter.DeviceName, ENUM_CURRENT_SETTINGS, &setting, EDS_ROTATEDMODE); + + EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); + + curDisplay = _glfwCreateDisplay(curDisplay, &adapter, &monitor, &setting); + } +} + +void _glfwTerminateDisplays(void) +{ + while(_glfwLibrary.displayListHead) + _glfwLibrary.displayListHead = _glfwDestroyDisplay(_glfwLibrary.displayListHead); +} + diff --git a/src/win32_init.c b/src/win32_init.c index 51b3f093..853a1f13 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -164,6 +164,8 @@ int _glfwPlatformInit(void) _glfwLibrary.originalRampSize = 256; _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwInitDisplays(); + _glfwInitTimer(); return GL_TRUE; @@ -179,6 +181,8 @@ int _glfwPlatformTerminate(void) // Restore the original gamma ramp _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); + _glfwTerminateDisplays(); + if (_glfwLibrary.Win32.classAtom) { UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.Win32.instance); diff --git a/src/win32_platform.h b/src/win32_platform.h index 6b61cb77..d1ee889a 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -318,6 +318,10 @@ typedef struct _GLFWlibraryWin32 // Time void _glfwInitTimer(void); +// Display support +void _glfwInitDisplays(void); +void _glfwTerminateDisplays(void); + // Fullscreen support void _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate, From 58d4323eceafa5a6f5b156b0f15e962c8aea3c7c Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sun, 2 Oct 2011 16:13:47 -0400 Subject: [PATCH 10/20] Implemented display aware glfwVideoModes function for X11 XRandR and win32. --- src/fullscreen.c | 8 ++++++- src/internal.h | 5 ++++- src/win32_display.c | 2 ++ src/win32_fullscreen.c | 4 ++-- src/win32_platform.h | 8 +++++++ src/x11_display.c | 7 ++++-- src/x11_fullscreen.c | 51 ++++++++++++++++++++++++++++++++++-------- src/x11_platform.h | 10 +++++++++ 8 files changed, 80 insertions(+), 15 deletions(-) diff --git a/src/fullscreen.c b/src/fullscreen.c index 6814bcac..ec8c6bfd 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -110,13 +110,19 @@ GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcou return 0; } + if (display == GLFW_DISPLAY_INVALID_HANDLE) + { + _glfwSetError(GLFW_INVALID_VALUE, "Display handle is invalid."); + return 0; + } + if (maxcount <= 0 || list == NULL) { // TODO: Figure out if this is an error return 0; } - count = _glfwPlatformGetVideoModes(list, maxcount); + count = _glfwPlatformGetVideoModes(display, list, maxcount); if (count > 0) qsort(list, count, sizeof(GLFWvidmode), _glfwCompareVideoModes); diff --git a/src/internal.h b/src/internal.h index e757aaee..1ecccc5f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -232,6 +232,9 @@ struct _GLFWdisplay // logical orientation of the screen on the desktop int screenXPosition; int screenYPosition; + + // These are defined in the current port's platform.h + _GLFW_PLATFORM_DISPLAY_STATE; }; //------------------------------------------------------------------------ @@ -298,7 +301,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); // Fullscreen -int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount); +int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount); void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); // Gamma ramp diff --git a/src/win32_display.c b/src/win32_display.c index 31b48cef..e489b9d7 100644 --- a/src/win32_display.c +++ b/src/win32_display.c @@ -57,6 +57,8 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapte (*current)->screenXPosition = setting->dmPosition.x; (*current)->screenYPosition = setting->dmPosition.y; + + memcpy((*current)->Win32.DeviceName, adapter->DeviceName, 32); return &((*current)->next); } diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index f8cc0dbc..5aed5bf1 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -182,7 +182,7 @@ void _glfwRestoreVideoMode(void) // Get a list of available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) { DEVMODE deviceMode; DWORD deviceModeNum; @@ -197,7 +197,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) vidModes = NULL; vidModesCount = 0; - while (EnumDisplaySettings(NULL, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) + while (EnumDisplaySettings(display->Win32.DeviceName, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) { deviceModeNum++; diff --git a/src/win32_platform.h b/src/win32_platform.h index d1ee889a..4b99805c 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -202,6 +202,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL +#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayWin32 Win32 //======================================================================== @@ -310,6 +311,13 @@ typedef struct _GLFWlibraryWin32 } _GLFWlibraryWin32; +//------------------------------------------------------------------------ +// Platform-specific display structure +//------------------------------------------------------------------------ +typedef struct _GLFWdisplayWin32 +{ + char DeviceName[32]; +} _GLFWdisplayWin32; //======================================================================== // Prototypes for platform specific internal functions diff --git a/src/x11_display.c b/src/x11_display.c index bd4a90a4..ec882ded 100644 --- a/src/x11_display.c +++ b/src/x11_display.c @@ -51,6 +51,8 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, XRROutputInfo* outputI (*current)->screenXPosition = crtcInfo->x; (*current)->screenYPosition = crtcInfo->y; + + (*current)->X11.output = outputInfo; return &((*current)->next); } @@ -60,6 +62,8 @@ _GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display) result = display->next; + XRRFreeOutputInfo(display->X11.output); + _glfwFree(display); return result; @@ -105,10 +109,9 @@ void _glfwInitDisplays(void) curDisplay = _glfwCreateDisplay(curDisplay, outputInfo, crtcInfo); + // Freeing of the outputInfo is done in _glfwDestroyDisplay XRRFreeCrtcInfo(crtcInfo); } - - XRRFreeOutputInfo(outputInfo); } } } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index c154fe3d..d7f98859 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -325,11 +325,26 @@ struct _glfwResolution int height; }; +int _glfwCompareResolution(const void* left, const void* right) +{ + int result = 0; + const struct _glfwResolution* leftResolution = left; + const struct _glfwResolution* rightResolution = right; + + result = leftResolution->height - rightResolution->height; + if (result == 0) + { + result = leftResolution->width - rightResolution->width; + } + + return result; +} + //======================================================================== // List available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) { int count, k, l, r, g, b, rgba, gl; int depth, screen; @@ -397,19 +412,37 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) if (_glfwLibrary.X11.RandR.available) { #if defined(_GLFW_HAS_XRANDR) - sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); - sizelist = XRRConfigSizes(sc, &sizecount); + XRRScreenResources* resource; + unsigned int a; + resource = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount); + resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * display->X11.output->nmode); - for (k = 0; k < sizecount; k++) + for (k = 0; k < display->X11.output->nmode; k++) { - resarray[rescount].width = sizelist[k].width; - resarray[rescount].height = sizelist[k].height; - rescount++; + for (a = 0; a < resource->nmode; a++) + { + if (resource->modes[a].id != display->X11.output->modes[k]) + { + continue; + } + + struct _glfwResolution res = { + resource->modes[a].width, + resource->modes[a].height + }; + + if (!bsearch(&res, resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution)) + { + resarray[rescount].width = resource->modes[a].width; + resarray[rescount].height = resource->modes[a].height; + rescount++; + qsort(resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution); + } + } } - XRRFreeScreenConfigInfo(sc); + XRRFreeScreenResources(resource); #endif /*_GLFW_HAS_XRANDR*/ } else if (_glfwLibrary.X11.VidMode.available) diff --git a/src/x11_platform.h b/src/x11_platform.h index ed730566..7a3199a7 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -88,6 +88,7 @@ #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayX11 X11 //======================================================================== @@ -244,6 +245,15 @@ GLFWGLOBAL struct { } _glfwJoy[GLFW_JOYSTICK_LAST + 1]; +//------------------------------------------------------------------------ +// Platform-specific window structure +//------------------------------------------------------------------------ +typedef struct _GLFWdisplayX11 +{ + XRROutputInfo* output; +} _GLFWdisplayX11; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== From 426df42d006514f257df629a6a6a663a917dd9b5 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Mon, 3 Oct 2011 03:24:35 -0400 Subject: [PATCH 11/20] Replaced display with monitor in monitor related api. --- include/GL/glfw3.h | 46 +++++++++++++++++++++--------------------- src/display.c | 46 +++++++++++++++++++++--------------------- src/fullscreen.c | 8 ++++---- src/internal.h | 14 ++++++------- src/win32_display.c | 32 ++++++++++++++--------------- src/win32_fullscreen.c | 4 ++-- src/win32_init.c | 4 ++-- src/win32_platform.h | 14 ++++++------- src/x11_display.c | 36 ++++++++++++++++----------------- src/x11_fullscreen.c | 8 ++++---- src/x11_init.c | 4 ++-- src/x11_platform.h | 12 +++++------ tests/listmodes.c | 20 +++++++++--------- 13 files changed, 124 insertions(+), 124 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 887540ac..57f82eae 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -539,36 +539,36 @@ GLFWAPI int glfwGetError(void); GLFWAPI const char* glfwErrorString(int error); GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun); -/* Display constants */ -#define GLFW_DISPLAY_INVALID_HANDLE (NULL) -#define GLFW_DISPLAY_CONNECTED 0 -#define GLFW_DISPLAY_DISCONNECTED 1 -#define GLFW_DISPLAY_PARAM_S_NAME 0 -#define GLFW_DISPLAY_PARAM_I_PHYS_WIDTH 1 -#define GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT 2 -#define GLFW_DISPLAY_PARAM_I_SCREEN_X_POS 3 -#define GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS 4 -#define GLFW_DISPLAY_PARAM_S_NAME_LEN 30 +/* Monitor constants */ +#define GLFW_MONITOR_INVALID_HANDLE (NULL) +#define GLFW_MONITOR_CONNECTED 0 +#define GLFW_MONITOR_DISCONNECTED 1 +#define GLFW_MONITOR_PARAM_S_NAME 0 +#define GLFW_MONITOR_PARAM_I_PHYS_WIDTH 1 +#define GLFW_MONITOR_PARAM_I_PHYS_HEIGHT 2 +#define GLFW_MONITOR_PARAM_I_SCREEN_X_POS 3 +#define GLFW_MONITOR_PARAM_I_SCREEN_Y_POS 4 +#define GLFW_MONITOR_PARAM_S_NAME_LEN 30 -/* Display types */ -typedef struct _GLFWdisplay* GLFWdisplay; -typedef void (* GLFWdisplaydevicefun)(GLFWdisplay,int); /* connect / disconnect */ +/* Monitor types */ +typedef struct _GLFWmonitor* GLFWmonitor; +typedef void (* GLFWmonitordevicefun)(GLFWmonitor,int); /* connect / disconnect */ -/* Display callback registration */ -GLFWAPI void glfwSetDisplayDeviceCallback(GLFWdisplaydevicefun cbfun); +/* Monitor callback registration */ +GLFWAPI void glfwSetMonitorDeviceCallback(GLFWmonitordevicefun cbfun); -/* Display attributes */ -GLFWAPI void glfwSetDisplayUserPointer(GLFWdisplay display, void* pointer); -GLFWAPI void* glfwGetDisplayUserPointer(GLFWdisplay display); -GLFWAPI int glfwGetDisplayIntegerParam(GLFWdisplay display, int param); -GLFWAPI const char* glfwGetDisplayStringParam(GLFWdisplay display, int param); +/* Monitor attributes */ +GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor monitor, void* pointer); +GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor monitor); +GLFWAPI int glfwGetMonitorIntegerParam(GLFWmonitor monitor, int param); +GLFWAPI const char* glfwGetMonitorStringParam(GLFWmonitor monitor, int param); -/* Display discovery */ -GLFWAPI GLFWdisplay glfwGetNextDisplay(GLFWdisplay iterator); +/* Monitor discovery */ +GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator); /* Video mode functions */ -GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount); +GLFWAPI int glfwGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount); GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); /* Gamma ramp functions */ diff --git a/src/display.c b/src/display.c index beb6f5d4..d3c0ef69 100644 --- a/src/display.c +++ b/src/display.c @@ -32,21 +32,21 @@ //======================================================================== -// Get a list of connected displays +// Get a list of connected monitors //======================================================================== -GLFWAPI GLFWdisplay glfwGetNextDisplay(GLFWdisplay iterator) +GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator) { - GLFWdisplay result = GLFW_DISPLAY_INVALID_HANDLE; + GLFWmonitor result = GLFW_MONITOR_INVALID_HANDLE; if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return result; } - if (iterator == GLFW_DISPLAY_INVALID_HANDLE) + if (iterator == GLFW_MONITOR_INVALID_HANDLE) { - result = _glfwLibrary.displayListHead; + result = _glfwLibrary.monitorListHead; } else { @@ -55,7 +55,7 @@ GLFWAPI GLFWdisplay glfwGetNextDisplay(GLFWdisplay iterator) return result; } -GLFWAPI int glfwGetDisplayIntegerParam(GLFWdisplay display, int param) +GLFWAPI int glfwGetMonitorIntegerParam(GLFWmonitor monitor, int param) { if (!_glfwInitialized) { @@ -63,29 +63,29 @@ GLFWAPI int glfwGetDisplayIntegerParam(GLFWdisplay display, int param) return 0; } - if (display == GLFW_DISPLAY_INVALID_HANDLE) + if (monitor == GLFW_MONITOR_INVALID_HANDLE) { - _glfwSetError(GLFW_INVALID_VALUE, "Display handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, "Monitor handle is invalid."); return 0; } switch(param) { - case GLFW_DISPLAY_PARAM_I_PHYS_WIDTH: - return display->physicalWidth; - case GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT: - return display->physicalHeight; - case GLFW_DISPLAY_PARAM_I_SCREEN_X_POS: - return display->screenXPosition; - case GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS: - return display->screenYPosition; + case GLFW_MONITOR_PARAM_I_PHYS_WIDTH: + return monitor->physicalWidth; + case GLFW_MONITOR_PARAM_I_PHYS_HEIGHT: + return monitor->physicalHeight; + case GLFW_MONITOR_PARAM_I_SCREEN_X_POS: + return monitor->screenXPosition; + case GLFW_MONITOR_PARAM_I_SCREEN_Y_POS: + return monitor->screenYPosition; default: - _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid integer display attribute."); + _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid integer monitor attribute."); return 0; } } -GLFWAPI const char* glfwGetDisplayStringParam(GLFWdisplay display, int param) +GLFWAPI const char* glfwGetMonitorStringParam(GLFWmonitor monitor, int param) { if (!_glfwInitialized) { @@ -93,18 +93,18 @@ GLFWAPI const char* glfwGetDisplayStringParam(GLFWdisplay display, int param) return NULL; } - if (display == GLFW_DISPLAY_INVALID_HANDLE) + if (monitor == GLFW_MONITOR_INVALID_HANDLE) { - _glfwSetError(GLFW_INVALID_VALUE, "display handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, "monitor handle is invalid."); return NULL; } switch(param) { - case GLFW_DISPLAY_PARAM_S_NAME: - return display->deviceName; + case GLFW_MONITOR_PARAM_S_NAME: + return monitor->deviceName; default: - _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid string display attribute."); + _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid string monitor attribute."); return NULL; } } diff --git a/src/fullscreen.c b/src/fullscreen.c index ec8c6bfd..891b8b9b 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -100,7 +100,7 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) // Get a list of available video modes //======================================================================== -GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) +GLFWAPI int glfwGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) { int count; @@ -110,9 +110,9 @@ GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcou return 0; } - if (display == GLFW_DISPLAY_INVALID_HANDLE) + if (monitor == GLFW_MONITOR_INVALID_HANDLE) { - _glfwSetError(GLFW_INVALID_VALUE, "Display handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, "Monitor handle is invalid."); return 0; } @@ -122,7 +122,7 @@ GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcou return 0; } - count = _glfwPlatformGetVideoModes(display, list, maxcount); + count = _glfwPlatformGetVideoModes(monitor, list, maxcount); if (count > 0) qsort(list, count, sizeof(GLFWvidmode), _glfwCompareVideoModes); diff --git a/src/internal.h b/src/internal.h index 1ecccc5f..d7d71aeb 100644 --- a/src/internal.h +++ b/src/internal.h @@ -76,7 +76,7 @@ typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWfbconfig _GLFWfbconfig; typedef struct _GLFWwindow _GLFWwindow; typedef struct _GLFWlibrary _GLFWlibrary; -typedef struct _GLFWdisplay _GLFWdisplay; +typedef struct _GLFWmonitor _GLFWmonitor; //------------------------------------------------------------------------ @@ -219,13 +219,13 @@ struct _GLFWwindow //------------------------------------------------------------------------ // Display structure //------------------------------------------------------------------------ -struct _GLFWdisplay +struct _GLFWmonitor { - struct _GLFWdisplay* next; + struct _GLFWmonitor* next; void* userPointer; - char deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN+1]; + char deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN+1]; // physical dimensions in millimeters. int physicalWidth; int physicalHeight; @@ -234,7 +234,7 @@ struct _GLFWdisplay int screenYPosition; // These are defined in the current port's platform.h - _GLFW_PLATFORM_DISPLAY_STATE; + _GLFW_PLATFORM_MONITOR_STATE; }; //------------------------------------------------------------------------ @@ -248,7 +248,7 @@ struct _GLFWlibrary _GLFWwindow* currentWindow; _GLFWwindow* activeWindow; _GLFWwindow* cursorLockWindow; - _GLFWdisplay* displayListHead; + _GLFWmonitor* monitorListHead; GLFWwindowsizefun windowSizeCallback; GLFWwindowclosefun windowCloseCallback; @@ -301,7 +301,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); // Fullscreen -int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount); +int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount); void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); // Gamma ramp diff --git a/src/win32_display.c b/src/win32_display.c index e489b9d7..2743972a 100644 --- a/src/win32_display.c +++ b/src/win32_display.c @@ -38,12 +38,12 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -_GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapter, DISPLAY_DEVICE* monitor, DEVMODE* setting) +_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, DISPLAY_DEVICE* adapter, DISPLAY_DEVICE* monitor, DEVMODE* setting) { HDC dc = NULL; - *current = _glfwMalloc(sizeof(_GLFWdisplay)); - memset(*current, 0, sizeof(_GLFWdisplay)); + *current = _glfwMalloc(sizeof(_GLFWmonitor)); + memset(*current, 0, sizeof(_GLFWmonitor)); dc = CreateDC("DISPLAY", monitor->DeviceString, NULL, NULL); @@ -52,8 +52,8 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapte DeleteDC(dc); - memcpy((*current)->deviceName, monitor->DeviceName, GLFW_DISPLAY_PARAM_S_NAME_LEN+1); - (*current)->deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN] = '\0'; + memcpy((*current)->deviceName, monitor->DeviceName, GLFW_MONITOR_PARAM_S_NAME_LEN+1); + (*current)->deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN] = '\0'; (*current)->screenXPosition = setting->dmPosition.x; (*current)->screenYPosition = setting->dmPosition.y; @@ -62,20 +62,20 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapte return &((*current)->next); } -_GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display) +_GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) { - _GLFWdisplay* result; + _GLFWmonitor* result; - result = display->next; + result = monitor->next; - _glfwFree(display); + _glfwFree(monitor); return result; } -void _glfwInitDisplays(void) +void _glfwInitMonitors(void) { - _GLFWdisplay** curDisplay; + _GLFWmonitor** curMonitor; DISPLAY_DEVICE adapter; DWORD adapterNum; @@ -85,7 +85,7 @@ void _glfwInitDisplays(void) DEVMODE setting; DWORD settingNum; - curDisplay = &_glfwLibrary.displayListHead; + curMonitor = &_glfwLibrary.monitorListHead; adapter.cb = sizeof(DISPLAY_DEVICE); adapterNum = 0; @@ -105,13 +105,13 @@ void _glfwInitDisplays(void) EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); - curDisplay = _glfwCreateDisplay(curDisplay, &adapter, &monitor, &setting); + curMonitor = _glfwCreateMonitor(curMonitor, &adapter, &monitor, &setting); } } -void _glfwTerminateDisplays(void) +void _glfwTerminateMonitors(void) { - while(_glfwLibrary.displayListHead) - _glfwLibrary.displayListHead = _glfwDestroyDisplay(_glfwLibrary.displayListHead); + while(_glfwLibrary.monitorListHead) + _glfwLibrary.monitorListHead = _glfwDestroyMonitor(_glfwLibrary.monitorListHead); } diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index 5aed5bf1..05504a9e 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -182,7 +182,7 @@ void _glfwRestoreVideoMode(void) // Get a list of available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) { DEVMODE deviceMode; DWORD deviceModeNum; @@ -197,7 +197,7 @@ int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxc vidModes = NULL; vidModesCount = 0; - while (EnumDisplaySettings(display->Win32.DeviceName, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) + while (EnumDisplaySettings(monitor->Win32.DeviceName, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) { deviceModeNum++; diff --git a/src/win32_init.c b/src/win32_init.c index 853a1f13..6a8edd2f 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -164,7 +164,7 @@ int _glfwPlatformInit(void) _glfwLibrary.originalRampSize = 256; _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); - _glfwInitDisplays(); + _glfwInitMonitors(); _glfwInitTimer(); @@ -181,7 +181,7 @@ int _glfwPlatformTerminate(void) // Restore the original gamma ramp _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); - _glfwTerminateDisplays(); + _glfwTerminateMonitors(); if (_glfwLibrary.Win32.classAtom) { diff --git a/src/win32_platform.h b/src/win32_platform.h index 4b99805c..77198343 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -202,7 +202,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL -#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayWin32 Win32 +#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 Win32 //======================================================================== @@ -312,12 +312,12 @@ typedef struct _GLFWlibraryWin32 } _GLFWlibraryWin32; //------------------------------------------------------------------------ -// Platform-specific display structure +// Platform-specific monitor structure //------------------------------------------------------------------------ -typedef struct _GLFWdisplayWin32 +typedef struct _GLFWmonitorWin32 { char DeviceName[32]; -} _GLFWdisplayWin32; +} _GLFWmonitorWin32; //======================================================================== // Prototypes for platform specific internal functions @@ -326,9 +326,9 @@ typedef struct _GLFWdisplayWin32 // Time void _glfwInitTimer(void); -// Display support -void _glfwInitDisplays(void); -void _glfwTerminateDisplays(void); +// Monitor support +void _glfwInitMonitors(void); +void _glfwTerminateMonitors(void); // Fullscreen support void _glfwSetVideoMode(int* width, int* height, diff --git a/src/x11_display.c b/src/x11_display.c index ec882ded..33db712b 100644 --- a/src/x11_display.c +++ b/src/x11_display.c @@ -38,16 +38,16 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -_GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) +_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) { - *current = _glfwMalloc(sizeof(_GLFWdisplay)); - memset(*current, 0, sizeof(_GLFWdisplay)); + *current = _glfwMalloc(sizeof(_GLFWmonitor)); + memset(*current, 0, sizeof(_GLFWmonitor)); (*current)->physicalWidth = outputInfo->mm_width; (*current)->physicalHeight = outputInfo->mm_height; - memcpy((*current)->deviceName, outputInfo->name, GLFW_DISPLAY_PARAM_S_NAME_LEN+1); - (*current)->deviceName[GLFW_DISPLAY_PARAM_S_NAME_LEN] = '\0'; + memcpy((*current)->deviceName, outputInfo->name, GLFW_MONITOR_PARAM_S_NAME_LEN+1); + (*current)->deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN] = '\0'; (*current)->screenXPosition = crtcInfo->x; (*current)->screenYPosition = crtcInfo->y; @@ -56,28 +56,28 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, XRROutputInfo* outputI return &((*current)->next); } -_GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display) +_GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) { - _GLFWdisplay* result; + _GLFWmonitor* result; - result = display->next; + result = monitor->next; - XRRFreeOutputInfo(display->X11.output); + XRRFreeOutputInfo(monitor->X11.output); - _glfwFree(display); + _glfwFree(monitor); return result; } -void _glfwInitDisplays(void) +void _glfwInitMonitors(void) { if(_glfwLibrary.X11.RandR.available == GL_TRUE) { XRRScreenResources* resources; int outputIDX; - _GLFWdisplay** curDisplay; + _GLFWmonitor** curMonitor; - curDisplay = &_glfwLibrary.displayListHead; + curMonitor = &_glfwLibrary.monitorListHead; resources = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root); @@ -107,18 +107,18 @@ void _glfwInitDisplays(void) } } - curDisplay = _glfwCreateDisplay(curDisplay, outputInfo, crtcInfo); + curMonitor = _glfwCreateMonitor(curMonitor, outputInfo, crtcInfo); - // Freeing of the outputInfo is done in _glfwDestroyDisplay + // Freeing of the outputInfo is done in _glfwDestroyMonitor XRRFreeCrtcInfo(crtcInfo); } } } } -void _glfwTerminateDisplays(void) +void _glfwTerminateMonitors(void) { - while(_glfwLibrary.displayListHead) - _glfwLibrary.displayListHead = _glfwDestroyDisplay(_glfwLibrary.displayListHead); + while(_glfwLibrary.monitorListHead) + _glfwLibrary.monitorListHead = _glfwDestroyMonitor(_glfwLibrary.monitorListHead); } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index d7f98859..a31144c6 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -344,7 +344,7 @@ int _glfwCompareResolution(const void* left, const void* right) // List available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) { int count, k, l, r, g, b, rgba, gl; int depth, screen; @@ -416,13 +416,13 @@ int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxco unsigned int a; resource = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * display->X11.output->nmode); + resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * monitor->X11.output->nmode); - for (k = 0; k < display->X11.output->nmode; k++) + for (k = 0; k < monitor->X11.output->nmode; k++) { for (a = 0; a < resource->nmode; a++) { - if (resource->modes[a].id != display->X11.output->modes[k]) + if (resource->modes[a].id != monitor->X11.output->modes[k]) { continue; } diff --git a/src/x11_init.c b/src/x11_init.c index a9124435..bbc05ff7 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -577,7 +577,7 @@ int _glfwPlatformInit(void) _glfwInitJoysticks(); - _glfwInitDisplays(); + _glfwInitMonitors(); // Start the timer _glfwInitTimer(); @@ -600,7 +600,7 @@ int _glfwPlatformTerminate(void) terminateDisplay(); - _glfwTerminateDisplays(); + _glfwTerminateMonitors(); _glfwTerminateJoysticks(); diff --git a/src/x11_platform.h b/src/x11_platform.h index 7a3199a7..7808fde8 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -88,7 +88,7 @@ #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX -#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayX11 X11 +#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorX11 X11 //======================================================================== @@ -248,10 +248,10 @@ GLFWGLOBAL struct { //------------------------------------------------------------------------ // Platform-specific window structure //------------------------------------------------------------------------ -typedef struct _GLFWdisplayX11 +typedef struct _GLFWmonitorX11 { XRROutputInfo* output; -} _GLFWdisplayX11; +} _GLFWmonitorX11; //======================================================================== @@ -271,9 +271,9 @@ void _glfwRestoreVideoMode(int screen); void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); -// Displays -void _glfwInitDisplays(void); -void _glfwTerminateDisplays(void); +// Monitors +void _glfwInitMonitors(void); +void _glfwTerminateMonitors(void); // Unicode support long _glfwKeySym2Unicode(KeySym keysym); diff --git a/tests/listmodes.c b/tests/listmodes.c index 39edad86..a43d2f54 100644 --- a/tests/listmodes.c +++ b/tests/listmodes.c @@ -18,7 +18,7 @@ static void print_mode(GLFWvidmode* mode) int main(void) { - GLFWdisplay displayHandle; + GLFWmonitor monitorHandle; GLFWvidmode dtmode, modes[400]; int modecount, i; @@ -33,21 +33,21 @@ int main(void) printf("Desktop mode: "); print_mode(&dtmode); - displayHandle = GLFW_DISPLAY_INVALID_HANDLE; + monitorHandle = GLFW_MONITOR_INVALID_HANDLE; - while( GLFW_DISPLAY_INVALID_HANDLE != ( displayHandle = glfwGetNextDisplay( displayHandle ))) + while( GLFW_MONITOR_INVALID_HANDLE != ( monitorHandle = glfwGetNextMonitor( monitorHandle ))) { - printf( "Display name: %s\n" + printf( "Monitor name: %s\n" "Physical dimensions: %dmm x %dmm\n" "Logical position: (%d,%d)\n", - glfwGetDisplayStringParam( displayHandle, GLFW_DISPLAY_PARAM_S_NAME ), - glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_PHYS_WIDTH ), - glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_PHYS_HEIGHT ), - glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_SCREEN_X_POS ), - glfwGetDisplayIntegerParam( displayHandle, GLFW_DISPLAY_PARAM_I_SCREEN_Y_POS ) + glfwGetMonitorStringParam( monitorHandle, GLFW_MONITOR_PARAM_S_NAME ), + glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_PHYS_WIDTH ), + glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_PHYS_HEIGHT ), + glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_SCREEN_X_POS ), + glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_SCREEN_Y_POS ) ); // List available video modes - modecount = glfwGetVideoModes(displayHandle, modes, sizeof(modes) / sizeof(GLFWvidmode)); + modecount = glfwGetVideoModes(monitorHandle, modes, sizeof(modes) / sizeof(GLFWvidmode)); printf( "Available modes:\n" ); for( i = 0; i < modecount; i ++ ) { From f89feefa46eac5b3be0986b9fe2fffe76d11ec20 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Mon, 3 Oct 2011 12:48:59 -0400 Subject: [PATCH 12/20] Added define guards for XRandR code. --- src/x11_display.c | 8 ++++++++ src/x11_fullscreen.c | 5 ----- src/x11_platform.h | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/x11_display.c b/src/x11_display.c index 33db712b..bdc37bb9 100644 --- a/src/x11_display.c +++ b/src/x11_display.c @@ -38,6 +38,7 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +#if defined (_GLFW_HAS_XRANDR) _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) { *current = _glfwMalloc(sizeof(_GLFWmonitor)); @@ -55,6 +56,7 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputI (*current)->X11.output = outputInfo; return &((*current)->next); } +#endif /*_GLFW_HAS_XRANDR*/ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) { @@ -62,7 +64,9 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) result = monitor->next; +#if defined (_GLFW_HAS_XRANDR) XRRFreeOutputInfo(monitor->X11.output); +#endif /*_GLFW_HAS_XRANDR*/ _glfwFree(monitor); @@ -71,8 +75,11 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) void _glfwInitMonitors(void) { + _glfwLibrary.monitorListHead = NULL; + if(_glfwLibrary.X11.RandR.available == GL_TRUE) { +#if defined (_GLFW_HAS_XRANDR) XRRScreenResources* resources; int outputIDX; _GLFWmonitor** curMonitor; @@ -113,6 +120,7 @@ void _glfwInitMonitors(void) XRRFreeCrtcInfo(crtcInfo); } } +#endif /*_GLFW_HAS_XRANDR*/ } } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index a31144c6..69c2f624 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -353,11 +353,6 @@ int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxco int viscount, rgbcount, rescount; int* rgbarray; struct _glfwResolution* resarray; -#if defined(_GLFW_HAS_XRANDR) - XRRScreenConfiguration* sc; - XRRScreenSize* sizelist; - int sizecount; -#endif /*_GLFW_HAS_XRANDR*/ #if defined(_GLFW_HAS_XF86VIDMODE) XF86VidModeModeInfo** modelist; int modecount, width, height; diff --git a/src/x11_platform.h b/src/x11_platform.h index 7808fde8..461d7436 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -250,7 +250,10 @@ GLFWGLOBAL struct { //------------------------------------------------------------------------ typedef struct _GLFWmonitorX11 { +#if defined(_GLFW_HAS_XRANDR) XRROutputInfo* output; +#endif /*_GLFW_HAS_XRANDR*/ + int dummy; } _GLFWmonitorX11; From 3aa4976d6f8f41afd2b5b855102b96c0fb3d8acf Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Mon, 3 Oct 2011 13:54:05 -0400 Subject: [PATCH 13/20] Removed constant string length for monitor parameters. --- include/GL/glfw3.h | 1 - src/internal.h | 2 +- src/win32_display.c | 6 ++++-- src/x11_display.c | 6 ++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 57f82eae..d6c834fe 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -548,7 +548,6 @@ GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun); #define GLFW_MONITOR_PARAM_I_PHYS_HEIGHT 2 #define GLFW_MONITOR_PARAM_I_SCREEN_X_POS 3 #define GLFW_MONITOR_PARAM_I_SCREEN_Y_POS 4 -#define GLFW_MONITOR_PARAM_S_NAME_LEN 30 /* Monitor types */ typedef struct _GLFWmonitor* GLFWmonitor; diff --git a/src/internal.h b/src/internal.h index d7d71aeb..d31aeebd 100644 --- a/src/internal.h +++ b/src/internal.h @@ -225,7 +225,7 @@ struct _GLFWmonitor void* userPointer; - char deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN+1]; + char* deviceName; // physical dimensions in millimeters. int physicalWidth; int physicalHeight; diff --git a/src/win32_display.c b/src/win32_display.c index 2743972a..1d0518ca 100644 --- a/src/win32_display.c +++ b/src/win32_display.c @@ -52,8 +52,9 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, DISPLAY_DEVICE* adapte DeleteDC(dc); - memcpy((*current)->deviceName, monitor->DeviceName, GLFW_MONITOR_PARAM_S_NAME_LEN+1); - (*current)->deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN] = '\0'; + (*monitor)->deviceName = _glfwMalloc(strlen(monitor->DeviceName) + 1); + memcpy((*current)->deviceName, monitor->DeviceName, strlen(monitor->DeviceName) + 1); + (*current)->deviceName[strlen(monitor->DeviceName)] = '\0'; (*current)->screenXPosition = setting->dmPosition.x; (*current)->screenYPosition = setting->dmPosition.y; @@ -68,6 +69,7 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) result = monitor->next; + _glfwFree(monitor->deviceName); _glfwFree(monitor); return result; diff --git a/src/x11_display.c b/src/x11_display.c index bdc37bb9..6d9feccb 100644 --- a/src/x11_display.c +++ b/src/x11_display.c @@ -47,8 +47,9 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputI (*current)->physicalWidth = outputInfo->mm_width; (*current)->physicalHeight = outputInfo->mm_height; - memcpy((*current)->deviceName, outputInfo->name, GLFW_MONITOR_PARAM_S_NAME_LEN+1); - (*current)->deviceName[GLFW_MONITOR_PARAM_S_NAME_LEN] = '\0'; + (*monitor)->deviceName = _glfwMalloc(strlen(outputInfo->name) + 1); + memcpy((*current)->deviceName, outputInfo->name, strlen(outputInfo->name) + 1); + (*current)->deviceName[strlen(outputInfo->name)] = '\0'; (*current)->screenXPosition = crtcInfo->x; (*current)->screenYPosition = crtcInfo->y; @@ -68,6 +69,7 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) XRRFreeOutputInfo(monitor->X11.output); #endif /*_GLFW_HAS_XRANDR*/ + _glfwFree(monitor->deviceName); _glfwFree(monitor); return result; From 29a4eca87ddb743b1694fc9d0db61651a66ee2f2 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Mon, 3 Oct 2011 14:22:06 -0400 Subject: [PATCH 14/20] Renamed monitor related files. --- src/CMakeLists.txt | 6 +++--- src/{display.c => monitor.c} | 0 src/{win32_display.c => win32_monitor.c} | 2 +- src/{x11_display.c => x11_monitor.c} | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/{display.c => monitor.c} (100%) rename src/{win32_display.c => win32_monitor.c} (98%) rename src/{x11_display.c => x11_monitor.c} (98%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e87fcc7e..f753d17d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${GLFW_INCLUDE_DIR}) -set(common_SOURCES display.c enable.c error.c fullscreen.c gamma.c init.c input.c +set(common_SOURCES monitor.c enable.c error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) @@ -41,9 +41,9 @@ elseif(_GLFW_WIN32_WGL) set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c win32_gamma.c win32_init.c win32_joystick.c win32_opengl.c win32_time.c win32_window.c - win32_dllmain.c win32_display.c) + win32_dllmain.c win32_monitor.c) elseif(_GLFW_X11_GLX) - set(libglfw_SOURCES ${common_SOURCES} x11_display.c x11_enable.c + set(libglfw_SOURCES ${common_SOURCES} x11_monitor.c x11_enable.c x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) diff --git a/src/display.c b/src/monitor.c similarity index 100% rename from src/display.c rename to src/monitor.c diff --git a/src/win32_display.c b/src/win32_monitor.c similarity index 98% rename from src/win32_display.c rename to src/win32_monitor.c index 1d0518ca..71361daf 100644 --- a/src/win32_display.c +++ b/src/win32_monitor.c @@ -52,7 +52,7 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, DISPLAY_DEVICE* adapte DeleteDC(dc); - (*monitor)->deviceName = _glfwMalloc(strlen(monitor->DeviceName) + 1); + (*current)->deviceName = _glfwMalloc(strlen(monitor->DeviceName) + 1); memcpy((*current)->deviceName, monitor->DeviceName, strlen(monitor->DeviceName) + 1); (*current)->deviceName[strlen(monitor->DeviceName)] = '\0'; diff --git a/src/x11_display.c b/src/x11_monitor.c similarity index 98% rename from src/x11_display.c rename to src/x11_monitor.c index 6d9feccb..6a3c5dec 100644 --- a/src/x11_display.c +++ b/src/x11_monitor.c @@ -47,7 +47,7 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputI (*current)->physicalWidth = outputInfo->mm_width; (*current)->physicalHeight = outputInfo->mm_height; - (*monitor)->deviceName = _glfwMalloc(strlen(outputInfo->name) + 1); + (*current)->deviceName = _glfwMalloc(strlen(outputInfo->name) + 1); memcpy((*current)->deviceName, outputInfo->name, strlen(outputInfo->name) + 1); (*current)->deviceName[strlen(outputInfo->name)] = '\0'; From 9738728298abe85abb0cf8a7621a84e235d3d859 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 6 Oct 2011 23:28:56 +0200 Subject: [PATCH 15/20] Reshuffling, formatting and shortening. --- include/GL/glfw3.h | 36 ++++++++--------- src/CMakeLists.txt | 4 ++ src/fullscreen.c | 8 ++-- src/internal.h | 8 ++-- src/monitor.c | 81 ++++++++++++++++++++++++-------------- src/win32_fullscreen.c | 16 ++++---- src/win32_monitor.c | 37 +++++++++++------- src/win32_platform.h | 3 +- src/win32_window.c | 89 ++++++++++++++++++++---------------------- src/x11_fullscreen.c | 2 +- src/x11_monitor.c | 32 +++++++-------- src/x11_platform.h | 6 ++- tests/listmodes.c | 33 ++++++++-------- 13 files changed, 194 insertions(+), 161 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index d6c834fe..bb5bc5ce 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -469,10 +469,22 @@ extern "C" { /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 +/* Monitor constants */ +#define GLFW_MONITOR_CONNECTED 0 +#define GLFW_MONITOR_DISCONNECTED 1 +#define GLFW_MONITOR_NAME 0 +#define GLFW_MONITOR_PHYSICAL_WIDTH 1 +#define GLFW_MONITOR_PHYSICAL_HEIGHT 2 +#define GLFW_MONITOR_SCREEN_POS_X 3 +#define GLFW_MONITOR_SCREEN_POS_Y 4 + /************************************************************************* * Typedefs *************************************************************************/ +/* Monitor handle type */ +typedef void* GLFWmonitor; + /* Window handle type */ typedef void* GLFWwindow; @@ -490,6 +502,7 @@ typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); typedef void* (* GLFWmallocfun)(size_t); typedef void (* GLFWfreefun)(void*); +typedef void (* GLFWmonitordevicefun)(GLFWmonitor,int); /* The video mode structure used by glfwGetVideoModes */ typedef struct @@ -539,33 +552,18 @@ GLFWAPI int glfwGetError(void); GLFWAPI const char* glfwErrorString(int error); GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun); -/* Monitor constants */ -#define GLFW_MONITOR_INVALID_HANDLE (NULL) -#define GLFW_MONITOR_CONNECTED 0 -#define GLFW_MONITOR_DISCONNECTED 1 -#define GLFW_MONITOR_PARAM_S_NAME 0 -#define GLFW_MONITOR_PARAM_I_PHYS_WIDTH 1 -#define GLFW_MONITOR_PARAM_I_PHYS_HEIGHT 2 -#define GLFW_MONITOR_PARAM_I_SCREEN_X_POS 3 -#define GLFW_MONITOR_PARAM_I_SCREEN_Y_POS 4 - -/* Monitor types */ -typedef struct _GLFWmonitor* GLFWmonitor; -typedef void (* GLFWmonitordevicefun)(GLFWmonitor,int); /* connect / disconnect */ - /* Monitor callback registration */ GLFWAPI void glfwSetMonitorDeviceCallback(GLFWmonitordevicefun cbfun); /* Monitor attributes */ -GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor monitor, void* pointer); -GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor monitor); -GLFWAPI int glfwGetMonitorIntegerParam(GLFWmonitor monitor, int param); -GLFWAPI const char* glfwGetMonitorStringParam(GLFWmonitor monitor, int param); +GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor monitor, void* pointer); +GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor monitor); +GLFWAPI int glfwGetMonitorParam(GLFWmonitor monitor, int param); +GLFWAPI const char* glfwGetMonitorString(GLFWmonitor monitor, int param); /* Monitor discovery */ GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator); - /* Video mode functions */ GLFWAPI int glfwGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount); GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f753d17d..c0913b88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,8 @@ +if(WIN32) + add_definitions(-DWINVER=0x0501) +endif(WIN32) + if(CYGWIN) # These lines are intended to remove the --export-all-symbols diff --git a/src/fullscreen.c b/src/fullscreen.c index 891b8b9b..7f067b5f 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -100,9 +100,10 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) // Get a list of available video modes //======================================================================== -GLFWAPI int glfwGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) +GLFWAPI int glfwGetVideoModes(GLFWmonitor handle, GLFWvidmode* list, int maxcount) { int count; + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; if (!_glfwInitialized) { @@ -110,9 +111,10 @@ GLFWAPI int glfwGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcou return 0; } - if (monitor == GLFW_MONITOR_INVALID_HANDLE) + if (monitor == NULL) { - _glfwSetError(GLFW_INVALID_VALUE, "Monitor handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwGetVideoModes: Invalid monitor handle"); return 0; } diff --git a/src/internal.h b/src/internal.h index d31aeebd..95a29d0a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -225,13 +225,13 @@ struct _GLFWmonitor void* userPointer; - char* deviceName; + char* name; // physical dimensions in millimeters. int physicalWidth; int physicalHeight; // logical orientation of the screen on the desktop - int screenXPosition; - int screenYPosition; + int screenX; + int screenY; // These are defined in the current port's platform.h _GLFW_PLATFORM_MONITOR_STATE; @@ -301,7 +301,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); // Fullscreen -int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount); +int _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, GLFWvidmode* list, int maxcount); void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); // Gamma ramp diff --git a/src/monitor.c b/src/monitor.c index d3c0ef69..78c919b2 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -31,81 +31,102 @@ #include "internal.h" +////////////////////////////////////////////////////////////////////////// +////// GLFW public API ////// +////////////////////////////////////////////////////////////////////////// + //======================================================================== -// Get a list of connected monitors +// Iterate through connected monitors //======================================================================== -GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator) +GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor handle) { - GLFWmonitor result = GLFW_MONITOR_INVALID_HANDLE; + _GLFWmonitor* iterator = (_GLFWmonitor*) handle; + _GLFWmonitor* result = NULL; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return result; } - if (iterator == GLFW_MONITOR_INVALID_HANDLE) - { + if (iterator == NULL) result = _glfwLibrary.monitorListHead; - } else - { result = iterator->next; - } + return result; } -GLFWAPI int glfwGetMonitorIntegerParam(GLFWmonitor monitor, int param) + +//======================================================================== +// Get monitor parameter +//======================================================================== + +GLFWAPI int glfwGetMonitorParam(GLFWmonitor handle, int param) { + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return 0; } - if (monitor == GLFW_MONITOR_INVALID_HANDLE) + if (monitor == NULL) { - _glfwSetError(GLFW_INVALID_VALUE, "Monitor handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwGetMonitorParam: Invalid monitor handle"); return 0; } - switch(param) + switch (param) { - case GLFW_MONITOR_PARAM_I_PHYS_WIDTH: + case GLFW_MONITOR_PHYSICAL_WIDTH: return monitor->physicalWidth; - case GLFW_MONITOR_PARAM_I_PHYS_HEIGHT: + case GLFW_MONITOR_PHYSICAL_HEIGHT: return monitor->physicalHeight; - case GLFW_MONITOR_PARAM_I_SCREEN_X_POS: - return monitor->screenXPosition; - case GLFW_MONITOR_PARAM_I_SCREEN_Y_POS: - return monitor->screenYPosition; - default: - _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid integer monitor attribute."); - return 0; + case GLFW_MONITOR_SCREEN_POS_X: + return monitor->screenX; + case GLFW_MONITOR_SCREEN_POS_Y: + return monitor->screenY; } + + _glfwSetError(GLFW_INVALID_ENUM, + "glfwGetMonitorParam: Invalid enum value for 'param' parameter"); + return 0; } -GLFWAPI const char* glfwGetMonitorStringParam(GLFWmonitor monitor, int param) + +//======================================================================== +// Get monitor string +//======================================================================== + +GLFWAPI const char* glfwGetMonitorString(GLFWmonitor handle, int param) { + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return NULL; } - if (monitor == GLFW_MONITOR_INVALID_HANDLE) + if (monitor == NULL) { - _glfwSetError(GLFW_INVALID_VALUE, "monitor handle is invalid."); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwGetMonitorString: Invalid monitor handle"); return NULL; } - switch(param) + switch (param) { - case GLFW_MONITOR_PARAM_S_NAME: - return monitor->deviceName; - default: - _glfwSetError(GLFW_INVALID_ENUM, "Param represents not a valid string monitor attribute."); - return NULL; + case GLFW_MONITOR_NAME: + return monitor->name; } + + _glfwSetError(GLFW_INVALID_ENUM, + "glfwGetMonitorString: Invalid enum value for 'param' parameter"); + return NULL; } diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index 05504a9e..08f5e93e 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -182,7 +182,7 @@ void _glfwRestoreVideoMode(void) // Get a list of available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, GLFWvidmode* list, int maxcount) { DEVMODE deviceMode; DWORD deviceModeNum; @@ -197,14 +197,18 @@ int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxc vidModes = NULL; vidModesCount = 0; - while (EnumDisplaySettings(monitor->Win32.DeviceName, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) + for (;;) { + if (!EnumDisplaySettings(monitor->Win32.name, deviceModeNum, &deviceMode)) + break; + + if (vidModesCount >= maxcount) + break; + deviceModeNum++; if (deviceMode.dmBitsPerPel < 15) - { continue; - } vidMode.height = deviceMode.dmPelsHeight; vidMode.width = deviceMode.dmPelsWidth; @@ -216,9 +220,7 @@ int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxc // skip duplicates. if (vidModes && bsearch(&vidMode, vidModes, vidModesCount, sizeof(GLFWvidmode), _glfwCompareVideoModes)) - { continue; - } vidModes = realloc(vidModes, sizeof(GLFWvidmode) * ++vidModesCount); memcpy(vidModes + (vidModesCount - 1), &vidMode, sizeof(GLFWvidmode)); @@ -227,9 +229,7 @@ int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxc } if (list && maxcount) - { memcpy(list, vidModes, sizeof(GLFWvidmode) * min(vidModesCount, maxcount)); - } free(vidModes); diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 71361daf..c8fd5fe2 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -33,12 +33,20 @@ #include #include +// The MinGW package for Debian lacks this +#ifndef EDS_ROTATEDMODE +#define EDS_ROTATEDMODE 0x00000004 +#endif + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, DISPLAY_DEVICE* adapter, DISPLAY_DEVICE* monitor, DEVMODE* setting) +_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, + DISPLAY_DEVICE* adapter, + DISPLAY_DEVICE* monitor, + DEVMODE* setting) { HDC dc = NULL; @@ -52,14 +60,14 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, DISPLAY_DEVICE* adapte DeleteDC(dc); - (*current)->deviceName = _glfwMalloc(strlen(monitor->DeviceName) + 1); - memcpy((*current)->deviceName, monitor->DeviceName, strlen(monitor->DeviceName) + 1); - (*current)->deviceName[strlen(monitor->DeviceName)] = '\0'; + (*current)->name = _glfwMalloc(strlen(monitor->DeviceName) + 1); + memcpy((*current)->name, monitor->DeviceName, strlen(monitor->DeviceName) + 1); + (*current)->name[strlen(monitor->DeviceName)] = '\0'; - (*current)->screenXPosition = setting->dmPosition.x; - (*current)->screenYPosition = setting->dmPosition.y; + (*current)->screenX = setting->dmPosition.x; + (*current)->screenY = setting->dmPosition.y; - memcpy((*current)->Win32.DeviceName, adapter->DeviceName, 32); + memcpy((*current)->Win32.name, adapter->DeviceName, 32); return &((*current)->next); } @@ -69,7 +77,7 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) result = monitor->next; - _glfwFree(monitor->deviceName); + _glfwFree(monitor->name); _glfwFree(monitor); return result; @@ -96,14 +104,15 @@ void _glfwInitMonitors(void) setting.dmSize = sizeof(DEVMODE); settingNum = 0; - while(EnumDisplayDevices(NULL, adapterNum++, &adapter, 0)) + while (EnumDisplayDevices(NULL, adapterNum++, &adapter, 0)) { - if(adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) - { + if (adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) continue; - } - EnumDisplaySettingsEx(adapter.DeviceName, ENUM_CURRENT_SETTINGS, &setting, EDS_ROTATEDMODE); + EnumDisplaySettingsEx(adapter.DeviceName, + ENUM_CURRENT_SETTINGS, + &setting, + EDS_ROTATEDMODE); EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); @@ -113,7 +122,7 @@ void _glfwInitMonitors(void) void _glfwTerminateMonitors(void) { - while(_glfwLibrary.monitorListHead) + while (_glfwLibrary.monitorListHead) _glfwLibrary.monitorListHead = _glfwDestroyMonitor(_glfwLibrary.monitorListHead); } diff --git a/src/win32_platform.h b/src/win32_platform.h index 77198343..fa371ee4 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -316,7 +316,8 @@ typedef struct _GLFWlibraryWin32 //------------------------------------------------------------------------ typedef struct _GLFWmonitorWin32 { - char DeviceName[32]; + char name[32]; + } _GLFWmonitorWin32; //======================================================================== diff --git a/src/win32_window.c b/src/win32_window.c index b9a6a6a3..45fb6c6e 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -33,9 +33,6 @@ #include #include -void showMouseCursor(_GLFWwindow* window); -void captureMouseCursor(_GLFWwindow* window); - //======================================================================== // Convert BPP to RGB bits based on "best guess" //======================================================================== @@ -148,6 +145,48 @@ static void setForegroundWindow(HWND hWnd) } +//======================================================================== +// Hide mouse cursor (lock it) +//======================================================================== + +static void hideMouseCursor(_GLFWwindow* window) +{ + ShowCursor(FALSE); +} + + +//======================================================================== +// Show mouse cursor (unlock it) +//======================================================================== + +static void showMouseCursor(_GLFWwindow* window) +{ + // Un-capture cursor + ReleaseCapture(); + + // Release the cursor from the window + ClipCursor(NULL); + + ShowCursor(TRUE); +} + +//======================================================================== +// Capture mouse cursor +//======================================================================== + +static void captureMouseCursor(_GLFWwindow* window) +{ + RECT ClipWindowRect; + + // Clip cursor to the window + if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) + ClipCursor(&ClipWindowRect); + + // Capture cursor to user window + SetCapture(window->Win32.handle); +} + + //======================================================================== // Returns the specified attribute of the specified pixel format // NOTE: Do not call this unless we have found WGL_ARB_pixel_format @@ -1848,50 +1887,6 @@ void _glfwPlatformWaitEvents(void) } -//======================================================================== -// Hide mouse cursor (lock it) -//======================================================================== - -void hideMouseCursor(_GLFWwindow* window) -{ - ShowCursor(FALSE); - - captureMouseCursor(window); -} - - -//======================================================================== -// Show mouse cursor (unlock it) -//======================================================================== - -void showMouseCursor(_GLFWwindow* window) -{ - // Un-capture cursor - ReleaseCapture(); - - // Release the cursor from the window - ClipCursor(NULL); - - ShowCursor(TRUE); -} - -//======================================================================== -// Capture mouse cursor -//======================================================================== - -static void captureMouseCursor(_GLFWwindow* window) -{ - RECT ClipWindowRect; - - // Clip cursor to the window - if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) - ClipCursor(&ClipWindowRect); - - // Capture cursor to user window - SetCapture(window->Win32.handle); -} - - //======================================================================== // Set physical mouse cursor position //======================================================================== diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 69c2f624..2606ab6f 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -344,7 +344,7 @@ int _glfwCompareResolution(const void* left, const void* right) // List available video modes //======================================================================== -int _glfwPlatformGetVideoModes(GLFWmonitor monitor, GLFWvidmode* list, int maxcount) +int _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, GLFWvidmode* list, int maxcount) { int count, k, l, r, g, b, rgba, gl; int depth, screen; diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 6a3c5dec..50c142d4 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -38,8 +38,9 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -#if defined (_GLFW_HAS_XRANDR) -_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) +_GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, + XRROutputInfo* outputInfo, + XRRCrtcInfo* crtcInfo) { *current = _glfwMalloc(sizeof(_GLFWmonitor)); memset(*current, 0, sizeof(_GLFWmonitor)); @@ -47,17 +48,16 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputI (*current)->physicalWidth = outputInfo->mm_width; (*current)->physicalHeight = outputInfo->mm_height; - (*current)->deviceName = _glfwMalloc(strlen(outputInfo->name) + 1); - memcpy((*current)->deviceName, outputInfo->name, strlen(outputInfo->name) + 1); - (*current)->deviceName[strlen(outputInfo->name)] = '\0'; + (*current)->name = _glfwMalloc(strlen(outputInfo->name) + 1); + memcpy((*current)->name, outputInfo->name, strlen(outputInfo->name) + 1); + (*current)->name[strlen(outputInfo->name)] = '\0'; - (*current)->screenXPosition = crtcInfo->x; - (*current)->screenYPosition = crtcInfo->y; + (*current)->screenX = crtcInfo->x; + (*current)->screenY = crtcInfo->y; (*current)->X11.output = outputInfo; return &((*current)->next); } -#endif /*_GLFW_HAS_XRANDR*/ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) { @@ -66,10 +66,10 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) result = monitor->next; #if defined (_GLFW_HAS_XRANDR) - XRRFreeOutputInfo(monitor->X11.output); + XRRFreeOutputInfo(monitor->X11.output); #endif /*_GLFW_HAS_XRANDR*/ - _glfwFree(monitor->deviceName); + _glfwFree(monitor->name); _glfwFree(monitor); return result; @@ -79,7 +79,7 @@ void _glfwInitMonitors(void) { _glfwLibrary.monitorListHead = NULL; - if(_glfwLibrary.X11.RandR.available == GL_TRUE) + if (_glfwLibrary.X11.RandR.available) { #if defined (_GLFW_HAS_XRANDR) XRRScreenResources* resources; @@ -91,7 +91,7 @@ void _glfwInitMonitors(void) resources = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root); - for(outputIDX = 0; outputIDX < resources->noutput; outputIDX++) + for (outputIDX = 0; outputIDX < resources->noutput; outputIDX++) { // physical device XRROutputInfo* outputInfo = NULL; @@ -103,11 +103,11 @@ void _glfwInitMonitors(void) resources, resources->outputs[outputIDX]); - if(outputInfo->connection == RR_Connected) + if (outputInfo->connection == RR_Connected) { - for(crtcIDX = 0; crtcIDX < outputInfo->ncrtc; crtcIDX++) + for (crtcIDX = 0; crtcIDX < outputInfo->ncrtc; crtcIDX++) { - if(outputInfo->crtc == outputInfo->crtcs[crtcIDX]) + if (outputInfo->crtc == outputInfo->crtcs[crtcIDX]) { crtcInfo = XRRGetCrtcInfo(_glfwLibrary.X11.display, resources, @@ -128,7 +128,7 @@ void _glfwInitMonitors(void) void _glfwTerminateMonitors(void) { - while(_glfwLibrary.monitorListHead) + while (_glfwLibrary.monitorListHead) _glfwLibrary.monitorListHead = _glfwDestroyMonitor(_glfwLibrary.monitorListHead); } diff --git a/src/x11_platform.h b/src/x11_platform.h index 461d7436..70984072 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -251,9 +251,11 @@ GLFWGLOBAL struct { typedef struct _GLFWmonitorX11 { #if defined(_GLFW_HAS_XRANDR) - XRROutputInfo* output; -#endif /*_GLFW_HAS_XRANDR*/ + XRROutputInfo* output; +#else int dummy; +#endif /*_GLFW_HAS_XRANDR*/ + } _GLFWmonitorX11; diff --git a/tests/listmodes.c b/tests/listmodes.c index a43d2f54..2ba61577 100644 --- a/tests/listmodes.c +++ b/tests/listmodes.c @@ -18,7 +18,7 @@ static void print_mode(GLFWvidmode* mode) int main(void) { - GLFWmonitor monitorHandle; + GLFWmonitor monitor; GLFWvidmode dtmode, modes[400]; int modecount, i; @@ -33,29 +33,30 @@ int main(void) printf("Desktop mode: "); print_mode(&dtmode); - monitorHandle = GLFW_MONITOR_INVALID_HANDLE; + monitor = NULL; - while( GLFW_MONITOR_INVALID_HANDLE != ( monitorHandle = glfwGetNextMonitor( monitorHandle ))) + while ((monitor = glfwGetNextMonitor(monitor))) { - printf( "Monitor name: %s\n" - "Physical dimensions: %dmm x %dmm\n" - "Logical position: (%d,%d)\n", - glfwGetMonitorStringParam( monitorHandle, GLFW_MONITOR_PARAM_S_NAME ), - glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_PHYS_WIDTH ), - glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_PHYS_HEIGHT ), - glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_SCREEN_X_POS ), - glfwGetMonitorIntegerParam( monitorHandle, GLFW_MONITOR_PARAM_I_SCREEN_Y_POS ) - ); + printf("Monitor name: %s\n" + "Physical dimensions: %dmm x %dmm\n" + "Logical position: (%d,%d)\n", + glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), + glfwGetMonitorParam(monitor, GLFW_MONITOR_PHYSICAL_WIDTH), + glfwGetMonitorParam(monitor, GLFW_MONITOR_PHYSICAL_HEIGHT), + glfwGetMonitorParam(monitor, GLFW_MONITOR_SCREEN_POS_X), + glfwGetMonitorParam(monitor, GLFW_MONITOR_SCREEN_POS_Y)); + // List available video modes - modecount = glfwGetVideoModes(monitorHandle, modes, sizeof(modes) / sizeof(GLFWvidmode)); - printf( "Available modes:\n" ); - for( i = 0; i < modecount; i ++ ) + modecount = glfwGetVideoModes(monitor, modes, sizeof(modes) / sizeof(GLFWvidmode)); + printf("Available modes:\n"); + + for (i = 0; i < modecount; i++) { printf("%3i: ", i); print_mode(modes + i); } } - glfwTerminate(); + exit(EXIT_SUCCESS); } From 1036d8e8085fb1c8b9f0409ed1c2b63d7a049f10 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 6 Oct 2011 23:53:11 +0200 Subject: [PATCH 16/20] Restored dropped guards for RandR-specific function. --- src/x11_monitor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 50c142d4..e827fb35 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -38,6 +38,7 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +#if defined (_GLFW_HAS_XRANDR) _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, XRROutputInfo* outputInfo, XRRCrtcInfo* crtcInfo) @@ -58,6 +59,7 @@ _GLFWmonitor** _glfwCreateMonitor(_GLFWmonitor** current, (*current)->X11.output = outputInfo; return &((*current)->next); } +#endif /*_GLFW_HAS_XRANDR*/ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) { From 719962817efd2739690e6c0461fd6c3e9ae0955a Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Fri, 7 Oct 2011 00:15:42 -0400 Subject: [PATCH 17/20] Added hexadecimal prefix 0x0006 to monitor related constants. --- include/GL/glfw3.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index bb5bc5ce..0a07fe84 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -470,13 +470,13 @@ extern "C" { #define GLFW_GAMMA_RAMP_SIZE 256 /* Monitor constants */ -#define GLFW_MONITOR_CONNECTED 0 -#define GLFW_MONITOR_DISCONNECTED 1 -#define GLFW_MONITOR_NAME 0 -#define GLFW_MONITOR_PHYSICAL_WIDTH 1 -#define GLFW_MONITOR_PHYSICAL_HEIGHT 2 -#define GLFW_MONITOR_SCREEN_POS_X 3 -#define GLFW_MONITOR_SCREEN_POS_Y 4 +#define GLFW_MONITOR_NAME 0x00060000 +#define GLFW_MONITOR_PHYSICAL_WIDTH 0x00060001 +#define GLFW_MONITOR_PHYSICAL_HEIGHT 0x00060002 +#define GLFW_MONITOR_SCREEN_POS_X 0x00060003 +#define GLFW_MONITOR_SCREEN_POS_Y 0x00060004 +#define GLFW_MONITOR_CONNECTED 0x00061000 +#define GLFW_MONITOR_DISCONNECTED 0x00061001 /************************************************************************* * Typedefs From 784f60365e0a33f3dbaaa196b9bdd9d2e6851d3e Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sun, 9 Oct 2011 00:20:34 -0400 Subject: [PATCH 18/20] Stub implementation of monitor callback. --- src/internal.h | 1 + src/monitor.c | 15 +++++++++++++++ tests/events.c | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/internal.h b/src/internal.h index be01dbe6..74388d6e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -264,6 +264,7 @@ struct _GLFWlibrary GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; GLFWcharfun charCallback; + GLFWmonitordevicefun monitorCallback; GLFWthreadmodel threading; GLFWallocator allocator; diff --git a/src/monitor.c b/src/monitor.c index 78c919b2..3263eb9f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -130,3 +130,18 @@ GLFWAPI const char* glfwGetMonitorString(GLFWmonitor handle, int param) return NULL; } +//======================================================================== +// Set a callback function for monitor events +//======================================================================== + +GLFWAPI void glfwSetMonitorDeviceCallback(GLFWmonitordevicefun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwLibrary.monitorCallback= cbfun; +} + diff --git a/tests/events.c b/tests/events.c index ac758100..1a1280a3 100644 --- a/tests/events.c +++ b/tests/events.c @@ -216,6 +216,19 @@ static const char* get_character_string(int character) return result; } +static const char* get_monitor_event_name(int event) +{ + switch (event) + { + case GLFW_MONITOR_CONNECTED: + return "connected"; + case GLFW_MONITOR_DISCONNECTED: + return "disconnected"; + } + + return NULL; +} + static void window_size_callback(GLFWwindow window, int width, int height) { printf("%08x at %0.3f: Window size: %i %i\n", @@ -330,6 +343,16 @@ static void char_callback(GLFWwindow window, int character) get_character_string(character)); } +void monitor_callback(GLFWmonitor monitor, int event) +{ + printf("%08x at %0.3f: Monitor %s %s", + counter++, + glfwGetTime(), + glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), + get_monitor_event_name(event)); + +} + int main(void) { GLFWwindow window; @@ -354,6 +377,7 @@ int main(void) glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); + glfwSetMonitorDeviceCallback(monitor_callback); window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL); if (!window) From 85d4bfcff5ba5a434ca658b2f21a64c16d558ffa Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Fri, 14 Oct 2011 14:32:06 -0400 Subject: [PATCH 19/20] Implemented monitor (dis)connect callback for win32. --- src/win32_monitor.c | 105 ++++++++++++++++++++++++++++++++++++++++++- src/win32_platform.h | 2 + src/win32_window.c | 11 ++++- 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index c8fd5fe2..7b03b9fb 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -83,6 +83,9 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor) return result; } +// todo: This is ugly. The platform should only allocate a list of the current devices. +// The platform independent code should be in charge of the handling for the initial +// setup, refreshing and freeing the list. void _glfwInitMonitors(void) { _GLFWmonitor** curMonitor; @@ -106,7 +109,7 @@ void _glfwInitMonitors(void) while (EnumDisplayDevices(NULL, adapterNum++, &adapter, 0)) { - if (adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) + if (adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER || !(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) continue; EnumDisplaySettingsEx(adapter.DeviceName, @@ -120,6 +123,106 @@ void _glfwInitMonitors(void) } } +void _glfwRefreshMonitors(void) +{ + DISPLAY_DEVICE adapter; + DWORD adapterNum = 0; + + DISPLAY_DEVICE monitor; + + DEVMODE setting; + + _GLFWmonitor* newMonitorList = NULL; + _GLFWmonitor** curMonitor = &newMonitorList; + + _GLFWmonitor* curNewMonitor; + _GLFWmonitor* curOldMonitor; + + while (EnumDisplayDevices(NULL, adapterNum++, &adapter, 0)) + { + if (adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER || !(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) + continue; + + EnumDisplaySettingsEx(adapter.DeviceName, ENUM_CURRENT_SETTINGS, &setting, EDS_ROTATEDMODE); + + EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); + + curMonitor = _glfwCreateMonitor(curMonitor, &adapter, &monitor, &setting); + } + + curNewMonitor = newMonitorList; + curOldMonitor = _glfwLibrary.monitorListHead; + + while (_glfwLibrary.monitorCallback && (curNewMonitor || curOldMonitor)) + { + _GLFWmonitor* lookAheadOldMonitor; + _GLFWmonitor* lookAheadNewMonitor; + + if (curOldMonitor && curNewMonitor && !strcmp(curOldMonitor->name, curOldMonitor->name)) + { + curNewMonitor = curNewMonitor->next; + curOldMonitor = curOldMonitor->next; + continue; + } + + if (curNewMonitor && !curOldMonitor) + { + _glfwLibrary.monitorCallback(curNewMonitor, GLFW_MONITOR_CONNECTED); + curNewMonitor = curNewMonitor->next; + continue; + } + + if (!curNewMonitor && curOldMonitor) + { + _glfwLibrary.monitorCallback(curOldMonitor, GLFW_MONITOR_DISCONNECTED); + curOldMonitor = curOldMonitor->next; + continue; + } + + lookAheadOldMonitor = curOldMonitor->next; + lookAheadNewMonitor = curNewMonitor->next; + + while (lookAheadOldMonitor && !strcmp(curNewMonitor->name, lookAheadOldMonitor->name)) + lookAheadOldMonitor = lookAheadOldMonitor->next; + + while (lookAheadNewMonitor && !strcmp(curOldMonitor->name, lookAheadNewMonitor->name)) + lookAheadNewMonitor = lookAheadNewMonitor->next; + + if (!lookAheadOldMonitor) + { + // nothing found in the old monitor list, that matches the current new monitor. + _glfwLibrary.monitorCallback(curNewMonitor, GLFW_MONITOR_CONNECTED); + curNewMonitor = curNewMonitor->next; + } + else + { + while (strcmp(curOldMonitor->name, lookAheadOldMonitor->name)) + { + _glfwLibrary.monitorCallback(curOldMonitor, GLFW_MONITOR_DISCONNECTED); + curOldMonitor = curOldMonitor->next; + } + } + + if (!lookAheadNewMonitor) + { + // nothing found in the new monitor list, that matches the current old monitor. + _glfwLibrary.monitorCallback(curOldMonitor, GLFW_MONITOR_DISCONNECTED); + curOldMonitor = curOldMonitor->next; + } + else + { + while (strcmp(curNewMonitor->name, lookAheadNewMonitor->name)) + { + _glfwLibrary.monitorCallback(curNewMonitor, GLFW_MONITOR_CONNECTED); + curNewMonitor = curNewMonitor->next; + } + } + } + + _glfwTerminateMonitors(); + _glfwLibrary.monitorListHead = newMonitorList; +} + void _glfwTerminateMonitors(void) { while (_glfwLibrary.monitorListHead) diff --git a/src/win32_platform.h b/src/win32_platform.h index c09b6235..91c71fbe 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -42,6 +42,7 @@ #include #include +#include // This path may need to be changed if you build GLFW using your own setup // We ship and use our own copy of wglext.h since GLFW uses fairly new @@ -332,6 +333,7 @@ void _glfwInitTimer(void); // Monitor support void _glfwInitMonitors(void); +void _glfwRefreshMonitors(void); void _glfwTerminateMonitors(void); // Fullscreen support diff --git a/src/win32_window.c b/src/win32_window.c index fcc9e891..f362368a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -30,7 +30,6 @@ #include "internal.h" -#include #include @@ -1104,6 +1103,16 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, break; } + + case WM_DEVICECHANGE: + { + if (DBT_DEVNODES_CHANGED == wParam) + { + _glfwRefreshMonitors(); + return TRUE; + } + break; + } } // Pass all unhandled messages to DefWindowProc From 7fbb707ac36c7cf303f5734c5ba33cfa1a3a5950 Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Wed, 11 Jan 2012 09:11:34 +0100 Subject: [PATCH 20/20] Added tests to gitignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e3cefe05..9df01be7 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ tests/sharing tests/tearing tests/version tests/windows +tests/dynamic +tests/glfwinfo