1 //========================================================================
2 // GLFW 3.4 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
6 // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would
19 // be appreciated but is not required.
21 // 2. Altered source versions must be plainly marked as such, and must not
22 // be misrepresented as being the original software.
24 // 3. This notice may not be removed or altered from any source
27 //========================================================================
28 // Please use C89 style variable declarations in this file because VS 2010
29 //========================================================================
39 //////////////////////////////////////////////////////////////////////////
40 ////// GLFW event API //////
41 //////////////////////////////////////////////////////////////////////////
43 // Notifies shared code that a window has lost or received input focus
45 void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused)
47 if (window->callbacks.focus)
48 window->callbacks.focus((GLFWwindow*) window, focused);
54 for (key = 0; key <= GLFW_KEY_LAST; key++)
56 if (window->keys[key] == GLFW_PRESS)
58 const int scancode = _glfwPlatformGetKeyScancode(key);
59 _glfwInputKey(window, key, scancode, GLFW_RELEASE, 0);
63 for (button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++)
65 if (window->mouseButtons[button] == GLFW_PRESS)
66 _glfwInputMouseClick(window, button, GLFW_RELEASE, 0);
71 // Notifies shared code that a window has moved
72 // The position is specified in content area relative screen coordinates
74 void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
76 if (window->callbacks.pos)
77 window->callbacks.pos((GLFWwindow*) window, x, y);
80 // Notifies shared code that a window has been resized
81 // The size is specified in screen coordinates
83 void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
85 if (window->callbacks.size)
86 window->callbacks.size((GLFWwindow*) window, width, height);
89 // Notifies shared code that a window has been iconified or restored
91 void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified)
93 if (window->callbacks.iconify)
94 window->callbacks.iconify((GLFWwindow*) window, iconified);
97 // Notifies shared code that a window has been maximized or restored
99 void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized)
101 if (window->callbacks.maximize)
102 window->callbacks.maximize((GLFWwindow*) window, maximized);
105 // Notifies shared code that a window framebuffer has been resized
106 // The size is specified in pixels
108 void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
110 if (window->callbacks.fbsize)
111 window->callbacks.fbsize((GLFWwindow*) window, width, height);
114 // Notifies shared code that a window content scale has changed
115 // The scale is specified as the ratio between the current and default DPI
117 void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale)
119 if (window->callbacks.scale)
120 window->callbacks.scale((GLFWwindow*) window, xscale, yscale);
123 // Notifies shared code that the window contents needs updating
125 void _glfwInputWindowDamage(_GLFWwindow* window)
127 if (window->callbacks.refresh)
128 window->callbacks.refresh((GLFWwindow*) window);
131 // Notifies shared code that the user wishes to close a window
133 void _glfwInputWindowCloseRequest(_GLFWwindow* window)
135 window->shouldClose = GLFW_TRUE;
137 if (window->callbacks.close)
138 window->callbacks.close((GLFWwindow*) window);
141 // Notifies shared code that a window has changed its desired monitor
143 void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor)
145 window->monitor = monitor;
148 //////////////////////////////////////////////////////////////////////////
149 ////// GLFW public API //////
150 //////////////////////////////////////////////////////////////////////////
152 GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
154 GLFWmonitor* monitor,
157 _GLFWfbconfig fbconfig;
158 _GLFWctxconfig ctxconfig;
159 _GLFWwndconfig wndconfig;
162 assert(title != NULL);
166 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
168 if (width <= 0 || height <= 0)
170 _glfwInputError(GLFW_INVALID_VALUE,
171 "Invalid window size %ix%i",
177 fbconfig = _glfw.hints.framebuffer;
178 ctxconfig = _glfw.hints.context;
179 wndconfig = _glfw.hints.window;
181 wndconfig.width = width;
182 wndconfig.height = height;
183 wndconfig.title = title;
184 ctxconfig.share = (_GLFWwindow*) share;
186 if (!_glfwIsValidContextConfig(&ctxconfig))
189 window = calloc(1, sizeof(_GLFWwindow));
190 window->next = _glfw.windowListHead;
191 _glfw.windowListHead = window;
193 window->videoMode.width = width;
194 window->videoMode.height = height;
195 window->videoMode.redBits = fbconfig.redBits;
196 window->videoMode.greenBits = fbconfig.greenBits;
197 window->videoMode.blueBits = fbconfig.blueBits;
198 window->videoMode.refreshRate = _glfw.hints.refreshRate;
200 window->monitor = (_GLFWmonitor*) monitor;
201 window->resizable = wndconfig.resizable;
202 window->decorated = wndconfig.decorated;
203 window->autoIconify = wndconfig.autoIconify;
204 window->floating = wndconfig.floating;
205 window->focusOnShow = wndconfig.focusOnShow;
206 window->mousePassthrough = wndconfig.mousePassthrough;
207 window->cursorMode = GLFW_CURSOR_NORMAL;
209 window->minwidth = GLFW_DONT_CARE;
210 window->minheight = GLFW_DONT_CARE;
211 window->maxwidth = GLFW_DONT_CARE;
212 window->maxheight = GLFW_DONT_CARE;
213 window->numer = GLFW_DONT_CARE;
214 window->denom = GLFW_DONT_CARE;
216 // Open the actual window and create its context
217 if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig))
219 glfwDestroyWindow((GLFWwindow*) window);
223 if (ctxconfig.client != GLFW_NO_API)
225 if (!_glfwRefreshContextAttribs(window, &ctxconfig))
227 glfwDestroyWindow((GLFWwindow*) window);
232 if (wndconfig.mousePassthrough)
233 _glfwPlatformSetWindowMousePassthrough(window, GLFW_TRUE);
237 if (wndconfig.centerCursor)
238 _glfwCenterCursorInContentArea(window);
242 if (wndconfig.visible)
244 _glfwPlatformShowWindow(window);
245 if (wndconfig.focused)
246 _glfwPlatformFocusWindow(window);
250 return (GLFWwindow*) window;
253 void glfwDefaultWindowHints(void)
255 _GLFW_REQUIRE_INIT();
257 // The default is OpenGL with minimum version 1.0
258 memset(&_glfw.hints.context, 0, sizeof(_glfw.hints.context));
259 _glfw.hints.context.client = GLFW_OPENGL_API;
260 _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API;
261 _glfw.hints.context.major = 1;
262 _glfw.hints.context.minor = 0;
264 // The default is a focused, visible, resizable window with decorations
265 memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window));
266 _glfw.hints.window.resizable = GLFW_TRUE;
267 _glfw.hints.window.visible = GLFW_TRUE;
268 _glfw.hints.window.decorated = GLFW_TRUE;
269 _glfw.hints.window.focused = GLFW_TRUE;
270 _glfw.hints.window.autoIconify = GLFW_TRUE;
271 _glfw.hints.window.centerCursor = GLFW_TRUE;
272 _glfw.hints.window.focusOnShow = GLFW_TRUE;
274 // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
276 memset(&_glfw.hints.framebuffer, 0, sizeof(_glfw.hints.framebuffer));
277 _glfw.hints.framebuffer.redBits = 8;
278 _glfw.hints.framebuffer.greenBits = 8;
279 _glfw.hints.framebuffer.blueBits = 8;
280 _glfw.hints.framebuffer.alphaBits = 8;
281 _glfw.hints.framebuffer.depthBits = 24;
282 _glfw.hints.framebuffer.stencilBits = 8;
283 _glfw.hints.framebuffer.doublebuffer = GLFW_TRUE;
285 // The default is to select the highest available refresh rate
286 _glfw.hints.refreshRate = GLFW_DONT_CARE;
288 // The default is to use full Retina resolution framebuffers
289 _glfw.hints.window.ns.retina = GLFW_TRUE;
292 GLFWAPI void glfwWindowHint(int hint, int value)
294 _GLFW_REQUIRE_INIT();
299 _glfw.hints.framebuffer.redBits = value;
301 case GLFW_GREEN_BITS:
302 _glfw.hints.framebuffer.greenBits = value;
305 _glfw.hints.framebuffer.blueBits = value;
307 case GLFW_ALPHA_BITS:
308 _glfw.hints.framebuffer.alphaBits = value;
310 case GLFW_DEPTH_BITS:
311 _glfw.hints.framebuffer.depthBits = value;
313 case GLFW_STENCIL_BITS:
314 _glfw.hints.framebuffer.stencilBits = value;
316 case GLFW_ACCUM_RED_BITS:
317 _glfw.hints.framebuffer.accumRedBits = value;
319 case GLFW_ACCUM_GREEN_BITS:
320 _glfw.hints.framebuffer.accumGreenBits = value;
322 case GLFW_ACCUM_BLUE_BITS:
323 _glfw.hints.framebuffer.accumBlueBits = value;
325 case GLFW_ACCUM_ALPHA_BITS:
326 _glfw.hints.framebuffer.accumAlphaBits = value;
328 case GLFW_AUX_BUFFERS:
329 _glfw.hints.framebuffer.auxBuffers = value;
332 _glfw.hints.framebuffer.stereo = value ? GLFW_TRUE : GLFW_FALSE;
334 case GLFW_DOUBLEBUFFER:
335 _glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE;
337 case GLFW_TRANSPARENT_FRAMEBUFFER:
338 _glfw.hints.framebuffer.transparent = value ? GLFW_TRUE : GLFW_FALSE;
341 _glfw.hints.framebuffer.samples = value;
343 case GLFW_SRGB_CAPABLE:
344 _glfw.hints.framebuffer.sRGB = value ? GLFW_TRUE : GLFW_FALSE;
347 _glfw.hints.window.resizable = value ? GLFW_TRUE : GLFW_FALSE;
350 _glfw.hints.window.decorated = value ? GLFW_TRUE : GLFW_FALSE;
353 _glfw.hints.window.focused = value ? GLFW_TRUE : GLFW_FALSE;
355 case GLFW_AUTO_ICONIFY:
356 _glfw.hints.window.autoIconify = value ? GLFW_TRUE : GLFW_FALSE;
359 _glfw.hints.window.floating = value ? GLFW_TRUE : GLFW_FALSE;
362 _glfw.hints.window.maximized = value ? GLFW_TRUE : GLFW_FALSE;
365 _glfw.hints.window.visible = value ? GLFW_TRUE : GLFW_FALSE;
367 case GLFW_COCOA_RETINA_FRAMEBUFFER:
368 _glfw.hints.window.ns.retina = value ? GLFW_TRUE : GLFW_FALSE;
370 case GLFW_WIN32_KEYBOARD_MENU:
371 _glfw.hints.window.win32.keymenu = value ? GLFW_TRUE : GLFW_FALSE;
373 case GLFW_COCOA_GRAPHICS_SWITCHING:
374 _glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE;
376 case GLFW_SCALE_TO_MONITOR:
377 _glfw.hints.window.scaleToMonitor = value ? GLFW_TRUE : GLFW_FALSE;
379 case GLFW_CENTER_CURSOR:
380 _glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
382 case GLFW_FOCUS_ON_SHOW:
383 _glfw.hints.window.focusOnShow = value ? GLFW_TRUE : GLFW_FALSE;
385 case GLFW_MOUSE_PASSTHROUGH:
386 _glfw.hints.window.mousePassthrough = value ? GLFW_TRUE : GLFW_FALSE;
388 case GLFW_CLIENT_API:
389 _glfw.hints.context.client = value;
391 case GLFW_CONTEXT_CREATION_API:
392 _glfw.hints.context.source = value;
394 case GLFW_CONTEXT_VERSION_MAJOR:
395 _glfw.hints.context.major = value;
397 case GLFW_CONTEXT_VERSION_MINOR:
398 _glfw.hints.context.minor = value;
400 case GLFW_CONTEXT_ROBUSTNESS:
401 _glfw.hints.context.robustness = value;
403 case GLFW_OPENGL_FORWARD_COMPAT:
404 _glfw.hints.context.forward = value ? GLFW_TRUE : GLFW_FALSE;
406 case GLFW_CONTEXT_DEBUG:
407 _glfw.hints.context.debug = value ? GLFW_TRUE : GLFW_FALSE;
409 case GLFW_CONTEXT_NO_ERROR:
410 _glfw.hints.context.noerror = value ? GLFW_TRUE : GLFW_FALSE;
412 case GLFW_OPENGL_PROFILE:
413 _glfw.hints.context.profile = value;
415 case GLFW_CONTEXT_RELEASE_BEHAVIOR:
416 _glfw.hints.context.release = value;
418 case GLFW_REFRESH_RATE:
419 _glfw.hints.refreshRate = value;
423 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint);
426 GLFWAPI void glfwWindowHintString(int hint, const char* value)
428 assert(value != NULL);
430 _GLFW_REQUIRE_INIT();
434 case GLFW_COCOA_FRAME_NAME:
435 strncpy(_glfw.hints.window.ns.frameName, value,
436 sizeof(_glfw.hints.window.ns.frameName) - 1);
438 case GLFW_X11_CLASS_NAME:
439 strncpy(_glfw.hints.window.x11.className, value,
440 sizeof(_glfw.hints.window.x11.className) - 1);
442 case GLFW_X11_INSTANCE_NAME:
443 strncpy(_glfw.hints.window.x11.instanceName, value,
444 sizeof(_glfw.hints.window.x11.instanceName) - 1);
448 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint);
451 GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
453 _GLFWwindow* window = (_GLFWwindow*) handle;
455 _GLFW_REQUIRE_INIT();
457 // Allow closing of NULL (to match the behavior of free)
461 // Clear all callbacks to avoid exposing a half torn-down window object
462 memset(&window->callbacks, 0, sizeof(window->callbacks));
464 // The window's context must not be current on another thread when the
465 // window is destroyed
466 if (window == _glfwPlatformGetTls(&_glfw.contextSlot))
467 glfwMakeContextCurrent(NULL);
469 _glfwPlatformDestroyWindow(window);
471 // Unlink window from global linked list
473 _GLFWwindow** prev = &_glfw.windowListHead;
475 while (*prev != window)
476 prev = &((*prev)->next);
478 *prev = window->next;
484 GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle)
486 _GLFWwindow* window = (_GLFWwindow*) handle;
487 assert(window != NULL);
489 _GLFW_REQUIRE_INIT_OR_RETURN(0);
490 return window->shouldClose;
493 GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
495 _GLFWwindow* window = (_GLFWwindow*) handle;
496 assert(window != NULL);
498 _GLFW_REQUIRE_INIT();
499 window->shouldClose = value;
502 GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
504 _GLFWwindow* window = (_GLFWwindow*) handle;
505 assert(window != NULL);
506 assert(title != NULL);
508 _GLFW_REQUIRE_INIT();
509 _glfwPlatformSetWindowTitle(window, title);
512 GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle,
513 int count, const GLFWimage* images)
515 _GLFWwindow* window = (_GLFWwindow*) handle;
516 assert(window != NULL);
518 assert(count == 0 || images != NULL);
520 _GLFW_REQUIRE_INIT();
521 _glfwPlatformSetWindowIcon(window, count, images);
524 GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
526 _GLFWwindow* window = (_GLFWwindow*) handle;
527 assert(window != NULL);
534 _GLFW_REQUIRE_INIT();
535 _glfwPlatformGetWindowPos(window, xpos, ypos);
538 GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
540 _GLFWwindow* window = (_GLFWwindow*) handle;
541 assert(window != NULL);
543 _GLFW_REQUIRE_INIT();
548 _glfwPlatformSetWindowPos(window, xpos, ypos);
551 GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
553 _GLFWwindow* window = (_GLFWwindow*) handle;
554 assert(window != NULL);
561 _GLFW_REQUIRE_INIT();
562 _glfwPlatformGetWindowSize(window, width, height);
565 GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
567 _GLFWwindow* window = (_GLFWwindow*) handle;
568 assert(window != NULL);
572 _GLFW_REQUIRE_INIT();
574 window->videoMode.width = width;
575 window->videoMode.height = height;
577 _glfwPlatformSetWindowSize(window, width, height);
580 GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle,
581 int minwidth, int minheight,
582 int maxwidth, int maxheight)
584 _GLFWwindow* window = (_GLFWwindow*) handle;
585 assert(window != NULL);
587 _GLFW_REQUIRE_INIT();
589 if (minwidth != GLFW_DONT_CARE && minheight != GLFW_DONT_CARE)
591 if (minwidth < 0 || minheight < 0)
593 _glfwInputError(GLFW_INVALID_VALUE,
594 "Invalid window minimum size %ix%i",
595 minwidth, minheight);
600 if (maxwidth != GLFW_DONT_CARE && maxheight != GLFW_DONT_CARE)
602 if (maxwidth < 0 || maxheight < 0 ||
603 maxwidth < minwidth || maxheight < minheight)
605 _glfwInputError(GLFW_INVALID_VALUE,
606 "Invalid window maximum size %ix%i",
607 maxwidth, maxheight);
612 window->minwidth = minwidth;
613 window->minheight = minheight;
614 window->maxwidth = maxwidth;
615 window->maxheight = maxheight;
617 if (window->monitor || !window->resizable)
620 _glfwPlatformSetWindowSizeLimits(window,
622 maxwidth, maxheight);
625 GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom)
627 _GLFWwindow* window = (_GLFWwindow*) handle;
628 assert(window != NULL);
632 _GLFW_REQUIRE_INIT();
634 if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE)
636 if (numer <= 0 || denom <= 0)
638 _glfwInputError(GLFW_INVALID_VALUE,
639 "Invalid window aspect ratio %i:%i",
645 window->numer = numer;
646 window->denom = denom;
648 if (window->monitor || !window->resizable)
651 _glfwPlatformSetWindowAspectRatio(window, numer, denom);
654 GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height)
656 _GLFWwindow* window = (_GLFWwindow*) handle;
657 assert(window != NULL);
664 _GLFW_REQUIRE_INIT();
665 _glfwPlatformGetFramebufferSize(window, width, height);
668 GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
670 int* right, int* bottom)
672 _GLFWwindow* window = (_GLFWwindow*) handle;
673 assert(window != NULL);
684 _GLFW_REQUIRE_INIT();
685 _glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
688 GLFWAPI void glfwGetWindowContentScale(GLFWwindow* handle,
689 float* xscale, float* yscale)
691 _GLFWwindow* window = (_GLFWwindow*) handle;
692 assert(window != NULL);
699 _GLFW_REQUIRE_INIT();
700 _glfwPlatformGetWindowContentScale(window, xscale, yscale);
703 GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle)
705 _GLFWwindow* window = (_GLFWwindow*) handle;
706 assert(window != NULL);
708 _GLFW_REQUIRE_INIT_OR_RETURN(1.f);
709 return _glfwPlatformGetWindowOpacity(window);
712 GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity)
714 _GLFWwindow* window = (_GLFWwindow*) handle;
715 assert(window != NULL);
716 assert(opacity == opacity);
717 assert(opacity >= 0.f);
718 assert(opacity <= 1.f);
720 _GLFW_REQUIRE_INIT();
722 if (opacity != opacity || opacity < 0.f || opacity > 1.f)
724 _glfwInputError(GLFW_INVALID_VALUE, "Invalid window opacity %f", opacity);
728 _glfwPlatformSetWindowOpacity(window, opacity);
731 GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
733 _GLFWwindow* window = (_GLFWwindow*) handle;
734 assert(window != NULL);
736 _GLFW_REQUIRE_INIT();
737 _glfwPlatformIconifyWindow(window);
740 GLFWAPI void glfwRestoreWindow(GLFWwindow* handle)
742 _GLFWwindow* window = (_GLFWwindow*) handle;
743 assert(window != NULL);
745 _GLFW_REQUIRE_INIT();
746 _glfwPlatformRestoreWindow(window);
749 GLFWAPI void glfwMaximizeWindow(GLFWwindow* handle)
751 _GLFWwindow* window = (_GLFWwindow*) handle;
752 assert(window != NULL);
754 _GLFW_REQUIRE_INIT();
759 _glfwPlatformMaximizeWindow(window);
762 GLFWAPI void glfwShowWindow(GLFWwindow* handle)
764 _GLFWwindow* window = (_GLFWwindow*) handle;
765 assert(window != NULL);
767 _GLFW_REQUIRE_INIT();
772 _glfwPlatformShowWindow(window);
774 if (window->focusOnShow)
775 _glfwPlatformFocusWindow(window);
778 GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
780 _GLFWwindow* window = (_GLFWwindow*) handle;
781 assert(window != NULL);
783 _GLFW_REQUIRE_INIT();
785 _glfwPlatformRequestWindowAttention(window);
788 GLFWAPI void glfwHideWindow(GLFWwindow* handle)
790 _GLFWwindow* window = (_GLFWwindow*) handle;
791 assert(window != NULL);
793 _GLFW_REQUIRE_INIT();
798 _glfwPlatformHideWindow(window);
801 GLFWAPI void glfwFocusWindow(GLFWwindow* handle)
803 _GLFWwindow* window = (_GLFWwindow*) handle;
804 assert(window != NULL);
806 _GLFW_REQUIRE_INIT();
808 _glfwPlatformFocusWindow(window);
811 GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
813 _GLFWwindow* window = (_GLFWwindow*) handle;
814 assert(window != NULL);
816 _GLFW_REQUIRE_INIT_OR_RETURN(0);
821 return _glfwPlatformWindowFocused(window);
823 return _glfwPlatformWindowIconified(window);
825 return _glfwPlatformWindowVisible(window);
827 return _glfwPlatformWindowMaximized(window);
829 return _glfwPlatformWindowHovered(window);
830 case GLFW_FOCUS_ON_SHOW:
831 return window->focusOnShow;
832 case GLFW_MOUSE_PASSTHROUGH:
833 return window->mousePassthrough;
834 case GLFW_TRANSPARENT_FRAMEBUFFER:
835 return _glfwPlatformFramebufferTransparent(window);
837 return window->resizable;
839 return window->decorated;
841 return window->floating;
842 case GLFW_AUTO_ICONIFY:
843 return window->autoIconify;
844 case GLFW_CLIENT_API:
845 return window->context.client;
846 case GLFW_CONTEXT_CREATION_API:
847 return window->context.source;
848 case GLFW_CONTEXT_VERSION_MAJOR:
849 return window->context.major;
850 case GLFW_CONTEXT_VERSION_MINOR:
851 return window->context.minor;
852 case GLFW_CONTEXT_REVISION:
853 return window->context.revision;
854 case GLFW_CONTEXT_ROBUSTNESS:
855 return window->context.robustness;
856 case GLFW_OPENGL_FORWARD_COMPAT:
857 return window->context.forward;
858 case GLFW_CONTEXT_DEBUG:
859 return window->context.debug;
860 case GLFW_OPENGL_PROFILE:
861 return window->context.profile;
862 case GLFW_CONTEXT_RELEASE_BEHAVIOR:
863 return window->context.release;
864 case GLFW_CONTEXT_NO_ERROR:
865 return window->context.noerror;
868 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib);
872 GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value)
874 _GLFWwindow* window = (_GLFWwindow*) handle;
875 assert(window != NULL);
877 _GLFW_REQUIRE_INIT();
879 value = value ? GLFW_TRUE : GLFW_FALSE;
881 if (attrib == GLFW_AUTO_ICONIFY)
882 window->autoIconify = value;
883 else if (attrib == GLFW_RESIZABLE)
885 if (window->resizable == value)
888 window->resizable = value;
889 if (!window->monitor)
890 _glfwPlatformSetWindowResizable(window, value);
892 else if (attrib == GLFW_DECORATED)
894 if (window->decorated == value)
897 window->decorated = value;
898 if (!window->monitor)
899 _glfwPlatformSetWindowDecorated(window, value);
901 else if (attrib == GLFW_FLOATING)
903 if (window->floating == value)
906 window->floating = value;
907 if (!window->monitor)
908 _glfwPlatformSetWindowFloating(window, value);
910 else if (attrib == GLFW_FOCUS_ON_SHOW)
911 window->focusOnShow = value;
912 else if (attrib == GLFW_MOUSE_PASSTHROUGH)
914 if (window->mousePassthrough == value)
917 window->mousePassthrough = value;
918 _glfwPlatformSetWindowMousePassthrough(window, value);
921 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib);
924 GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle)
926 _GLFWwindow* window = (_GLFWwindow*) handle;
927 assert(window != NULL);
929 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
930 return (GLFWmonitor*) window->monitor;
933 GLFWAPI void glfwSetWindowMonitor(GLFWwindow* wh,
936 int width, int height,
939 _GLFWwindow* window = (_GLFWwindow*) wh;
940 _GLFWmonitor* monitor = (_GLFWmonitor*) mh;
941 assert(window != NULL);
945 _GLFW_REQUIRE_INIT();
947 if (width <= 0 || height <= 0)
949 _glfwInputError(GLFW_INVALID_VALUE,
950 "Invalid window size %ix%i",
955 if (refreshRate < 0 && refreshRate != GLFW_DONT_CARE)
957 _glfwInputError(GLFW_INVALID_VALUE,
958 "Invalid refresh rate %i",
963 window->videoMode.width = width;
964 window->videoMode.height = height;
965 window->videoMode.refreshRate = refreshRate;
967 _glfwPlatformSetWindowMonitor(window, monitor,
968 xpos, ypos, width, height,
972 GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
974 _GLFWwindow* window = (_GLFWwindow*) handle;
975 assert(window != NULL);
977 _GLFW_REQUIRE_INIT();
978 window->userPointer = pointer;
981 GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
983 _GLFWwindow* window = (_GLFWwindow*) handle;
984 assert(window != NULL);
986 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
987 return window->userPointer;
990 GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
991 GLFWwindowposfun cbfun)
993 _GLFWwindow* window = (_GLFWwindow*) handle;
994 assert(window != NULL);
996 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
997 _GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
1001 GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
1002 GLFWwindowsizefun cbfun)
1004 _GLFWwindow* window = (_GLFWwindow*) handle;
1005 assert(window != NULL);
1007 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1008 _GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
1012 GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
1013 GLFWwindowclosefun cbfun)
1015 _GLFWwindow* window = (_GLFWwindow*) handle;
1016 assert(window != NULL);
1018 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1019 _GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
1023 GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
1024 GLFWwindowrefreshfun cbfun)
1026 _GLFWwindow* window = (_GLFWwindow*) handle;
1027 assert(window != NULL);
1029 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1030 _GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
1034 GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
1035 GLFWwindowfocusfun cbfun)
1037 _GLFWwindow* window = (_GLFWwindow*) handle;
1038 assert(window != NULL);
1040 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1041 _GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
1045 GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
1046 GLFWwindowiconifyfun cbfun)
1048 _GLFWwindow* window = (_GLFWwindow*) handle;
1049 assert(window != NULL);
1051 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1052 _GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
1056 GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* handle,
1057 GLFWwindowmaximizefun cbfun)
1059 _GLFWwindow* window = (_GLFWwindow*) handle;
1060 assert(window != NULL);
1062 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1063 _GLFW_SWAP_POINTERS(window->callbacks.maximize, cbfun);
1067 GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
1068 GLFWframebuffersizefun cbfun)
1070 _GLFWwindow* window = (_GLFWwindow*) handle;
1071 assert(window != NULL);
1073 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1074 _GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
1078 GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle,
1079 GLFWwindowcontentscalefun cbfun)
1081 _GLFWwindow* window = (_GLFWwindow*) handle;
1082 assert(window != NULL);
1084 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
1085 _GLFW_SWAP_POINTERS(window->callbacks.scale, cbfun);
1089 GLFWAPI void glfwPollEvents(void)
1091 _GLFW_REQUIRE_INIT();
1092 _glfwPlatformPollEvents();
1095 GLFWAPI void glfwWaitEvents(void)
1097 _GLFW_REQUIRE_INIT();
1098 _glfwPlatformWaitEvents();
1101 GLFWAPI void glfwWaitEventsTimeout(double timeout)
1103 _GLFW_REQUIRE_INIT();
1104 assert(timeout == timeout);
1105 assert(timeout >= 0.0);
1106 assert(timeout <= DBL_MAX);
1108 if (timeout != timeout || timeout < 0.0 || timeout > DBL_MAX)
1110 _glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", timeout);
1114 _glfwPlatformWaitEventsTimeout(timeout);
1117 GLFWAPI void glfwPostEmptyEvent(void)
1119 _GLFW_REQUIRE_INIT();
1120 _glfwPlatformPostEmptyEvent();