mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 13:20:58 +00:00
Obtain screen object from displayID only when we need it
Apple's documentation of [NSScreen screens] mentions that, "The (screens) array should not be cached. Screens can be added, removed, or dynamically reconfigured at any time." Because of this, we simply obtain the screen from a displayID whenever we need it.
This commit is contained in:
parent
9b44ce8935
commit
676a9eafee
@ -269,4 +269,3 @@ const char* _glfwPlatformGetVersionString(void)
|
|||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
|||||||
|
|
||||||
monitor = _glfwAllocMonitor(name, size.width, size.height);
|
monitor = _glfwAllocMonitor(name, size.width, size.height);
|
||||||
monitor->ns.displayID = displays[i];
|
monitor->ns.displayID = displays[i];
|
||||||
monitor->ns.screen = [screens objectAtIndex:j];
|
|
||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
@ -427,4 +426,3 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* handle)
|
|||||||
_GLFW_REQUIRE_INIT_OR_RETURN(kCGNullDirectDisplay);
|
_GLFW_REQUIRE_INIT_OR_RETURN(kCGNullDirectDisplay);
|
||||||
return monitor->ns.displayID;
|
return monitor->ns.displayID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,6 @@ typedef struct _GLFWmonitorNS
|
|||||||
{
|
{
|
||||||
CGDirectDisplayID displayID;
|
CGDirectDisplayID displayID;
|
||||||
CGDisplayModeRef previousMode;
|
CGDisplayModeRef previousMode;
|
||||||
id screen;
|
|
||||||
|
|
||||||
} _GLFWmonitorNS;
|
} _GLFWmonitorNS;
|
||||||
|
|
||||||
|
@ -32,6 +32,27 @@
|
|||||||
#include <crt_externs.h>
|
#include <crt_externs.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Returns the screen that is specified by a displayID
|
||||||
|
//
|
||||||
|
static NSScreen *getScreen(CGDirectDisplayID displayID)
|
||||||
|
{
|
||||||
|
// NOTE: Apple's documentation of [NSScreen screens] mentions that,
|
||||||
|
// "The (screens) array should not be cached. Screens can be
|
||||||
|
// added, removed, or dynamically reconfigured at any time."
|
||||||
|
// Because of this, we simply obtain the screen from a
|
||||||
|
// displayID whenever we need it.
|
||||||
|
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)
|
||||||
@ -87,36 +108,10 @@ static GLboolean enterFullscreenMode(_GLFWwindow* window)
|
|||||||
|
|
||||||
status = _glfwSetVideoMode(window->monitor, &window->videoMode);
|
status = _glfwSetVideoMode(window->monitor, &window->videoMode);
|
||||||
|
|
||||||
// NOTE: Apple's documentation of [NSScreen screens] mentions that,
|
|
||||||
// "The [screens] array should not be cached. Screens can be
|
|
||||||
// added, removed, or dynamically reconfigured at any time."
|
|
||||||
// Because of this, window->monitor->ns.screen may not point
|
|
||||||
// to a valid object so [window->monitor->ns.screen frame]
|
|
||||||
// used below can crash an application. The follow code
|
|
||||||
// provides a quick-and-dirty fix to this problem.
|
|
||||||
NSScreen *cached = window->monitor->ns.screen;
|
|
||||||
NSArray *current = [NSScreen screens];
|
|
||||||
|
|
||||||
bool updated = YES;
|
|
||||||
for (NSScreen *screen in current)
|
|
||||||
if (cached == screen)
|
|
||||||
updated = NO;
|
|
||||||
|
|
||||||
if (updated)
|
|
||||||
for(NSScreen *screen in current) {
|
|
||||||
NSDictionary* dictionary = [screen deviceDescription];
|
|
||||||
NSNumber *number = [dictionary objectForKey:@"NSScreenNumber"];
|
|
||||||
if ([number unsignedIntegerValue] ==
|
|
||||||
window->monitor->ns.displayID) {
|
|
||||||
window->monitor->ns.screen = screen;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: The window is resized despite mode setting failure to make
|
// NOTE: The window is resized despite mode setting failure to make
|
||||||
// glfwSetWindowSize more robust
|
// glfwSetWindowSize more robust
|
||||||
[window->ns.object setFrame:[window->monitor->ns.screen frame]
|
[window->ns.object setFrame:[getScreen(window->monitor->ns.displayID) frame]
|
||||||
display:YES];
|
display:YES];
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -864,7 +859,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
NSRect contentRect;
|
NSRect contentRect;
|
||||||
|
|
||||||
if (wndconfig->monitor)
|
if (wndconfig->monitor)
|
||||||
contentRect = [wndconfig->monitor->ns.screen frame];
|
contentRect = [getScreen(wndconfig->monitor->ns.displayID) frame];
|
||||||
else
|
else
|
||||||
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
|
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user