Introduced window positioning hints and window position properties

This commit is contained in:
m@bitsnbites.eu 2012-10-28 00:23:28 +02:00 committed by m
parent 2b4c556cd0
commit c9f4dedd96
10 changed files with 59 additions and 14 deletions

View File

@ -413,6 +413,8 @@ extern "C" {
#define GLFW_OPENGL_ROBUSTNESS 0x00022006
#define GLFW_RESIZABLE 0x00022007
#define GLFW_VISIBLE 0x00022008
#define GLFW_POSITION_X 0x00022009
#define GLFW_POSITION_Y 0x0002200A
/* GLFW_CLIENT_API tokens */
#define GLFW_OPENGL_API 0x00000001

View File

@ -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];

View File

@ -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;

View File

@ -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)

View File

@ -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:

View File

@ -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;

View File

@ -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;
}
}

View File

@ -51,10 +51,12 @@ static int window_close_callback(GLFWwindow window)
return GL_FALSE;
}
static GLFWwindow open_window(const char* title, GLFWwindow share)
static GLFWwindow open_window(const char* title, GLFWwindow share, int posX, int posY)
{
GLFWwindow window;
glfwWindowHint(GLFW_POSITION_X, posX);
glfwWindowHint(GLFW_POSITION_Y, posY);
window = glfwCreateWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
if (!window)
return NULL;
@ -125,7 +127,6 @@ static void draw_quad(GLuint texture)
int main(int argc, char** argv)
{
GLuint texture;
int x, y;
if (!glfwInit())
{
@ -133,7 +134,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
windows[0] = open_window("First", NULL);
windows[0] = open_window("First", NULL, 0, 0);
if (!windows[0])
{
fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError()));
@ -147,7 +148,8 @@ int main(int argc, char** argv)
// It will then be shared with the second context, created below
texture = create_texture();
windows[1] = open_window("Second", windows[0]);
// Put the second window to the right of the first one
windows[1] = open_window("Second", windows[0], WIDTH + 50, 0);
if (!windows[1])
{
fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError()));
@ -161,10 +163,6 @@ int main(int argc, char** argv)
glColor3f(0.6f, 0.f, 0.6f);
glfwCopyContext(windows[0], windows[1], GL_CURRENT_BIT);
// Put the second window to the right of the first one
glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
while (!closed)
{
glfwMakeContextCurrent(windows[0]);

View File

@ -89,6 +89,8 @@ int main(void)
for (i = 0; i < count; i++)
{
glfwWindowHint(GLFW_POSITION_X, 200 + 250 * i);
glfwWindowHint(GLFW_POSITION_Y, 200);
threads[i].window = glfwCreateWindow(200, 200,
GLFW_WINDOWED,
threads[i].title,
@ -100,8 +102,6 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);
if (thrd_create(&threads[i].id, thread_main, threads + i) !=
thrd_success)
{

View File

@ -55,6 +55,8 @@ int main(void)
for (i = 0; i < 4; i++)
{
glfwWindowHint(GLFW_POSITION_X, 100 + (i & 1) * 300);
glfwWindowHint(GLFW_POSITION_Y, 100 + (i >> 1) * 300);
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
if (!windows[i])
{
@ -70,8 +72,6 @@ int main(void)
(GLclampf) (i >> 1),
i ? 0.f : 1.f,
0.f);
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
}
while (running)