|
|
|
@ -31,6 +31,7 @@ |
|
|
|
|
#include "internal.h" |
|
|
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
@ -38,108 +39,115 @@ |
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Initialize the monitor list
|
|
|
|
|
// Create a monitor struct from the specified information
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
void _glfwInitMonitors(void) |
|
|
|
|
_GLFWmonitor* _glfwCreateMonitor(const char* name, |
|
|
|
|
int physicalWidth, int physicalHeight, |
|
|
|
|
int screenX, int screenY) |
|
|
|
|
{ |
|
|
|
|
_glfwLibrary.monitorListHead = _glfwCreateMonitors(); |
|
|
|
|
_GLFWmonitor* monitor = (_GLFWmonitor*) calloc(1, sizeof(_GLFWmonitor)); |
|
|
|
|
if (!monitor) |
|
|
|
|
{ |
|
|
|
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
monitor->name = strdup(name); |
|
|
|
|
monitor->physicalWidth = physicalWidth; |
|
|
|
|
monitor->physicalHeight = physicalHeight; |
|
|
|
|
monitor->screenX = screenX; |
|
|
|
|
monitor->screenY = screenY; |
|
|
|
|
|
|
|
|
|
return monitor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Refresh monitor list and notify callback
|
|
|
|
|
// Destroy the specified monitor
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
void _glfwRefreshMonitors(void) |
|
|
|
|
void _glfwDestroyMonitor(_GLFWmonitor* monitor) |
|
|
|
|
{ |
|
|
|
|
_GLFWmonitor* newMonitorList; |
|
|
|
|
_GLFWmonitor* curNewMonitor; |
|
|
|
|
_GLFWmonitor* curOldMonitor; |
|
|
|
|
|
|
|
|
|
newMonitorList = _glfwCreateMonitors(); |
|
|
|
|
curNewMonitor = newMonitorList; |
|
|
|
|
curOldMonitor = _glfwLibrary.monitorListHead; |
|
|
|
|
|
|
|
|
|
while (_glfwLibrary.monitorCallback && (curNewMonitor || curOldMonitor)) |
|
|
|
|
{ |
|
|
|
|
_GLFWmonitor* lookAheadOldMonitor; |
|
|
|
|
_GLFWmonitor* lookAheadNewMonitor; |
|
|
|
|
if (monitor == NULL) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (curOldMonitor && curNewMonitor && !strcmp(curOldMonitor->name, curOldMonitor->name)) |
|
|
|
|
{ |
|
|
|
|
curNewMonitor = curNewMonitor->next; |
|
|
|
|
curOldMonitor = curOldMonitor->next; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
_glfwPlatformDestroyMonitor(monitor); |
|
|
|
|
|
|
|
|
|
if (curNewMonitor && !curOldMonitor) |
|
|
|
|
{ |
|
|
|
|
_glfwLibrary.monitorCallback(curNewMonitor, GLFW_MONITOR_CONNECTED); |
|
|
|
|
curNewMonitor = curNewMonitor->next; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
free(monitor->modes); |
|
|
|
|
free(monitor->name); |
|
|
|
|
free(monitor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!curNewMonitor && curOldMonitor) |
|
|
|
|
{ |
|
|
|
|
_glfwLibrary.monitorCallback(curOldMonitor, GLFW_MONITOR_DISCONNECTED); |
|
|
|
|
curOldMonitor = curOldMonitor->next; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lookAheadOldMonitor = curOldMonitor->next; |
|
|
|
|
lookAheadNewMonitor = curNewMonitor->next; |
|
|
|
|
//========================================================================
|
|
|
|
|
// Enumerate monitors and notify user of changes
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
while (lookAheadOldMonitor && !strcmp(curNewMonitor->name, lookAheadOldMonitor->name)) |
|
|
|
|
lookAheadOldMonitor = lookAheadOldMonitor->next; |
|
|
|
|
void _glfwInputMonitorChange(void) |
|
|
|
|
{ |
|
|
|
|
int i, j, monitorCount; |
|
|
|
|
_GLFWmonitor** monitors; |
|
|
|
|
|
|
|
|
|
while (lookAheadNewMonitor && !strcmp(curOldMonitor->name, lookAheadNewMonitor->name)) |
|
|
|
|
lookAheadNewMonitor = lookAheadNewMonitor->next; |
|
|
|
|
monitors = _glfwPlatformGetMonitors(&monitorCount); |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
for (i = 0; i < monitorCount; i++) |
|
|
|
|
{ |
|
|
|
|
for (j = 0; j < _glfwLibrary.monitorCount; j++) |
|
|
|
|
{ |
|
|
|
|
while (strcmp(curOldMonitor->name, lookAheadOldMonitor->name)) |
|
|
|
|
if (_glfwLibrary.monitors[j] == NULL) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
if (strcmp(monitors[i]->name, _glfwLibrary.monitors[j]->name) == 0) |
|
|
|
|
{ |
|
|
|
|
_glfwLibrary.monitorCallback(curOldMonitor, GLFW_MONITOR_DISCONNECTED); |
|
|
|
|
curOldMonitor = curOldMonitor->next; |
|
|
|
|
// This monitor was connected before, so re-use the existing
|
|
|
|
|
// monitor object to preserve its address and user pointer
|
|
|
|
|
|
|
|
|
|
_glfwDestroyMonitor(monitors[i]); |
|
|
|
|
monitors[i] = _glfwLibrary.monitors[j]; |
|
|
|
|
_glfwLibrary.monitors[j] = NULL; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!lookAheadNewMonitor) |
|
|
|
|
if (j == _glfwLibrary.monitorCount) |
|
|
|
|
{ |
|
|
|
|
// 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; |
|
|
|
|
} |
|
|
|
|
// This monitor was not connected before
|
|
|
|
|
_glfwLibrary.monitorCallback(monitors[i], GLFW_MONITOR_CONNECTED); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_glfwTerminateMonitors(); |
|
|
|
|
_glfwLibrary.monitorListHead = newMonitorList; |
|
|
|
|
for (i = 0; i < _glfwLibrary.monitorCount; i++) |
|
|
|
|
{ |
|
|
|
|
if (_glfwLibrary.monitors[i] == NULL) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
// This monitor is no longer connected
|
|
|
|
|
_glfwLibrary.monitorCallback(_glfwLibrary.monitors[i], |
|
|
|
|
GLFW_MONITOR_DISCONNECTED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_glfwDestroyMonitors(); |
|
|
|
|
|
|
|
|
|
_glfwLibrary.monitors = monitors; |
|
|
|
|
_glfwLibrary.monitorCount = monitorCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Delete the monitor list
|
|
|
|
|
// Destroy all monitors
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
void _glfwTerminateMonitors(void) |
|
|
|
|
void _glfwDestroyMonitors(void) |
|
|
|
|
{ |
|
|
|
|
while (_glfwLibrary.monitorListHead) |
|
|
|
|
_glfwLibrary.monitorListHead = _glfwDestroyMonitor(_glfwLibrary.monitorListHead); |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < _glfwLibrary.monitorCount; i++) |
|
|
|
|
_glfwDestroyMonitor(_glfwLibrary.monitors[i]); |
|
|
|
|
|
|
|
|
|
free(_glfwLibrary.monitors); |
|
|
|
|
_glfwLibrary.monitors = NULL; |
|
|
|
|
_glfwLibrary.monitorCount = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,26 +156,41 @@ void _glfwTerminateMonitors(void) |
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Iterate through connected monitors
|
|
|
|
|
// Return the currently connected monitors
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor handle) |
|
|
|
|
GLFWAPI GLFWmonitor* glfwGetMonitors(int* count) |
|
|
|
|
{ |
|
|
|
|
_GLFWmonitor* iterator = (_GLFWmonitor*) handle; |
|
|
|
|
_GLFWmonitor* result; |
|
|
|
|
|
|
|
|
|
if (!_glfwInitialized) |
|
|
|
|
{ |
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (iterator == NULL) |
|
|
|
|
result = _glfwLibrary.monitorListHead; |
|
|
|
|
else |
|
|
|
|
result = iterator->next; |
|
|
|
|
if (count == NULL) |
|
|
|
|
{ |
|
|
|
|
_glfwSetError(GLFW_INVALID_VALUE, NULL); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*count = _glfwLibrary.monitorCount; |
|
|
|
|
return (GLFWmonitor*) _glfwLibrary.monitors; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Get the primary monitor
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
GLFWAPI GLFWmonitor glfwGetPrimaryMonitor(void) |
|
|
|
|
{ |
|
|
|
|
if (!_glfwInitialized) |
|
|
|
|
{ |
|
|
|
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
return _glfwLibrary.monitors[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|