Replaced glfwGetDesktopMode with glfwGetVideoMode.

This commit is contained in:
Camilla Berglund 2012-08-30 01:53:23 +02:00
parent e0ce920191
commit 89b42d084d
13 changed files with 56 additions and 66 deletions

View File

@ -539,7 +539,7 @@ GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator);
/* Video mode functions */ /* Video mode functions */
GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor monitor, int* count); GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor monitor, int* count);
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); GLFWAPI void glfwGetVideoMode(GLFWmonitor monitor, GLFWvidmode* mode);
/* Gamma ramp functions */ /* Gamma ramp functions */
GLFWAPI void glfwSetGamma(float gamma); GLFWAPI void glfwSetGamma(float gamma);

View File

@ -303,6 +303,7 @@ version of GLFW.</p>
<li>Renamed <code>glfwGetJoystickPos</code> to <code>glfwGetJoystickAxes</code> to match <code>glfwGetJoystickButtons</code></li> <li>Renamed <code>glfwGetJoystickPos</code> to <code>glfwGetJoystickAxes</code> to match <code>glfwGetJoystickButtons</code></li>
<li>Renamed mouse position functions to cursor position equivalents</li> <li>Renamed mouse position functions to cursor position equivalents</li>
<li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li> <li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li>
<li>Replaced <code>glfwGetDesktopMode</code> width <code>glfwGetVideoMode</code></li>
<li>Replaced ad hoc build system with CMake</li> <li>Replaced ad hoc build system with CMake</li>
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li> <li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
<li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li> <li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>

View File

@ -167,6 +167,8 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
return GL_FALSE; return GL_FALSE;
} }
_glfwLibrary.NS.previousMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
CGDisplayCapture(CGMainDisplayID()); CGDisplayCapture(CGMainDisplayID());
CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL); CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL);
@ -182,7 +184,7 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
void _glfwRestoreVideoMode(void) void _glfwRestoreVideoMode(void)
{ {
CGDisplaySetDisplayMode(CGMainDisplayID(), CGDisplaySetDisplayMode(CGMainDisplayID(),
_glfwLibrary.NS.desktopMode, _glfwLibrary.NS.previousMode,
NULL); NULL);
CGDisplayRelease(CGMainDisplayID()); 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);
} }

View File

@ -92,8 +92,6 @@ int _glfwPlatformInit(void)
changeToResourcesDirectory(); changeToResourcesDirectory();
_glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
// Save the original gamma ramp // Save the original gamma ramp
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID()); _glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
@ -132,8 +130,6 @@ int _glfwPlatformTerminate(void)
if (_glfwLibrary.rampChanged) if (_glfwLibrary.rampChanged)
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
CGDisplayModeRelease(_glfwLibrary.NS.desktopMode);
[NSApp setDelegate:nil]; [NSApp setDelegate:nil];
[_glfwLibrary.NS.delegate release]; [_glfwLibrary.NS.delegate release];
_glfwLibrary.NS.delegate = nil; _glfwLibrary.NS.delegate = nil;

View File

@ -90,7 +90,7 @@ typedef struct _GLFWlibraryNS
double resolution; double resolution;
} timer; } timer;
CGDisplayModeRef desktopMode; CGDisplayModeRef previousMode;
CGEventSourceRef eventSource; CGEventSourceRef eventSource;
id delegate; id delegate;
id autoreleasePool; id autoreleasePool;

View File

@ -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) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
@ -163,11 +165,10 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
if (mode == NULL) if (mode == NULL)
{ {
_glfwSetError(GLFW_INVALID_VALUE, _glfwSetError(GLFW_INVALID_VALUE, NULL);
"glfwGetDesktopMode: Parameter 'mode' cannot be NULL");
return; return;
} }
_glfwPlatformGetDesktopMode(mode); _glfwPlatformGetVideoMode(monitor, mode);
} }

View File

@ -286,7 +286,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
// Video mode support // Video mode support
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count); GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
// Gamma ramp support // Gamma ramp support
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);

View File

@ -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; 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); 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->width = dm.dmPelsWidth;
mode->height = dm.dmPelsHeight; mode->height = dm.dmPelsHeight;
_glfwSplitBPP(dm.dmBitsPerPel, _glfwSplitBPP(dm.dmBitsPerPel,

View File

@ -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, mode->width = DisplayWidth(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen); _glfwLibrary.X11.screen);
mode->height = DisplayHeight(_glfwLibrary.X11.display, mode->height = DisplayHeight(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen); _glfwLibrary.X11.screen);
} }
}

View File

@ -24,7 +24,7 @@
//======================================================================== //========================================================================
// //
// This test is used to test window activation and iconfication for // 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
// //
//======================================================================== //========================================================================

View File

@ -119,10 +119,10 @@ int main(int argc, char** argv)
if (mode == GLFW_FULLSCREEN) if (mode == GLFW_FULLSCREEN)
{ {
GLFWvidmode desktop_mode; GLFWvidmode mode;
glfwGetDesktopMode(&desktop_mode); glfwGetVideoMode(glfwGetNextMonitor(NULL), &mode);
width = desktop_mode.width; width = mode.width;
height = desktop_mode.height; height = mode.height;
} }
else else
{ {

View File

@ -100,10 +100,10 @@ int main(int argc, char** argv)
if (mode == GLFW_FULLSCREEN) if (mode == GLFW_FULLSCREEN)
{ {
GLFWvidmode desktop_mode; GLFWvidmode current_mode;
glfwGetDesktopMode(&desktop_mode); glfwGetVideoMode(glfwGetNextMonitor(NULL), &current_mode);
width = desktop_mode.width; width = current_mode.width;
height = desktop_mode.height; height = current_mode.height;
} }
else else
{ {

10
tests/modes.c Executable file → Normal file
View File

@ -93,11 +93,11 @@ static void key_callback(GLFWwindow dummy, int key, int action)
static void list_modes(GLFWmonitor monitor) static void list_modes(GLFWmonitor monitor)
{ {
int count, i; int count, i;
GLFWvidmode desktop_mode; GLFWvidmode mode;
GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
glfwGetDesktopMode(&desktop_mode); glfwGetVideoMode(monitor, &mode);
printf("Desktop mode: %s\n", format_mode(&desktop_mode)); printf("Current mode: %s\n", format_mode(&mode));
printf("Monitor %s (%ix%i mm):\n", printf("Monitor %s (%ix%i mm):\n",
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), 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)); printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) if (memcmp(&mode, modes + i, sizeof(GLFWvidmode)) == 0)
printf(" (desktop mode)"); printf(" (current mode)");
putchar('\n'); putchar('\n');
} }