diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 5c70af2e..335a2a3b 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -539,7 +539,7 @@ GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator); /* Video mode functions */ GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor monitor, int* count); -GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); +GLFWAPI void glfwGetVideoMode(GLFWmonitor monitor, GLFWvidmode* mode); /* Gamma ramp functions */ GLFWAPI void glfwSetGamma(float gamma); diff --git a/readme.html b/readme.html index 2eeda27b..5f0a77bb 100644 --- a/readme.html +++ b/readme.html @@ -303,6 +303,7 @@ version of GLFW.

  • Renamed glfwGetJoystickPos to glfwGetJoystickAxes to match glfwGetJoystickButtons
  • Renamed mouse position functions to cursor position equivalents
  • Replaced glfwOpenWindow and glfwCloseWindow with glfwCreateWindow and glfwDestroyWindow
  • +
  • Replaced glfwGetDesktopMode width glfwGetVideoMode
  • Replaced ad hoc build system with CMake
  • Replaced layout-dependent key codes with single, platform-independent set based on US layout
  • Replaced mouse wheel interface with two-dimensional, floating point scrolling interface
  • diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m index 47f86739..581d2d54 100644 --- a/src/cocoa_fullscreen.m +++ b/src/cocoa_fullscreen.m @@ -167,6 +167,8 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate) return GL_FALSE; } + _glfwLibrary.NS.previousMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); + CGDisplayCapture(CGMainDisplayID()); CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL); @@ -182,7 +184,7 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate) void _glfwRestoreVideoMode(void) { CGDisplaySetDisplayMode(CGMainDisplayID(), - _glfwLibrary.NS.desktopMode, + _glfwLibrary.NS.previousMode, NULL); CGDisplayRelease(CGMainDisplayID()); @@ -227,11 +229,15 @@ GLFWvidmode* _glfwPlatformGetVideoModes(int* found) //======================================================================== -// Get the desktop video mode +// Get the current video mode for the specified monitor //======================================================================== -void _glfwPlatformGetDesktopMode(GLFWvidmode *mode) +void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode) { - *mode = vidmodeFromCGDisplayMode(_glfwLibrary.NS.desktopMode); + CGDisplayModeRef displayMode; + + displayMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); + *mode = vidmodeFromCGDisplayMode(displayMode); + CGDisplayModeRelease(displayMode); } diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 7c208b90..76d5b8b2 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -92,8 +92,6 @@ int _glfwPlatformInit(void) changeToResourcesDirectory(); - _glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); - // Save the original gamma ramp _glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID()); _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); @@ -132,8 +130,6 @@ int _glfwPlatformTerminate(void) if (_glfwLibrary.rampChanged) _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); - CGDisplayModeRelease(_glfwLibrary.NS.desktopMode); - [NSApp setDelegate:nil]; [_glfwLibrary.NS.delegate release]; _glfwLibrary.NS.delegate = nil; diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 97e903d7..cc1c1c91 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -90,7 +90,7 @@ typedef struct _GLFWlibraryNS double resolution; } timer; - CGDisplayModeRef desktopMode; + CGDisplayModeRef previousMode; CGEventSourceRef eventSource; id delegate; id autoreleasePool; diff --git a/src/fullscreen.c b/src/fullscreen.c index a169f196..37866261 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -150,11 +150,13 @@ GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor handle, int* count) //======================================================================== -// Get the desktop video mode +// Get the current video mode for the specified monitor //======================================================================== -GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode) +GLFWAPI void glfwGetVideoMode(GLFWmonitor handle, GLFWvidmode* mode) { + _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); @@ -163,11 +165,10 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode) if (mode == NULL) { - _glfwSetError(GLFW_INVALID_VALUE, - "glfwGetDesktopMode: Parameter 'mode' cannot be NULL"); + _glfwSetError(GLFW_INVALID_VALUE, NULL); return; } - _glfwPlatformGetDesktopMode(mode); + _glfwPlatformGetVideoMode(monitor, mode); } diff --git a/src/internal.h b/src/internal.h index ac0946b5..8d5266da 100755 --- a/src/internal.h +++ b/src/internal.h @@ -286,7 +286,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); // Video mode support GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count); -void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); +void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode); // Gamma ramp support void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index a22abdfc..eb9c0c70 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -268,18 +268,26 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) //======================================================================== -// Get the desktop video mode +// Get the current video mode for the specified monitor //======================================================================== -void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) +void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { DEVMODE dm; + WCHAR* deviceName; - // Get desktop display mode + deviceName = _glfwCreateWideStringFromUTF8(monitor->Win32.name); + if (!deviceName) + { + _glfwSetError(GLFW_PLATFORM_ERROR, "Win32: Failed to convert device name"); + return; + } + + ZeroMemory(&dm, sizeof(DEVMODE)); dm.dmSize = sizeof(DEVMODE); - EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm); - // Return desktop mode parameters + EnumDisplaySettings(deviceName, ENUM_REGISTRY_SETTINGS, &dm); + mode->width = dm.dmPelsWidth; mode->height = dm.dmPelsHeight; _glfwSplitBPP(dm.dmBitsPerPel, diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 64f543bf..5848b296 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -514,40 +514,18 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) //======================================================================== -// Get the desktop video mode +// Get the current video mode for the specified monitor //======================================================================== -void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) +void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { - int bpp; + _glfwSplitBPP(DefaultDepth(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen), + &mode->redBits, &mode->greenBits, &mode->blueBits); - // Get and split display depth - bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); - _glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits); - - if (_glfwLibrary.X11.FS.modeChanged) - { - if (_glfwLibrary.X11.RandR.available) - { -#if defined(_GLFW_HAS_XRANDR) - mode->width = _glfwLibrary.X11.FS.oldWidth; - mode->height = _glfwLibrary.X11.FS.oldHeight; -#endif /*_GLFW_HAS_XRANDR*/ - } - else if (_glfwLibrary.X11.VidMode.available) - { -#if defined(_GLFW_HAS_XF86VIDMODE) - mode->width = _glfwLibrary.X11.FS.oldMode.hdisplay; - mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay; -#endif /*_GLFW_HAS_XF86VIDMODE*/ - } - } - else - { - mode->width = DisplayWidth(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen); - mode->height = DisplayHeight(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen); - } + mode->width = DisplayWidth(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); + mode->height = DisplayHeight(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); } diff --git a/tests/fsfocus.c b/tests/fsfocus.c index 1c46d7af..6ae0cb45 100644 --- a/tests/fsfocus.c +++ b/tests/fsfocus.c @@ -24,7 +24,7 @@ //======================================================================== // // This test is used to test window activation and iconfication for -// fullscreen windows with a video mode differing from the desktop mode +// fullscreen windows with a video mode differing from the current mode // //======================================================================== diff --git a/tests/gamma.c b/tests/gamma.c index e74d5b43..37a78926 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -119,10 +119,10 @@ int main(int argc, char** argv) if (mode == GLFW_FULLSCREEN) { - GLFWvidmode desktop_mode; - glfwGetDesktopMode(&desktop_mode); - width = desktop_mode.width; - height = desktop_mode.height; + GLFWvidmode mode; + glfwGetVideoMode(glfwGetNextMonitor(NULL), &mode); + width = mode.width; + height = mode.height; } else { diff --git a/tests/iconify.c b/tests/iconify.c index 33b6f058..845bfea3 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -100,10 +100,10 @@ int main(int argc, char** argv) if (mode == GLFW_FULLSCREEN) { - GLFWvidmode desktop_mode; - glfwGetDesktopMode(&desktop_mode); - width = desktop_mode.width; - height = desktop_mode.height; + GLFWvidmode current_mode; + glfwGetVideoMode(glfwGetNextMonitor(NULL), ¤t_mode); + width = current_mode.width; + height = current_mode.height; } else { diff --git a/tests/modes.c b/tests/modes.c old mode 100755 new mode 100644 index 8a51726d..98837884 --- a/tests/modes.c +++ b/tests/modes.c @@ -93,11 +93,11 @@ static void key_callback(GLFWwindow dummy, int key, int action) static void list_modes(GLFWmonitor monitor) { int count, i; - GLFWvidmode desktop_mode; + GLFWvidmode mode; GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); - glfwGetDesktopMode(&desktop_mode); - printf("Desktop mode: %s\n", format_mode(&desktop_mode)); + glfwGetVideoMode(monitor, &mode); + printf("Current mode: %s\n", format_mode(&mode)); printf("Monitor %s (%ix%i mm):\n", glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), @@ -108,8 +108,8 @@ static void list_modes(GLFWmonitor monitor) { printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); - if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) - printf(" (desktop mode)"); + if (memcmp(&mode, modes + i, sizeof(GLFWvidmode)) == 0) + printf(" (current mode)"); putchar('\n'); }