mirror of
https://github.com/glfw/glfw.git
synced 2026-09-19 15:25:50 +00:00
Introduced window positioning hints and window position properties
This commit is contained in:
+1
-1
@@ -686,7 +686,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
styleMask = NSBorderlessWindowMask;
|
||||
|
||||
window->NS.object = [[NSWindow alloc]
|
||||
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
|
||||
initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height)
|
||||
styleMask:styleMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
@@ -107,6 +107,8 @@ struct _GLFWhints
|
||||
GLboolean glDebug;
|
||||
int glProfile;
|
||||
int glRobustness;
|
||||
int positionX;
|
||||
int positionY;
|
||||
};
|
||||
|
||||
|
||||
@@ -123,6 +125,8 @@ struct _GLFWwndconfig
|
||||
int refreshRate;
|
||||
GLboolean resizable;
|
||||
GLboolean visible;
|
||||
int positionX;
|
||||
int positionY;
|
||||
int clientAPI;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
|
||||
@@ -772,7 +772,11 @@ static int createWindow(_GLFWwindow* window,
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
wa.left = wa.top = 0;
|
||||
else
|
||||
{
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
||||
wa.left += wndconfig->positionX;
|
||||
wa.top += wndconfig->positionY;
|
||||
}
|
||||
|
||||
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
||||
if (!wideTitle)
|
||||
|
||||
@@ -238,6 +238,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
||||
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
|
||||
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.positionX = _glfwLibrary.hints.positionX;
|
||||
wndconfig.positionY = _glfwLibrary.hints.positionY;
|
||||
wndconfig.clientAPI = _glfwLibrary.hints.clientAPI;
|
||||
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
|
||||
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
|
||||
@@ -369,6 +371,10 @@ void glfwDefaultWindowHints(void)
|
||||
_glfwLibrary.hints.resizable = GL_TRUE;
|
||||
_glfwLibrary.hints.visible = GL_TRUE;
|
||||
|
||||
// The default window position is the upper left corner of the screen
|
||||
_glfwLibrary.hints.positionX = 0;
|
||||
_glfwLibrary.hints.positionY = 0;
|
||||
|
||||
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil
|
||||
_glfwLibrary.hints.redBits = 8;
|
||||
_glfwLibrary.hints.greenBits = 8;
|
||||
@@ -437,6 +443,12 @@ GLFWAPI void glfwWindowHint(int target, int hint)
|
||||
case GLFW_VISIBLE:
|
||||
_glfwLibrary.hints.visible = hint;
|
||||
break;
|
||||
case GLFW_POSITION_X:
|
||||
_glfwLibrary.hints.positionX = hint;
|
||||
break;
|
||||
case GLFW_POSITION_Y:
|
||||
_glfwLibrary.hints.positionY = hint;
|
||||
break;
|
||||
case GLFW_FSAA_SAMPLES:
|
||||
_glfwLibrary.hints.samples = hint;
|
||||
break;
|
||||
@@ -747,6 +759,10 @@ 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_OPENGL_VERSION_MAJOR:
|
||||
|
||||
@@ -141,6 +141,12 @@ 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;
|
||||
|
||||
|
||||
|
||||
+16
-1
@@ -119,7 +119,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
|
||||
window->X11.handle = XCreateWindow(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.root,
|
||||
0, 0, // Position
|
||||
wndconfig->positionX, wndconfig->positionY,
|
||||
window->width, window->height,
|
||||
0, // Border width
|
||||
visual->depth, // Color depth
|
||||
@@ -136,6 +136,12 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
_glfwSetError(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->mode == GLFW_FULLSCREEN && !_glfwLibrary.X11.hasEWMH)
|
||||
@@ -1060,6 +1066,15 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||
{
|
||||
XMapRaised(_glfwLibrary.X11.display, window->X11.handle);
|
||||
XFlush(_glfwLibrary.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(_glfwLibrary.X11.display, window->X11.handle,
|
||||
window->X11.positionX, window->X11.positionY);
|
||||
window->X11.windowPosSet = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user