1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-10-08 15:17:25 -04:00

Made glfwGetMonitorPos immediate.

This commit is contained in:
Camilla Berglund 2013-02-20 16:00:53 +01:00
parent a591cdeba6
commit 7b3783abe2
7 changed files with 76 additions and 45 deletions

View File

@ -231,11 +231,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
for (i = 0; i < monitorCount; i++) for (i = 0; i < monitorCount; i++)
{ {
const CGSize size = CGDisplayScreenSize(displays[i]); const CGSize size = CGDisplayScreenSize(displays[i]);
const CGRect bounds = CGDisplayBounds(displays[i]);
monitors[found] = _glfwCreateMonitor(getDisplayName(displays[i]), monitors[found] = _glfwCreateMonitor(getDisplayName(displays[i]),
size.width, size.height, size.width, size.height);
bounds.origin.x, bounds.origin.y);
monitors[found]->ns.displayID = displays[i]; monitors[found]->ns.displayID = displays[i];
found++; found++;
@ -258,6 +256,16 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
return monitors; return monitors;
} }
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
const CGRect bounds = CGDisplayBounds(monitor->ns.displayID);
if (xpos)
*xpos = (int) bounds.origin.x;
if (ypos)
*ypos = (int) bounds.origin.y;
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{ {
CFArrayRef modes; CFArrayRef modes;

View File

@ -273,8 +273,6 @@ struct _GLFWmonitor
// Physical dimensions in millimeters. // Physical dimensions in millimeters.
int widthMM, heightMM; int widthMM, heightMM;
// Logical orientation of the screen on the desktop
int positionX, positionY;
GLFWvidmode* modes; GLFWvidmode* modes;
int modeCount; int modeCount;
@ -363,6 +361,11 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
*/ */
_GLFWmonitor** _glfwPlatformGetMonitors(int* count); _GLFWmonitor** _glfwPlatformGetMonitors(int* count);
/*! @copydoc glfwGetMonitorPos
* @ingroup platform
*/
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
/*! @copydoc glfwGetVideoModes /*! @copydoc glfwGetVideoModes
* @ingroup platform * @ingroup platform
*/ */
@ -693,9 +696,7 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig);
/*! @ingroup utility /*! @ingroup utility
*/ */
_GLFWmonitor* _glfwCreateMonitor(const char* name, _GLFWmonitor* _glfwCreateMonitor(const char* name, int widthMM, int heightMM);
int widthMM, int heightMM,
int x, int y);
/*! @ingroup utility /*! @ingroup utility
*/ */

View File

@ -155,9 +155,7 @@ void _glfwInputMonitorChange(void)
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
_GLFWmonitor* _glfwCreateMonitor(const char* name, _GLFWmonitor* _glfwCreateMonitor(const char* name, int widthMM, int heightMM)
int widthMM, int heightMM,
int x, int y)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) calloc(1, sizeof(_GLFWmonitor)); _GLFWmonitor* monitor = (_GLFWmonitor*) calloc(1, sizeof(_GLFWmonitor));
if (!monitor) if (!monitor)
@ -169,8 +167,6 @@ _GLFWmonitor* _glfwCreateMonitor(const char* name,
monitor->name = strdup(name); monitor->name = strdup(name);
monitor->widthMM = widthMM; monitor->widthMM = widthMM;
monitor->heightMM = heightMM; monitor->heightMM = heightMM;
monitor->positionX = x;
monitor->positionY = y;
return monitor; return monitor;
} }
@ -281,10 +277,7 @@ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos)
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
if (xpos) _glfwPlatformGetMonitorPos(monitor, xpos, ypos);
*xpos = monitor->positionX;
if (ypos)
*ypos = monitor->positionY;
} }
GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* height) GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* height)

View File

