1 //========================================================================
2 // GLFW 3.1 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
6 // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
7 //
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.
11 //
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:
15 //
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.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not
22 //    be misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 //    distribution.
26 //
27 //========================================================================
28 
29 #include "internal.h"
30 
31 #include <string.h>
32 #include <stdlib.h>
33 
34 
35 //////////////////////////////////////////////////////////////////////////
36 //////                         GLFW event API                       //////
37 //////////////////////////////////////////////////////////////////////////
38 
_glfwInputWindowFocus(_GLFWwindow * window,GLboolean focused)39 void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
40 {
41     if (focused)
42     {
43         _glfw.cursorWindow = window;
44 
45         if (window->callbacks.focus)
46             window->callbacks.focus((GLFWwindow*) window, focused);
47     }
48     else
49     {
50         int i;
51 
52         _glfw.cursorWindow = NULL;
53 
54         if (window->callbacks.focus)
55             window->callbacks.focus((GLFWwindow*) window, focused);
56 
57         // Release all pressed keyboard keys
58         for (i = 0;  i <= GLFW_KEY_LAST;  i++)
59         {
60             if (window->keys[i] == GLFW_PRESS)
61                 _glfwInputKey(window, i, 0, GLFW_RELEASE, 0);
62         }
63 
64         // Release all pressed mouse buttons
65         for (i = 0;  i <= GLFW_MOUSE_BUTTON_LAST;  i++)
66         {
67             if (window->mouseButtons[i] == GLFW_PRESS)
68                 _glfwInputMouseClick(window, i, GLFW_RELEASE, 0);
69         }
70     }
71 }
72 
_glfwInputWindowPos(_GLFWwindow * window,int x,int y)73 void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
74 {
75     if (window->callbacks.pos)
76         window->callbacks.pos((GLFWwindow*) window, x, y);
77 }
78 
_glfwInputWindowSize(_GLFWwindow * window,int width,int height)79 void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
80 {
81     if (window->callbacks.size)
82         window->callbacks.size((GLFWwindow*) window, width, height);
83 }
84 
_glfwInputWindowIconify(_GLFWwindow * window,int iconified)85 void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
86 {
87     if (window->callbacks.iconify)
88         window->callbacks.iconify((GLFWwindow*) window, iconified);
89 }
90 
_glfwInputFramebufferSize(_GLFWwindow * window,int width,int height)91 void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
92 {
93     if (window->callbacks.fbsize)
94         window->callbacks.fbsize((GLFWwindow*) window, width, height);
95 }
96 
_glfwInputWindowDamage(_GLFWwindow * window)97 void _glfwInputWindowDamage(_GLFWwindow* window)
98 {
99     if (window->callbacks.refresh)
100         window->callbacks.refresh((GLFWwindow*) window);
101 }
102 
_glfwInputWindowCloseRequest(_GLFWwindow * window)103 void _glfwInputWindowCloseRequest(_GLFWwindow* window)
104 {
105     window->closed = GL_TRUE;
106 
107     if (window->callbacks.close)
108         window->callbacks.close((GLFWwindow*) window);
109 }
110 
111 
112 //////////////////////////////////////////////////////////////////////////
113 //////                        GLFW public API                       //////
114 //////////////////////////////////////////////////////////////////////////
115 
glfwCreateWindow(int width,int height,const char * title,GLFWmonitor * monitor,GLFWwindow * share)116 GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
117                                      const char* title,
118                                      GLFWmonitor* monitor,
119                                      GLFWwindow* share)
120 {
121     _GLFWfbconfig fbconfig;
122     _GLFWctxconfig ctxconfig;
123     _GLFWwndconfig wndconfig;
124     _GLFWwindow* window;
125     _GLFWwindow* previous;
126 
127     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
128 
129     if (width <= 0 || height <= 0)
130     {
131         _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size");
132         return NULL;
133     }
134 
135     fbconfig  = _glfw.hints.framebuffer;
136     ctxconfig = _glfw.hints.context;
137     wndconfig = _glfw.hints.window;
138 
139     wndconfig.width   = width;
140     wndconfig.height  = height;
141     wndconfig.title   = title;
142     wndconfig.monitor = (_GLFWmonitor*) monitor;
143     ctxconfig.share   = (_GLFWwindow*) share;
144 
145     if (wndconfig.monitor)
146     {
147         wndconfig.resizable = GL_TRUE;
148         wndconfig.visible   = GL_TRUE;
149         wndconfig.focused   = GL_TRUE;
150     }
151 
152     // Check the OpenGL bits of the window config
153     if (!_glfwIsValidContextConfig(&ctxconfig))
154         return NULL;
155 
156     window = calloc(1, sizeof(_GLFWwindow));
157     window->next = _glfw.windowListHead;
158     _glfw.windowListHead = window;
159 
160     window->videoMode.width       = width;
161     window->videoMode.height      = height;
162     window->videoMode.redBits     = fbconfig.redBits;
163     window->videoMode.greenBits   = fbconfig.greenBits;
164     window->videoMode.blueBits    = fbconfig.blueBits;
165     window->videoMode.refreshRate = _glfw.hints.refreshRate;
166 
167     window->monitor     = wndconfig.monitor;
168     window->resizable   = wndconfig.resizable;
169     window->decorated   = wndconfig.decorated;
170     window->autoIconify = wndconfig.autoIconify;
171     window->floating    = wndconfig.floating;
172     window->cursorMode  = GLFW_CURSOR_NORMAL;
173 
174     // Save the currently current context so it can be restored later
175     previous = _glfwPlatformGetCurrentContext();
176 
177     // Open the actual window and create its context
178     if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig))
179     {
180         glfwDestroyWindow((GLFWwindow*) window);
181         _glfwPlatformMakeContextCurrent(previous);
182         return NULL;
183     }
184 
185     _glfwPlatformMakeContextCurrent(window);
186 
187     // Retrieve the actual (as opposed to requested) context attributes
188     if (!_glfwRefreshContextAttribs(&ctxconfig))
189     {
190         glfwDestroyWindow((GLFWwindow*) window);
191         _glfwPlatformMakeContextCurrent(previous);
192         return NULL;
193     }
194 
195     // Verify the context against the requested parameters
196     if (!_glfwIsValidContext(&ctxconfig))
197     {
198         glfwDestroyWindow((GLFWwindow*) window);
199         _glfwPlatformMakeContextCurrent(previous);
200         return NULL;
201     }
202 
203     // Clearing the front buffer to black to avoid garbage pixels left over
204     // from previous uses of our bit of VRAM
205     window->Clear(GL_COLOR_BUFFER_BIT);
206     _glfwPlatformSwapBuffers(window);
207 
208     // Restore the previously current context (or NULL)
209     _glfwPlatformMakeContextCurrent(previous);
210 
211     if (wndconfig.monitor)
212     {
213         int width, height;
214         _glfwPlatformGetWindowSize(window, &width, &height);
215 
216         window->cursorPosX = width / 2;
217         window->cursorPosY = height / 2;
218 
219         _glfwPlatformSetCursorPos(window, window->cursorPosX, window->cursorPosY);
220     }
221     else
222     {
223         if (wndconfig.visible)
224         {
225             if (wndconfig.focused)
226                 _glfwPlatformShowWindow(window);
227             else
228                 _glfwPlatformUnhideWindow(window);
229         }
230     }
231 
232     return (GLFWwindow*) window;
233 }
234 
glfwDefaultWindowHints(void)235 void glfwDefaultWindowHints(void)
236 {
237     _GLFW_REQUIRE_INIT();
238 
239     memset(&_glfw.hints, 0, sizeof(_glfw.hints));
240 
241     // The default is OpenGL with minimum version 1.0
242     _glfw.hints.context.api   = GLFW_OPENGL_API;
243     _glfw.hints.context.major = 1;
244     _glfw.hints.context.minor = 0;
245 
246     // The default is a focused, visible, resizable window with decorations
247     _glfw.hints.window.resizable   = GL_TRUE;
248     _glfw.hints.window.visible     = GL_TRUE;
249     _glfw.hints.window.decorated   = GL_TRUE;
250     _glfw.hints.window.focused     = GL_TRUE;
251     _glfw.hints.window.autoIconify = GL_TRUE;
252 
253     // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
254     // double buffered
255     _glfw.hints.framebuffer.redBits      = 8;
256     _glfw.hints.framebuffer.greenBits    = 8;
257     _glfw.hints.framebuffer.blueBits     = 8;
258     _glfw.hints.framebuffer.alphaBits    = 8;
259     _glfw.hints.framebuffer.depthBits    = 24;
260     _glfw.hints.framebuffer.stencilBits  = 8;
261     _glfw.hints.framebuffer.doublebuffer = GL_TRUE;
262 
263     // The default is to select the highest available refresh rate
264     _glfw.hints.refreshRate = GLFW_DONT_CARE;
265 }
266 
glfwWindowHint(int target,int hint)267 GLFWAPI void glfwWindowHint(int target, int hint)
268 {
269     _GLFW_REQUIRE_INIT();
270 
271     switch (target)
272     {
273         case GLFW_RED_BITS:
274             _glfw.hints.framebuffer.redBits = hint;
275             break;
276         case GLFW_GREEN_BITS:
277             _glfw.hints.framebuffer.greenBits = hint;
278             break;
279         case GLFW_BLUE_BITS:
280             _glfw.hints.framebuffer.blueBits = hint;
281             break;
282         case GLFW_ALPHA_BITS:
283             _glfw.hints.framebuffer.alphaBits = hint;
284             break;
285         case GLFW_DEPTH_BITS:
286             _glfw.hints.framebuffer.depthBits = hint;
287             break;
288         case GLFW_STENCIL_BITS:
289             _glfw.hints.framebuffer.stencilBits = hint;
290             break;
291         case GLFW_ACCUM_RED_BITS:
292             _glfw.hints.framebuffer.accumRedBits = hint;
293             break;
294         case GLFW_ACCUM_GREEN_BITS:
295             _glfw.hints.framebuffer.accumGreenBits = hint;
296             break;
297         case GLFW_ACCUM_BLUE_BITS:
298             _glfw.hints.framebuffer.accumBlueBits = hint;
299             break;
300         case GLFW_ACCUM_ALPHA_BITS:
301             _glfw.hints.framebuffer.accumAlphaBits = hint;
302             break;
303         case GLFW_AUX_BUFFERS:
304             _glfw.hints.framebuffer.auxBuffers = hint;
305             break;
306         case GLFW_STEREO:
307             _glfw.hints.framebuffer.stereo = hint ? GL_TRUE : GL_FALSE;
308             break;
309         case GLFW_DOUBLEBUFFER:
310             _glfw.hints.framebuffer.doublebuffer = hint ? GL_TRUE : GL_FALSE;
311             break;
312         case GLFW_SAMPLES:
313             _glfw.hints.framebuffer.samples = hint;
314             break;
315         case GLFW_SRGB_CAPABLE:
316             _glfw.hints.framebuffer.sRGB = hint ? GL_TRUE : GL_FALSE;
317             break;
318         case GLFW_RESIZABLE:
319             _glfw.hints.window.resizable = hint ? GL_TRUE : GL_FALSE;
320             break;
321         case GLFW_DECORATED:
322             _glfw.hints.window.decorated = hint ? GL_TRUE : GL_FALSE;
323             break;
324         case GLFW_FOCUSED:
325             _glfw.hints.window.focused = hint ? GL_TRUE : GL_FALSE;
326             break;
327         case GLFW_AUTO_ICONIFY:
328             _glfw.hints.window.autoIconify = hint ? GL_TRUE : GL_FALSE;
329             break;
330         case GLFW_FLOATING:
331             _glfw.hints.window.floating = hint ? GL_TRUE : GL_FALSE;
332             break;
333         case GLFW_VISIBLE:
334             _glfw.hints.window.visible = hint ? GL_TRUE : GL_FALSE;
335             break;
336         case GLFW_CLIENT_API:
337             _glfw.hints.context.api = hint;
338             break;
339         case GLFW_CONTEXT_VERSION_MAJOR:
340             _glfw.hints.context.major = hint;
341             break;
342         case GLFW_CONTEXT_VERSION_MINOR:
343             _glfw.hints.context.minor = hint;
344             break;
345         case GLFW_CONTEXT_ROBUSTNESS:
346             _glfw.hints.context.robustness = hint;
347             break;
348         case GLFW_OPENGL_FORWARD_COMPAT:
349             _glfw.hints.context.forward = hint ? GL_TRUE : GL_FALSE;
350             break;
351         case GLFW_OPENGL_DEBUG_CONTEXT:
352             _glfw.hints.context.debug = hint ? GL_TRUE : GL_FALSE;
353             break;
354         case GLFW_OPENGL_PROFILE:
355             _glfw.hints.context.profile = hint;
356             break;
357         case GLFW_CONTEXT_RELEASE_BEHAVIOR:
358             _glfw.hints.context.release = hint;
359             break;
360         case GLFW_REFRESH_RATE:
361             _glfw.hints.refreshRate = hint;
362             break;
363         default:
364             _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint");
365             break;
366     }
367 }
368 
glfwDestroyWindow(GLFWwindow * handle)369 GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
370 {
371     _GLFWwindow* window = (_GLFWwindow*) handle;
372 
373     _GLFW_REQUIRE_INIT();
374 
375     // Allow closing of NULL (to match the behavior of free)
376     if (window == NULL)
377         return;
378 
379     // Clear all callbacks to avoid exposing a half torn-down window object
380     memset(&window->callbacks, 0, sizeof(window->callbacks));
381 
382     // The window's context must not be current on another thread when the
383     // window is destroyed
384     if (window == _glfwPlatformGetCurrentContext())
385         _glfwPlatformMakeContextCurrent(NULL);
386 
387     // Clear the focused window pointer if this is the focused window
388     if (_glfw.cursorWindow == window)
389         _glfw.cursorWindow = NULL;
390 
391     _glfwPlatformDestroyWindow(window);
392 
393     // Unlink window from global linked list
394     {
395         _GLFWwindow** prev = &_glfw.windowListHead;
396 
397         while (*prev != window)
398             prev = &((*prev)->next);
399 
400         *prev = window->next;
401     }
402 
403     free(window);
404 }
405 
glfwWindowShouldClose(GLFWwindow * handle)406 GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle)
407 {
408     _GLFWwindow* window = (_GLFWwindow*) handle;
409     _GLFW_REQUIRE_INIT_OR_RETURN(0);
410     return window->closed;
411 }
412 
glfwSetWindowShouldClose(GLFWwindow * handle,int value)413 GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
414 {
415     _GLFWwindow* window = (_GLFWwindow*) handle;
416     _GLFW_REQUIRE_INIT();
417     window->closed = value;
418 }
419 
glfwSetWindowTitle(GLFWwindow * handle,const char * title)420 GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
421 {
422     _GLFWwindow* window = (_GLFWwindow*) handle;
423     _GLFW_REQUIRE_INIT();
424     _glfwPlatformSetWindowTitle(window, title);
425 }
426 
glfwGetWindowPos(GLFWwindow * handle,int * xpos,int * ypos)427 GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
428 {
429     _GLFWwindow* window = (_GLFWwindow*) handle;
430 
431     if (xpos)
432         *xpos = 0;
433     if (ypos)
434         *ypos = 0;
435 
436     _GLFW_REQUIRE_INIT();
437     _glfwPlatformGetWindowPos(window, xpos, ypos);
438 }
439 
glfwSetWindowPos(GLFWwindow * handle,int xpos,int ypos)440 GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
441 {
442     _GLFWwindow* window = (_GLFWwindow*) handle;
443 
444     _GLFW_REQUIRE_INIT();
445 
446     if (window->monitor)
447     {
448         _glfwInputError(GLFW_INVALID_VALUE,
449                         "Full screen windows cannot be moved");
450         return;
451     }
452 
453     _glfwPlatformSetWindowPos(window, xpos, ypos);
454 }
455 
glfwGetWindowSize(GLFWwindow * handle,int * width,int * height)456 GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
457 {
458     _GLFWwindow* window = (_GLFWwindow*) handle;
459 
460     if (width)
461         *width = 0;
462     if (height)
463         *height = 0;
464 
465     _GLFW_REQUIRE_INIT();
466     _glfwPlatformGetWindowSize(window, width, height);
467 }
468 
glfwSetWindowSize(GLFWwindow * handle,int width,int height)469 GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
470 {
471     _GLFWwindow* window = (_GLFWwindow*) handle;
472 
473     _GLFW_REQUIRE_INIT();
474 
475     if (window->monitor)
476     {
477         window->videoMode.width  = width;
478         window->videoMode.height = height;
479     }
480 
481     _glfwPlatformSetWindowSize(window, width, height);
482 }
483 
glfwGetFramebufferSize(GLFWwindow * handle,int * width,int * height)484 GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height)
485 {
486     _GLFWwindow* window = (_GLFWwindow*) handle;
487 
488     if (width)
489         *width = 0;
490     if (height)
491         *height = 0;
492 
493     _GLFW_REQUIRE_INIT();
494     _glfwPlatformGetFramebufferSize(window, width, height);
495 }
496 
glfwGetWindowFrameSize(GLFWwindow * handle,int * left,int * top,int * right,int * bottom)497 GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
498                                     int* left, int* top,
499                                     int* right, int* bottom)
500 {
501     _GLFWwindow* window = (_GLFWwindow*) handle;
502 
503     if (left)
504         *left = 0;
505     if (top)
506         *top = 0;
507     if (right)
508         *right = 0;
509     if (bottom)
510         *bottom = 0;
511 
512     _GLFW_REQUIRE_INIT();
513     _glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
514 }
515 
glfwIconifyWindow(GLFWwindow * handle)516 GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
517 {
518     _GLFWwindow* window = (_GLFWwindow*) handle;
519     _GLFW_REQUIRE_INIT();
520     _glfwPlatformIconifyWindow(window);
521 }
522 
glfwRestoreWindow(GLFWwindow * handle)523 GLFWAPI void glfwRestoreWindow(GLFWwindow* handle)
524 {
525     _GLFWwindow* window = (_GLFWwindow*) handle;
526     _GLFW_REQUIRE_INIT();
527     _glfwPlatformRestoreWindow(window);
528 }
529 
glfwShowWindow(GLFWwindow * handle)530 GLFWAPI void glfwShowWindow(GLFWwindow* handle)
531 {
532     _GLFWwindow* window = (_GLFWwindow*) handle;
533 
534     _GLFW_REQUIRE_INIT();
535 
536     if (window->monitor)
537         return;
538 
539     _glfwPlatformShowWindow(window);
540 }
541 
glfwHideWindow(GLFWwindow * handle)542 GLFWAPI void glfwHideWindow(GLFWwindow* handle)
543 {
544     _GLFWwindow* window = (_GLFWwindow*) handle;
545 
546     _GLFW_REQUIRE_INIT();
547 
548     if (window->monitor)
549         return;
550 
551     _glfwPlatformHideWindow(window);
552 }
553 
glfwGetWindowAttrib(GLFWwindow * handle,int attrib)554 GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
555 {
556     _GLFWwindow* window = (_GLFWwindow*) handle;
557 
558     _GLFW_REQUIRE_INIT_OR_RETURN(0);
559 
560     switch (attrib)
561     {
562         case GLFW_FOCUSED:
563             return _glfwPlatformWindowFocused(window);
564         case GLFW_ICONIFIED:
565             return _glfwPlatformWindowIconified(window);
566         case GLFW_VISIBLE:
567             return _glfwPlatformWindowVisible(window);
568         case GLFW_RESIZABLE:
569             return window->resizable;
570         case GLFW_DECORATED:
571             return window->decorated;
572         case GLFW_FLOATING:
573             return window->floating;
574         case GLFW_CLIENT_API:
575             return window->context.api;
576         case GLFW_CONTEXT_VERSION_MAJOR:
577             return window->context.major;
578         case GLFW_CONTEXT_VERSION_MINOR:
579             return window->context.minor;
580         case GLFW_CONTEXT_REVISION:
581             return window->context.revision;
582         case GLFW_CONTEXT_ROBUSTNESS:
583             return window->context.robustness;
584         case GLFW_OPENGL_FORWARD_COMPAT:
585             return window->context.forward;
586         case GLFW_OPENGL_DEBUG_CONTEXT:
587             return window->context.debug;
588         case GLFW_OPENGL_PROFILE:
589             return window->context.profile;
590         case GLFW_CONTEXT_RELEASE_BEHAVIOR:
591             return window->context.release;
592     }
593 
594     _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute");
595     return 0;
596 }
597 
glfwGetWindowMonitor(GLFWwindow * handle)598 GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle)
599 {
600     _GLFWwindow* window = (_GLFWwindow*) handle;
601     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
602     return (GLFWmonitor*) window->monitor;
603 }
604 
glfwSetWindowUserPointer(GLFWwindow * handle,void * pointer)605 GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
606 {
607     _GLFWwindow* window = (_GLFWwindow*) handle;
608     _GLFW_REQUIRE_INIT();
609     window->userPointer = pointer;
610 }
611 
glfwGetWindowUserPointer(GLFWwindow * handle)612 GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
613 {
614     _GLFWwindow* window = (_GLFWwindow*) handle;
615     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
616     return window->userPointer;
617 }
618 
glfwSetWindowPosCallback(GLFWwindow * handle,GLFWwindowposfun cbfun)619 GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
620                                                   GLFWwindowposfun cbfun)
621 {
622     _GLFWwindow* window = (_GLFWwindow*) handle;
623     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
624     _GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
625     return cbfun;
626 }
627 
glfwSetWindowSizeCallback(GLFWwindow * handle,GLFWwindowsizefun cbfun)628 GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
629                                                     GLFWwindowsizefun cbfun)
630 {
631     _GLFWwindow* window = (_GLFWwindow*) handle;
632     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
633     _GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
634     return cbfun;
635 }
636 
glfwSetWindowCloseCallback(GLFWwindow * handle,GLFWwindowclosefun cbfun)637 GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
638                                                       GLFWwindowclosefun cbfun)
639 {
640     _GLFWwindow* window = (_GLFWwindow*) handle;
641     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
642     _GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
643     return cbfun;
644 }
645 
glfwSetWindowRefreshCallback(GLFWwindow * handle,GLFWwindowrefreshfun cbfun)646 GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
647                                                           GLFWwindowrefreshfun cbfun)
648 {
649     _GLFWwindow* window = (_GLFWwindow*) handle;
650     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
651     _GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
652     return cbfun;
653 }
654 
glfwSetWindowFocusCallback(GLFWwindow * handle,GLFWwindowfocusfun cbfun)655 GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
656                                                       GLFWwindowfocusfun cbfun)
657 {
658     _GLFWwindow* window = (_GLFWwindow*) handle;
659     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
660     _GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
661     return cbfun;
662 }
663 
glfwSetWindowIconifyCallback(GLFWwindow * handle,GLFWwindowiconifyfun cbfun)664 GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
665                                                           GLFWwindowiconifyfun cbfun)
666 {
667     _GLFWwindow* window = (_GLFWwindow*) handle;
668     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
669     _GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
670     return cbfun;
671 }
672 
glfwSetFramebufferSizeCallback(GLFWwindow * handle,GLFWframebuffersizefun cbfun)673 GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
674                                                               GLFWframebuffersizefun cbfun)
675 {
676     _GLFWwindow* window = (_GLFWwindow*) handle;
677     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
678     _GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
679     return cbfun;
680 }
681 
glfwPollEvents(void)682 GLFWAPI void glfwPollEvents(void)
683 {
684     _GLFW_REQUIRE_INIT();
685     _glfwPlatformPollEvents();
686 }
687 
glfwWaitEvents(void)688 GLFWAPI void glfwWaitEvents(void)
689 {
690     _GLFW_REQUIRE_INIT();
691 
692     if (!_glfw.windowListHead)
693         return;
694 
695     _glfwPlatformWaitEvents();
696 }
697 
glfwPostEmptyEvent(void)698 GLFWAPI void glfwPostEmptyEvent(void)
699 {
700     _GLFW_REQUIRE_INIT();
701 
702     if (!_glfw.windowListHead)
703         return;
704 
705     _glfwPlatformPostEmptyEvent();
706 }
707 
708