Reintroduced glfwGetWindowPos, glfwSetWindowPos.

This commit is contained in:
Camilla Berglund
2013-01-24 19:30:31 +01:00
parent ee5f30ea8f
commit 7c1932381b
11 changed files with 191 additions and 125 deletions
+26 -19
View File
@@ -67,26 +67,18 @@
{
[window->nsgl.context update];
NSRect contentRect =
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwInputWindowSize(window, width, height);
}
- (void)windowDidMove:(NSNotification *)notification
{
[window->nsgl.context update];
NSRect contentRect =
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
CGPoint flippedPos = CGPointMake(contentRect.origin.x - mainScreenOrigin.x,
mainScreenHeight - contentRect.origin.y -
mainScreenOrigin.y - window->height);
_glfwInputWindowPos(window, flippedPos.x, flippedPos.y);
int x, y;
_glfwPlatformGetWindowPos(window, &x, &y);
_glfwInputWindowPos(window, x, y);
}
- (void)windowDidMiniaturize:(NSNotification *)notification
@@ -690,11 +682,8 @@ static GLboolean createWindow(_GLFWwindow* window,
styleMask |= NSResizableWindowMask;
}
NSRect contentRect = NSMakeRect(wndconfig->positionX, wndconfig->positionY,
wndconfig->width, wndconfig->height);
window->ns.object = [[NSWindow alloc]
initWithContentRect:contentRect
initWithContentRect:NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
@@ -822,9 +811,27 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
[window->ns.object setTitle:[NSString stringWithUTF8String:title]];
}
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
{
const NSRect contentRect =
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
if (xpos)
*xpos = contentRect.origin.x;
if (ypos)
*ypos = contentRect.origin.y;
}
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
{
const NSRect frameRect =
[window->ns.object frameRectForContentRect:NSMakeRect(x, y, 0, 0)];
[window->ns.object setFrameOrigin:frameRect.origin];
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
NSRect contentRect =
const NSRect contentRect =
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
if (width)
+8 -5
View File
@@ -144,8 +144,6 @@ struct _GLFWhints
GLboolean glDebug;
int glProfile;
int glRobustness;
int positionX;
int positionY;
};
@@ -162,8 +160,6 @@ struct _GLFWwndconfig
const char* title;
GLboolean resizable;
GLboolean visible;
int positionX;
int positionY;
int clientAPI;
int glMajor;
int glMinor;
@@ -207,7 +203,6 @@ struct _GLFWwindow
struct _GLFWwindow* next;
// Window settings and state
int positionX, positionY;
GLboolean iconified;
GLboolean resizable;
GLboolean visible;
@@ -459,6 +454,14 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window);
*/
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
/*! @ingroup platform
*/
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
/*! @ingroup platform
*/
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
/*! @ingroup platform
*/
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
+41 -31
View File
@@ -715,16 +715,22 @@ static int createWindow(_GLFWwindow* window,
const _GLFWfbconfig* fbconfig)
{
int positionX, positionY, fullWidth, fullHeight;
POINT pos;
POINT cursorPos;
WCHAR* wideTitle;
// Set window styles common to all window modes
window->win32.dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
window->win32.dwExStyle = WS_EX_APPWINDOW;
// Add mode-dependent window styles
if (window->monitor)
{
window->win32.dwStyle |= WS_POPUP;
positionX = wndconfig->monitor->positionX;
positionY = wndconfig->monitor->positionY;
fullWidth = wndconfig->width;
fullHeight = wndconfig->height;
}
else
{
window->win32.dwStyle |= WS_OVERLAPPED | WS_CAPTION |
@@ -735,28 +741,13 @@ static int createWindow(_GLFWwindow* window,
window->win32.dwStyle |= WS_MAXIMIZEBOX | WS_SIZEBOX;
window->win32.dwExStyle |= WS_EX_WINDOWEDGE;
}
}
// Adjust window size for frame and title bar
getFullWindowSize(window,
wndconfig->width, wndconfig->height,
&fullWidth, &fullHeight);
positionX = CW_USEDEFAULT;
positionY = CW_USEDEFAULT;
if (window->monitor)
{
// Fullscreen windows are always opened in the upper left corner
// regardless of the desktop working area
positionX = wndconfig->monitor->positionX;
positionY = wndconfig->monitor->positionY;
}
else
{
RECT wa;
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
// Adjust window position to working area
positionX = wndconfig->positionX + wa.left;
positionY = wndconfig->positionY + wa.top;
getFullWindowSize(window,
wndconfig->width, wndconfig->height,
&fullWidth, &fullHeight);
}
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
@@ -772,10 +763,9 @@ static int createWindow(_GLFWwindow* window,
wideTitle,
window->win32.dwStyle,
positionX, positionY,
fullWidth, // Decorated window width
fullHeight, // Decorated window height
NULL, // No parent window
NULL, // No menu
fullWidth, fullHeight,
NULL, // No parent window
NULL, // No window menu
GetModuleHandle(NULL),
window); // Pass GLFW window to WM_CREATE
@@ -788,10 +778,10 @@ static int createWindow(_GLFWwindow* window,
}
// Initialize cursor position data
GetCursorPos(&pos);
ScreenToClient(window->win32.handle, &pos);
window->win32.oldCursorX = window->cursorPosX = pos.x;
window->win32.oldCursorY = window->cursorPosY = pos.y;
GetCursorPos(&cursorPos);
ScreenToClient(window->win32.handle, &cursorPos);
window->win32.oldCursorX = window->cursorPosX = cursorPos.x;
window->win32.oldCursorY = window->cursorPosY = cursorPos.y;
if (!_glfwCreateContext(window, wndconfig, fbconfig))
return GL_FALSE;
@@ -917,6 +907,26 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
free(wideTitle);
}
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
{
POINT pos = { 0, 0 };
ClientToScreen(window->win32.handle, &pos);
if (xpos)
*xpos = pos.x;
if (ypos)
*ypos = pos.y;
}
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
{
RECT rect = { xpos, ypos, xpos, ypos };
AdjustWindowRectEx(&rect, window->win32.dwStyle,
FALSE, window->win32.dwExStyle);
SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
RECT area;
+33 -22
View File
@@ -94,12 +94,6 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
if (window->positionX == x && window->positionY == y)
return;
window->positionX = x;
window->positionY = y;
if (window->callbacks.pos)
window->callbacks.pos((GLFWwindow*) window, x, y);
}
@@ -189,8 +183,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
wndconfig.title = title;
wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE;
wndconfig.positionX = _glfw.hints.positionX;
wndconfig.positionY = _glfw.hints.positionY;
wndconfig.clientAPI = _glfw.hints.clientAPI;
wndconfig.glMajor = _glfw.hints.glMajor;
wndconfig.glMinor = _glfw.hints.glMinor;
@@ -298,10 +290,6 @@ void glfwDefaultWindowHints(void)
_glfw.hints.resizable = GL_TRUE;
_glfw.hints.visible = GL_TRUE;
// The default window position is the upper left corner of the screen
_glfw.hints.positionX = 0;
_glfw.hints.positionY = 0;
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil
_glfw.hints.redBits = 8;
_glfw.hints.greenBits = 8;
@@ -362,12 +350,6 @@ GLFWAPI void glfwWindowHint(int target, int hint)
case GLFW_VISIBLE:
_glfw.hints.visible = hint;
break;
case GLFW_POSITION_X:
_glfw.hints.positionX = hint;
break;
case GLFW_POSITION_Y:
_glfw.hints.positionY = hint;
break;
case GLFW_SAMPLES:
_glfw.hints.samples = hint;
break;
@@ -455,6 +437,39 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
_glfwPlatformSetWindowTitle(window, title);
}
GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformGetWindowPos(window, xpos, ypos);
}
GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->monitor)
{
_glfwInputError(GLFW_INVALID_VALUE,
"Fullscreen windows cannot be positioned");
return;
}
_glfwPlatformSetWindowPos(window, xpos, ypos);
}
GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
@@ -579,10 +594,6 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow* handle, int param)
return window->resizable;
case GLFW_VISIBLE:
return window->visible;
case GLFW_POSITION_X:
return window->positionX;
case GLFW_POSITION_Y:
return window->positionY;
case GLFW_CLIENT_API:
return window->clientAPI;
case GLFW_CONTEXT_VERSION_MAJOR:
-6
View File
@@ -96,12 +96,6 @@ typedef struct _GLFWwindowX11
GLboolean cursorCentered; // True if cursor was moved since last poll
int cursorPosX, cursorPosY;
// Window position hint (commited the first time the window is shown)
GLboolean windowPosSet; // False until the window position has
// been set
int positionX; // The window position to be set the
int positionY; // first time the window is shown
} _GLFWwindowX11;
+20 -23
View File
@@ -120,7 +120,7 @@ static GLboolean createWindow(_GLFWwindow* window,
window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfw.x11.root,
wndconfig->positionX, wndconfig->positionY,
0, 0,
wndconfig->width, wndconfig->height,
0, // Border width
visual->depth, // Color depth
@@ -137,12 +137,6 @@ static GLboolean createWindow(_GLFWwindow* window,
_glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
return GL_FALSE;
}
// Request a window position to be set once the window is shown
// (see _glfwPlatformShowWindow)
window->x11.windowPosSet = GL_FALSE;
window->x11.positionX = wndconfig->positionX;
window->x11.positionY = wndconfig->positionY;
}
if (window->monitor && !_glfw.x11.hasEWMH)
@@ -208,13 +202,6 @@ static GLboolean createWindow(_GLFWwindow* window,
// Set ICCCM WM_NORMAL_HINTS property (even if no parts are set)
{
XSizeHints* hints = XAllocSizeHints();
if (!hints)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"X11: Failed to allocate size hints");
return GL_FALSE;
}
hints->flags = 0;
if (wndconfig->monitor)
@@ -896,6 +883,25 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
}
}
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
{
Window child;
int x, y;
XTranslateCoordinates(_glfw.x11.display, window->x11.handle, _glfw.x11.root,
0, 0, &x, &y, &child);
if (xpos)
*xpos = x;
if (ypos)
*ypos = y;
}
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
{
XMoveWindow(_glfw.x11.display, window->x11.handle, xpos, ypos);
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
{
XWindowAttributes attribs;
@@ -967,15 +973,6 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
{
XMapRaised(_glfw.x11.display, window->x11.handle);
XFlush(_glfw.x11.display);
// Set the window position the first time the window is shown
// Note: XMoveWindow has no effect before the window has been mapped.
if (!window->x11.windowPosSet)
{
XMoveWindow(_glfw.x11.display, window->x11.handle,
window->x11.positionX, window->x11.positionY);
window->x11.windowPosSet = GL_TRUE;
}
}
void _glfwPlatformHideWindow(_GLFWwindow* window)