Replace NSScreen with platform functions

This commit is contained in:
Camilla Berglund 2015-09-01 18:33:34 +02:00
parent 4ad00fa388
commit f6f0771770
2 changed files with 16 additions and 39 deletions

View File

@ -256,29 +256,12 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
monitors = calloc(displayCount, sizeof(_GLFWmonitor*)); monitors = calloc(displayCount, sizeof(_GLFWmonitor*));
CGGetOnlineDisplayList(displayCount, displays, &displayCount); CGGetOnlineDisplayList(displayCount, displays, &displayCount);
NSArray* screens = [NSScreen screens];
for (i = 0; i < displayCount; i++) for (i = 0; i < displayCount; i++)
{ {
NSUInteger j;
_GLFWmonitor* monitor; _GLFWmonitor* monitor;
CGDirectDisplayID screenDisplayID = CGDisplayMirrorsDisplay(displays[i]); if (CGDisplayIsAsleep(displays[i]))
if (screenDisplayID == kCGNullDirectDisplay)
screenDisplayID = displays[i];
for (j = 0; j < [screens count]; j++)
{
NSScreen* screen = [screens objectAtIndex:j];
NSDictionary* dictionary = [screen deviceDescription];
NSNumber* number = [dictionary objectForKey:@"NSScreenNumber"];
if ([number unsignedIntegerValue] == screenDisplayID)
break;
}
// Skip displays that has no screen
if (j == [screens count])
continue; continue;
const CGSize size = CGDisplayScreenSize(displays[i]); const CGSize size = CGDisplayScreenSize(displays[i]);

View File

@ -32,23 +32,6 @@
#include <crt_externs.h> #include <crt_externs.h>
// Returns the NSScreen corresponding to the specified CGDirectDisplayID
//
static NSScreen* getScreen(CGDirectDisplayID displayID)
{
NSArray* screens = [NSScreen screens];
for (NSScreen* screen in screens)
{
NSDictionary* dictionary = [screen deviceDescription];
NSNumber* number = [dictionary objectForKey:@"NSScreenNumber"];
if ([number unsignedIntegerValue] == displayID)
return screen;
}
return nil;
}
// Returns the specified standard cursor // Returns the specified standard cursor
// //
static NSCursor* getStandardCursor(int shape) static NSCursor* getStandardCursor(int shape)
@ -100,13 +83,16 @@ static void updateModeCursor(_GLFWwindow* window)
// //
static GLboolean enterFullscreenMode(_GLFWwindow* window) static GLboolean enterFullscreenMode(_GLFWwindow* window)
{ {
GLFWvidmode mode;
GLboolean status; GLboolean status;
int xpos, ypos;
status = _glfwSetVideoMode(window->monitor, &window->videoMode); status = _glfwSetVideoMode(window->monitor, &window->videoMode);
// NOTE: The window is resized despite mode setting failure to make _glfwPlatformGetVideoMode(window->monitor, &mode);
// glfwSetWindowSize more robust _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
[window->ns.object setFrame:[getScreen(window->monitor->ns.displayID) frame]
[window->ns.object setFrame:NSMakeRect(xpos, ypos, mode.width, mode.height)
display:YES]; display:YES];
return status; return status;
@ -864,7 +850,15 @@ static GLboolean createWindow(_GLFWwindow* window,
NSRect contentRect; NSRect contentRect;
if (wndconfig->monitor) if (wndconfig->monitor)
contentRect = [getScreen(wndconfig->monitor->ns.displayID) frame]; {
GLFWvidmode mode;
int xpos, ypos;
_glfwPlatformGetVideoMode(window->monitor, &mode);
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
contentRect = NSMakeRect(xpos, ypos, mode.width, mode.height);
}
else else
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height); contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);