GLFW: size, position & monitorsGLFW 3.1

glfwGetWindowFrameSize

Reads how thick the window's frame is on each side: the title bar on top and the borders.

Signature

void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom);

How it works

The size you give glfwCreateWindow is the content only. The system adds a title bar and borders around it. To center the WHOLE window on the screen, or to fit it inside the work area, you need those extra sizes.

The four numbers are the distances from each edge of the content area to the matching edge of the frame, in screen coordinates. top is usually the title bar height.

Parameters

windowGLFWwindow*

The window to measure.

leftint*

Width of the left border, or NULL.

topint*

Height of the top part (title bar + border), or NULL.

rightint*

Width of the right border, or NULL.

bottomint*

Height of the bottom border, or NULL.

Tips & pitfalls

  • The frame may only be known once the window exists, so measure after glfwCreateWindow (a hidden window works).

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GLFW_NOT_INITIALIZED
Called before glfwInit or after glfwTerminate.
GLFW_PLATFORM_ERROR
The operating system or window system reported a failure; the description says which.

Example

example.cpp
1int l, t, r, b;
2glfwGetWindowFrameSize(window, &l, &t, &r, &b);
3int outerW = w + l + r;   // whole window, frame included
4int outerH = h + t + b;
Official GLFW documentation