@ -109,7 +109,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
// Enumerate display adapters // Enumerate display adapters
DISPLAY_DEVICE adapter, display; DISPLAY_DEVICE adapter, display;
DEVMODE settings;
char* name; char* name;
HDC dc; HDC dc;
@ -127,14 +126,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
continue; continue;
} }
ZeroMemory(&settings, sizeof(DEVMODE));
settings.dmSize = sizeof(DEVMODE);
EnumDisplaySettingsEx(adapter.DeviceName,
ENUM_CURRENT_SETTINGS,
&settings,
EDS_ROTATEDMODE);
if (found == size) if (found == size)
{ {
if (size) if (size)
@ -168,9 +159,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
monitors[found] = _glfwCreateMonitor(name, monitors[found] = _glfwCreateMonitor(name,
GetDeviceCaps(dc, HORZSIZE), GetDeviceCaps(dc, HORZSIZE),
GetDeviceCaps(dc, VERTSIZE), GetDeviceCaps(dc, VERTSIZE));
settings.dmPosition.x,
settings.dmPosition.y);
free(name); free(name);
DeleteDC(dc); DeleteDC(dc);
@ -196,6 +185,23 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
return monitors; return monitors;
} }
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
DEVMODE settings;
ZeroMemory(&settings, sizeof(DEVMODE));
settings.dmSize = sizeof(DEVMODE);
EnumDisplaySettingsEx(monitor->win32.name,
ENUM_CURRENT_SETTINGS,
&settings,
EDS_ROTATEDMODE);
if (xpos)
*xpos = settings.dmPosition.x;
if (ypos)
*ypos = settings.dmPosition.y;
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{ {
int modeIndex = 0, count = 0; int modeIndex = 0, count = 0;

View File

@ -691,7 +691,7 @@ static int createWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
int positionX, positionY, fullWidth, fullHeight; int xpos, ypos, fullWidth, fullHeight;
POINT cursorPos; POINT cursorPos;
WCHAR* wideTitle; WCHAR* wideTitle;
@ -702,8 +702,7 @@ static int createWindow(_GLFWwindow* window,
{ {
window->win32.dwStyle |= WS_POPUP; window->win32.dwStyle |= WS_POPUP;
positionX = wndconfig->monitor->positionX; _glfwPlatformGetMonitorPos(wndconfig->monitor, &xpos, &ypos);
positionY = wndconfig->monitor->positionY;
fullWidth = wndconfig->width; fullWidth = wndconfig->width;
fullHeight = wndconfig->height; fullHeight = wndconfig->height;
@ -719,8 +718,8 @@ static int createWindow(_GLFWwindow* window,
window->win32.dwExStyle |= WS_EX_WINDOWEDGE; window->win32.dwExStyle |= WS_EX_WINDOWEDGE;
} }
positionX = CW_USEDEFAULT; xpos = CW_USEDEFAULT;
positionY = CW_USEDEFAULT; ypos = CW_USEDEFAULT;
getFullWindowSize(window, getFullWindowSize(window,
wndconfig->width, wndconfig->height, wndconfig->width, wndconfig->height,
@ -739,7 +738,7 @@ static int createWindow(_GLFWwindow* window,
_GLFW_WNDCLASSNAME, _GLFW_WNDCLASSNAME,
wideTitle, wideTitle,
window->win32.dwStyle, window->win32.dwStyle,
positionX, positionY, xpos, ypos,
fullWidth, fullHeight, fullWidth, fullHeight,
NULL, // No parent window NULL, // No parent window
NULL, // No window menu NULL, // No window menu

View File

@ -193,8 +193,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
} }
monitors[*found] = _glfwCreateMonitor(oi->name, monitors[*found] = _glfwCreateMonitor(oi->name,
oi->mm_width, oi->mm_height, oi->mm_width, oi->mm_height);
ci->x, ci->y);
monitors[*found]->x11.output = output; monitors[*found]->x11.output = output;
monitors[*found]->x11.crtc = oi->crtc; monitors[*found]->x11.crtc = oi->crtc;
@ -220,8 +219,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
} }
else else
{ {
int widthMM, heightMM;
monitors = (_GLFWmonitor**) calloc(1, sizeof(_GLFWmonitor*)); monitors = (_GLFWmonitor**) calloc(1, sizeof(_GLFWmonitor*));
if (!monitors) if (!monitors)
{ {
@ -229,16 +226,44 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
return NULL; return NULL;
} }
widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen); monitors[0] = _glfwCreateMonitor("Display",
heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen); DisplayWidthMM(_glfw.x11.display,
_glfw.x11.screen),
monitors[0] = _glfwCreateMonitor("Display", widthMM, heightMM, 0, 0); DisplayHeightMM(_glfw.x11.display,
_glfw.x11.screen));
*found = 1; *found = 1;
} }
return monitors; return monitors;
} }
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
if (_glfw.x11.randr.available)
{
XRRScreenResources* sr;
XRRCrtcInfo* ci;
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
if (xpos)
*xpos = ci->x;
if (ypos)
*ypos = ci->y;
XRRFreeCrtcInfo(ci);
XRRFreeScreenResources(sr);
}
else
{
if (xpos)
*xpos = 0;
if (ypos)
*ypos = 0;
}
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{ {
GLFWvidmode* result; GLFWvidmode* result;

View File

@ -199,8 +199,7 @@ static GLboolean createWindow(_GLFWwindow* window,
if (wndconfig->monitor) if (wndconfig->monitor)
{ {
hints->flags |= PPosition; hints->flags |= PPosition;
hints->x = wndconfig->monitor->positionX; _glfwPlatformGetMonitorPos(wndconfig->monitor, &hints->x, &hints->y);
hints->y = wndconfig->monitor->positionY;
} }
if (!wndconfig->resizable) if (!wndconfig->resizable)