1 //========================================================================
2 // Event linter (event spewer)
3 // Copyright (c) Camilla Löwy <elmindreda@glfw.org>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 //    claim that you wrote the original software. If you use this software
15 //    in a product, an acknowledgment in the product documentation would
16 //    be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 //    be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 //    distribution.
23 //
24 //========================================================================
25 //
26 // This test hooks every available callback and outputs their arguments
27 //
28 // Log messages go to stdout, error messages to stderr
29 //
30 // Every event also gets a (sequential) number to aid discussion of logs
31 //
32 //========================================================================
33 
34 #include <glad/glad.h>
35 #include <GLFW/glfw3.h>
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <ctype.h>
40 #include <string.h>
41 #include <locale.h>
42 
43 #include "getopt.h"
44 
45 // Event index
46 static unsigned int counter = 0;
47 
48 typedef struct
49 {
50     GLFWwindow* window;
51     int number;
52     int closeable;
53 } Slot;
54 
usage(void)55 static void usage(void)
56 {
57     printf("Usage: events [-f] [-h] [-n WINDOWS]\n");
58     printf("Options:\n");
59     printf("  -f use full screen\n");
60     printf("  -h show this help\n");
61     printf("  -n the number of windows to create\n");
62 }
63 
get_key_name(int key)64 static const char* get_key_name(int key)
65 {
66     switch (key)
67     {
68         // Printable keys
69         case GLFW_KEY_A:            return "A";
70         case GLFW_KEY_B:            return "B";
71         case GLFW_KEY_C:            return "C";
72         case GLFW_KEY_D:            return "D";
73         case GLFW_KEY_E:            return "E";
74         case GLFW_KEY_F:            return "F";
75         case GLFW_KEY_G:            return "G";
76         case GLFW_KEY_H:            return "H";
77         case GLFW_KEY_I:            return "I";
78         case GLFW_KEY_J:            return "J";
79         case GLFW_KEY_K:            return "K";
80         case GLFW_KEY_L:            return "L";
81         case GLFW_KEY_M:            return "M";
82         case GLFW_KEY_N:            return "N";
83         case GLFW_KEY_O:            return "O";
84         case GLFW_KEY_P:            return "P";
85         case GLFW_KEY_Q:            return "Q";
86         case GLFW_KEY_R:            return "R";
87         case GLFW_KEY_S:            return "S";
88         case GLFW_KEY_T:            return "T";
89         case GLFW_KEY_U:            return "U";
90         case GLFW_KEY_V:            return "V";
91         case GLFW_KEY_W:            return "W";
92         case GLFW_KEY_X:            return "X";
93         case GLFW_KEY_Y:            return "Y";
94         case GLFW_KEY_Z:            return "Z";
95         case GLFW_KEY_1:            return "1";
96         case GLFW_KEY_2:            return "2";
97         case GLFW_KEY_3:            return "3";
98         case GLFW_KEY_4:            return "4";
99         case GLFW_KEY_5:            return "5";
100         case GLFW_KEY_6:            return "6";
101         case GLFW_KEY_7:            return "7";
102         case GLFW_KEY_8:            return "8";
103         case GLFW_KEY_9:            return "9";
104         case GLFW_KEY_0:            return "0";
105         case GLFW_KEY_SPACE:        return "SPACE";
106         case GLFW_KEY_MINUS:        return "MINUS";
107         case GLFW_KEY_EQUAL:        return "EQUAL";
108         case GLFW_KEY_LEFT_BRACKET: return "LEFT BRACKET";
109         case GLFW_KEY_RIGHT_BRACKET: return "RIGHT BRACKET";
110         case GLFW_KEY_BACKSLASH:    return "BACKSLASH";
111         case GLFW_KEY_SEMICOLON:    return "SEMICOLON";
112         case GLFW_KEY_APOSTROPHE:   return "APOSTROPHE";
113         case GLFW_KEY_GRAVE_ACCENT: return "GRAVE ACCENT";
114         case GLFW_KEY_COMMA:        return "COMMA";
115         case GLFW_KEY_PERIOD:       return "PERIOD";
116         case GLFW_KEY_SLASH:        return "SLASH";
117         case GLFW_KEY_WORLD_1:      return "WORLD 1";
118         case GLFW_KEY_WORLD_2:      return "WORLD 2";
119 
120         // Function keys
121         case GLFW_KEY_ESCAPE:       return "ESCAPE";
122         case GLFW_KEY_F1:           return "F1";
123         case GLFW_KEY_F2:           return "F2";
124         case GLFW_KEY_F3:           return "F3";
125         case GLFW_KEY_F4:           return "F4";
126         case GLFW_KEY_F5:           return "F5";
127         case GLFW_KEY_F6:           return "F6";
128         case GLFW_KEY_F7:           return "F7";
129         case GLFW_KEY_F8:           return "F8";
130         case GLFW_KEY_F9:           return "F9";
131         case GLFW_KEY_F10:          return "F10";
132         case GLFW_KEY_F11:          return "F11";
133         case GLFW_KEY_F12:          return "F12";
134         case GLFW_KEY_F13:          return "F13";
135         case GLFW_KEY_F14:          return "F14";
136         case GLFW_KEY_F15:          return "F15";
137         case GLFW_KEY_F16:          return "F16";
138         case GLFW_KEY_F17:          return "F17";
139         case GLFW_KEY_F18:          return "F18";
140         case GLFW_KEY_F19:          return "F19";
141         case GLFW_KEY_F20:          return "F20";
142         case GLFW_KEY_F21:          return "F21";
143         case GLFW_KEY_F22:          return "F22";
144         case GLFW_KEY_F23:          return "F23";
145         case GLFW_KEY_F24:          return "F24";
146         case GLFW_KEY_F25:          return "F25";
147         case GLFW_KEY_UP:           return "UP";
148         case GLFW_KEY_DOWN:         return "DOWN";
149         case GLFW_KEY_LEFT:         return "LEFT";
150         case GLFW_KEY_RIGHT:        return "RIGHT";
151         case GLFW_KEY_LEFT_SHIFT:   return "LEFT SHIFT";
152         case GLFW_KEY_RIGHT_SHIFT:  return "RIGHT SHIFT";
153         case GLFW_KEY_LEFT_CONTROL: return "LEFT CONTROL";
154         case GLFW_KEY_RIGHT_CONTROL: return "RIGHT CONTROL";
155         case GLFW_KEY_LEFT_ALT:     return "LEFT ALT";
156         case GLFW_KEY_RIGHT_ALT:    return "RIGHT ALT";
157         case GLFW_KEY_TAB:          return "TAB";
158         case GLFW_KEY_ENTER:        return "ENTER";
159         case GLFW_KEY_BACKSPACE:    return "BACKSPACE";
160         case GLFW_KEY_INSERT:       return "INSERT";
161         case GLFW_KEY_DELETE:       return "DELETE";
162         case GLFW_KEY_PAGE_UP:      return "PAGE UP";
163         case GLFW_KEY_PAGE_DOWN:    return "PAGE DOWN";
164         case GLFW_KEY_HOME:         return "HOME";
165         case GLFW_KEY_END:          return "END";
166         case GLFW_KEY_KP_0:         return "KEYPAD 0";
167         case GLFW_KEY_KP_1:         return "KEYPAD 1";
168         case GLFW_KEY_KP_2:         return "KEYPAD 2";
169         case GLFW_KEY_KP_3:         return "KEYPAD 3";
170         case GLFW_KEY_KP_4:         return "KEYPAD 4";
171         case GLFW_KEY_KP_5:         return "KEYPAD 5";
172         case GLFW_KEY_KP_6:         return "KEYPAD 6";
173         case GLFW_KEY_KP_7:         return "KEYPAD 7";
174         case GLFW_KEY_KP_8:         return "KEYPAD 8";
175         case GLFW_KEY_KP_9:         return "KEYPAD 9";
176         case GLFW_KEY_KP_DIVIDE:    return "KEYPAD DIVIDE";
177         case GLFW_KEY_KP_MULTIPLY:  return "KEYPAD MULTPLY";
178         case GLFW_KEY_KP_SUBTRACT:  return "KEYPAD SUBTRACT";
179         case GLFW_KEY_KP_ADD:       return "KEYPAD ADD";
180         case GLFW_KEY_KP_DECIMAL:   return "KEYPAD DECIMAL";
181         case GLFW_KEY_KP_EQUAL:     return "KEYPAD EQUAL";
182         case GLFW_KEY_KP_ENTER:     return "KEYPAD ENTER";
183         case GLFW_KEY_PRINT_SCREEN: return "PRINT SCREEN";
184         case GLFW_KEY_NUM_LOCK:     return "NUM LOCK";
185         case GLFW_KEY_CAPS_LOCK:    return "CAPS LOCK";
186         case GLFW_KEY_SCROLL_LOCK:  return "SCROLL LOCK";
187         case GLFW_KEY_PAUSE:        return "PAUSE";
188         case GLFW_KEY_LEFT_SUPER:   return "LEFT SUPER";
189         case GLFW_KEY_RIGHT_SUPER:  return "RIGHT SUPER";
190         case GLFW_KEY_MENU:         return "MENU";
191 
192         default:                    return "UNKNOWN";
193     }
194 }
195 
get_action_name(int action)196 static const char* get_action_name(int action)
197 {
198     switch (action)
199     {
200         case GLFW_PRESS:
201             return "pressed";
202         case GLFW_RELEASE:
203             return "released";
204         case GLFW_REPEAT:
205             return "repeated";
206     }
207 
208     return "caused unknown action";
209 }
210 
get_button_name(int button)211 static const char* get_button_name(int button)
212 {
213     switch (button)
214     {
215         case GLFW_MOUSE_BUTTON_LEFT:
216             return "left";
217         case GLFW_MOUSE_BUTTON_RIGHT:
218             return "right";
219         case GLFW_MOUSE_BUTTON_MIDDLE:
220             return "middle";
221         default:
222         {
223             static char name[16];
224             snprintf(name, sizeof(name), "%i", button);
225             return name;
226         }
227     }
228 }
229 
get_mods_name(int mods)230 static const char* get_mods_name(int mods)
231 {
232     static char name[512];
233 
234     if (mods == 0)
235         return " no mods";
236 
237     name[0] = '\0';
238 
239     if (mods & GLFW_MOD_SHIFT)
240         strcat(name, " shift");
241     if (mods & GLFW_MOD_CONTROL)
242         strcat(name, " control");
243     if (mods & GLFW_MOD_ALT)
244         strcat(name, " alt");
245     if (mods & GLFW_MOD_SUPER)
246         strcat(name, " super");
247     if (mods & GLFW_MOD_CAPS_LOCK)
248         strcat(name, " capslock-on");
249     if (mods & GLFW_MOD_NUM_LOCK)
250         strcat(name, " numlock-on");
251 
252     return name;
253 }
254 
get_character_string(int codepoint)255 static const char* get_character_string(int codepoint)
256 {
257     // This assumes UTF-8, which is stupid
258     static char result[6 + 1];
259 
260     int length = wctomb(result, codepoint);
261     if (length == -1)
262         length = 0;
263 
264     result[length] = '\0';
265     return result;
266 }
267 
error_callback(int error,const char * description)268 static void error_callback(int error, const char* description)
269 {
270     fprintf(stderr, "Error: %s\n", description);
271 }
272 
window_pos_callback(GLFWwindow * window,int x,int y)273 static void window_pos_callback(GLFWwindow* window, int x, int y)
274 {
275     Slot* slot = glfwGetWindowUserPointer(window);
276     printf("%08x to %i at %0.3f: Window position: %i %i\n",
277            counter++, slot->number, glfwGetTime(), x, y);
278 }
279 
window_size_callback(GLFWwindow * window,int width,int height)280 static void window_size_callback(GLFWwindow* window, int width, int height)
281 {
282     Slot* slot = glfwGetWindowUserPointer(window);
283     printf("%08x to %i at %0.3f: Window size: %i %i\n",
284            counter++, slot->number, glfwGetTime(), width, height);
285 }
286 
framebuffer_size_callback(GLFWwindow * window,int width,int height)287 static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
288 {
289     Slot* slot = glfwGetWindowUserPointer(window);
290     printf("%08x to %i at %0.3f: Framebuffer size: %i %i\n",
291            counter++, slot->number, glfwGetTime(), width, height);
292 }
293 
window_content_scale_callback(GLFWwindow * window,float xscale,float yscale)294 static void window_content_scale_callback(GLFWwindow* window, float xscale, float yscale)
295 {
296     Slot* slot = glfwGetWindowUserPointer(window);
297     printf("%08x to %i at %0.3f: Window content scale: %0.3f %0.3f\n",
298            counter++, slot->number, glfwGetTime(), xscale, yscale);
299 }
300 
window_close_callback(GLFWwindow * window)301 static void window_close_callback(GLFWwindow* window)
302 {
303     Slot* slot = glfwGetWindowUserPointer(window);
304     printf("%08x to %i at %0.3f: Window close\n",
305            counter++, slot->number, glfwGetTime());
306 
307     glfwSetWindowShouldClose(window, slot->closeable);
308 }
309 
window_refresh_callback(GLFWwindow * window)310 static void window_refresh_callback(GLFWwindow* window)
311 {
312     Slot* slot = glfwGetWindowUserPointer(window);
313     printf("%08x to %i at %0.3f: Window refresh\n",
314            counter++, slot->number, glfwGetTime());
315 
316     glfwMakeContextCurrent(window);
317     glClear(GL_COLOR_BUFFER_BIT);
318     glfwSwapBuffers(window);
319 }
320 
window_focus_callback(GLFWwindow * window,int focused)321 static void window_focus_callback(GLFWwindow* window, int focused)
322 {
323     Slot* slot = glfwGetWindowUserPointer(window);
324     printf("%08x to %i at %0.3f: Window %s\n",
325            counter++, slot->number, glfwGetTime(),
326            focused ? "focused" : "defocused");
327 }
328 
window_iconify_callback(GLFWwindow * window,int iconified)329 static void window_iconify_callback(GLFWwindow* window, int iconified)
330 {
331     Slot* slot = glfwGetWindowUserPointer(window);
332     printf("%08x to %i at %0.3f: Window was %s\n",
333            counter++, slot->number, glfwGetTime(),
334            iconified ? "iconified" : "uniconified");
335 }
336 
window_maximize_callback(GLFWwindow * window,int maximized)337 static void window_maximize_callback(GLFWwindow* window, int maximized)
338 {
339     Slot* slot = glfwGetWindowUserPointer(window);
340     printf("%08x to %i at %0.3f: Window was %s\n",
341            counter++, slot->number, glfwGetTime(),
342            maximized ? "maximized" : "unmaximized");
343 }
344 
mouse_button_callback(GLFWwindow * window,int button,int action,int mods)345 static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
346 {
347     Slot* slot = glfwGetWindowUserPointer(window);
348     printf("%08x to %i at %0.3f: Mouse button %i (%s) (with%s) was %s\n",
349            counter++, slot->number, glfwGetTime(), button,
350            get_button_name(button),
351            get_mods_name(mods),
352            get_action_name(action));
353 }
354 
cursor_position_callback(GLFWwindow * window,double x,double y)355 static void cursor_position_callback(GLFWwindow* window, double x, double y)
356 {
357     Slot* slot = glfwGetWindowUserPointer(window);
358     printf("%08x to %i at %0.3f: Cursor position: %f %f\n",
359            counter++, slot->number, glfwGetTime(), x, y);
360 }
361 
cursor_enter_callback(GLFWwindow * window,int entered)362 static void cursor_enter_callback(GLFWwindow* window, int entered)
363 {
364     Slot* slot = glfwGetWindowUserPointer(window);
365     printf("%08x to %i at %0.3f: Cursor %s window\n",
366            counter++, slot->number, glfwGetTime(),
367            entered ? "entered" : "left");
368 }
369 
scroll_callback(GLFWwindow * window,double x,double y)370 static void scroll_callback(GLFWwindow* window, double x, double y)
371 {
372     Slot* slot = glfwGetWindowUserPointer(window);
373     printf("%08x to %i at %0.3f: Scroll: %0.3f %0.3f\n",
374            counter++, slot->number, glfwGetTime(), x, y);
375 }
376 
key_callback(GLFWwindow * window,int key,int scancode,int action,int mods)377 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
378 {
379     Slot* slot = glfwGetWindowUserPointer(window);
380     const char* name = glfwGetKeyName(key, scancode);
381 
382     if (name)
383     {
384         printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (%s) (with%s) was %s\n",
385                counter++, slot->number, glfwGetTime(), key, scancode,
386                get_key_name(key),
387                name,
388                get_mods_name(mods),
389                get_action_name(action));
390     }
391     else
392     {
393         printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (with%s) was %s\n",
394                counter++, slot->number, glfwGetTime(), key, scancode,
395                get_key_name(key),
396                get_mods_name(mods),
397                get_action_name(action));
398     }
399 
400     if (action != GLFW_PRESS)
401         return;
402 
403     switch (key)
404     {
405         case GLFW_KEY_C:
406         {
407             slot->closeable = !slot->closeable;
408 
409             printf("(( closing %s ))\n", slot->closeable ? "enabled" : "disabled");
410             break;
411         }
412 
413         case GLFW_KEY_L:
414         {
415             const int state = glfwGetInputMode(window, GLFW_LOCK_KEY_MODS);
416             glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, !state);
417 
418             printf("(( lock key mods %s ))\n", !state ? "enabled" : "disabled");
419             break;
420         }
421     }
422 }
423 
char_callback(GLFWwindow * window,unsigned int codepoint)424 static void char_callback(GLFWwindow* window, unsigned int codepoint)
425 {
426     Slot* slot = glfwGetWindowUserPointer(window);
427     printf("%08x to %i at %0.3f: Character 0x%08x (%s) input\n",
428            counter++, slot->number, glfwGetTime(), codepoint,
429            get_character_string(codepoint));
430 }
431 
char_mods_callback(GLFWwindow * window,unsigned int codepoint,int mods)432 static void char_mods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
433 {
434     Slot* slot = glfwGetWindowUserPointer(window);
435     printf("%08x to %i at %0.3f: Character 0x%08x (%s) with modifiers (with%s) input\n",
436             counter++, slot->number, glfwGetTime(), codepoint,
437             get_character_string(codepoint),
438             get_mods_name(mods));
439 }
440 
drop_callback(GLFWwindow * window,int count,const char ** paths)441 static void drop_callback(GLFWwindow* window, int count, const char** paths)
442 {
443     int i;
444     Slot* slot = glfwGetWindowUserPointer(window);
445 
446     printf("%08x to %i at %0.3f: Drop input\n",
447            counter++, slot->number, glfwGetTime());
448 
449     for (i = 0;  i < count;  i++)
450         printf("  %i: \"%s\"\n", i, paths[i]);
451 }
452 
monitor_callback(GLFWmonitor * monitor,int event)453 static void monitor_callback(GLFWmonitor* monitor, int event)
454 {
455     if (event == GLFW_CONNECTED)
456     {
457         int x, y, widthMM, heightMM;
458         const GLFWvidmode* mode = glfwGetVideoMode(monitor);
459 
460         glfwGetMonitorPos(monitor, &x, &y);
461         glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
462 
463         printf("%08x at %0.3f: Monitor %s (%ix%i at %ix%i, %ix%i mm) was connected\n",
464                counter++,
465                glfwGetTime(),
466                glfwGetMonitorName(monitor),
467                mode->width, mode->height,
468                x, y,
469                widthMM, heightMM);
470     }
471     else if (event == GLFW_DISCONNECTED)
472     {
473         printf("%08x at %0.3f: Monitor %s was disconnected\n",
474                counter++,
475                glfwGetTime(),
476                glfwGetMonitorName(monitor));
477     }
478 }
479 
joystick_callback(int jid,int event)480 static void joystick_callback(int jid, int event)
481 {
482     if (event == GLFW_CONNECTED)
483     {
484         int axisCount, buttonCount, hatCount;
485 
486         glfwGetJoystickAxes(jid, &axisCount);
487         glfwGetJoystickButtons(jid, &buttonCount);
488         glfwGetJoystickHats(jid, &hatCount);
489 
490         printf("%08x at %0.3f: Joystick %i (%s) was connected with %i axes, %i buttons, and %i hats\n",
491                counter++, glfwGetTime(),
492                jid,
493                glfwGetJoystickName(jid),
494                axisCount,
495                buttonCount,
496                hatCount);
497     }
498     else
499     {
500         printf("%08x at %0.3f: Joystick %i was disconnected\n",
501                counter++, glfwGetTime(), jid);
502     }
503 }
504 
main(int argc,char ** argv)505 int main(int argc, char** argv)
506 {
507     Slot* slots;
508     GLFWmonitor* monitor = NULL;
509     int ch, i, width, height, count = 1;
510 
511     setlocale(LC_ALL, "");
512 
513     glfwSetErrorCallback(error_callback);
514 
515     if (!glfwInit())
516         exit(EXIT_FAILURE);
517 
518     printf("Library initialized\n");
519 
520     glfwSetMonitorCallback(monitor_callback);
521     glfwSetJoystickCallback(joystick_callback);
522 
523     while ((ch = getopt(argc, argv, "hfn:")) != -1)
524     {
525         switch (ch)
526         {
527             case 'h':
528                 usage();
529                 exit(EXIT_SUCCESS);
530 
531             case 'f':
532                 monitor = glfwGetPrimaryMonitor();
533                 break;
534 
535             case 'n':
536                 count = (int) strtol(optarg, NULL, 10);
537                 break;
538 
539             default:
540                 usage();
541                 exit(EXIT_FAILURE);
542         }
543     }
544 
545     if (monitor)
546     {
547         const GLFWvidmode* mode = glfwGetVideoMode(monitor);
548 
549         glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
550         glfwWindowHint(GLFW_RED_BITS, mode->redBits);
551         glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
552         glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
553 
554         width = mode->width;
555         height = mode->height;
556     }
557     else
558     {
559         width  = 640;
560         height = 480;
561     }
562 
563     if (!count)
564     {
565         fprintf(stderr, "Invalid user\n");
566         exit(EXIT_FAILURE);
567     }
568 
569     slots = calloc(count, sizeof(Slot));
570 
571     for (i = 0;  i < count;  i++)
572     {
573         char title[128];
574 
575         slots[i].closeable = GLFW_TRUE;
576         slots[i].number = i + 1;
577 
578         snprintf(title, sizeof(title), "Event Linter (Window %i)", slots[i].number);
579 
580         if (monitor)
581         {
582             printf("Creating full screen window %i (%ix%i on %s)\n",
583                    slots[i].number,
584                    width, height,
585                    glfwGetMonitorName(monitor));
586         }
587         else
588         {
589             printf("Creating windowed mode window %i (%ix%i)\n",
590                    slots[i].number,
591                    width, height);
592         }
593 
594         slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL);
595         if (!slots[i].window)
596         {
597             free(slots);
598             glfwTerminate();
599             exit(EXIT_FAILURE);
600         }
601 
602         glfwSetWindowUserPointer(slots[i].window, slots + i);
603 
604         glfwSetWindowPosCallback(slots[i].window, window_pos_callback);
605         glfwSetWindowSizeCallback(slots[i].window, window_size_callback);
606         glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback);
607         glfwSetWindowContentScaleCallback(slots[i].window, window_content_scale_callback);
608         glfwSetWindowCloseCallback(slots[i].window, window_close_callback);
609         glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback);
610         glfwSetWindowFocusCallback(slots[i].window, window_focus_callback);
611         glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback);
612         glfwSetWindowMaximizeCallback(slots[i].window, window_maximize_callback);
613         glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback);
614         glfwSetCursorPosCallback(slots[i].window, cursor_position_callback);
615         glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback);
616         glfwSetScrollCallback(slots[i].window, scroll_callback);
617         glfwSetKeyCallback(slots[i].window, key_callback);
618         glfwSetCharCallback(slots[i].window, char_callback);
619         glfwSetCharModsCallback(slots[i].window, char_mods_callback);
620         glfwSetDropCallback(slots[i].window, drop_callback);
621 
622         glfwMakeContextCurrent(slots[i].window);
623         gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
624         glfwSwapInterval(1);
625     }
626 
627     printf("Main loop starting\n");
628 
629     for (;;)
630     {
631         for (i = 0;  i < count;  i++)
632         {
633             if (glfwWindowShouldClose(slots[i].window))
634                 break;
635         }
636 
637         if (i < count)
638             break;
639 
640         glfwWaitEvents();
641 
642         // Workaround for an issue with msvcrt and mintty
643         fflush(stdout);
644     }
645 
646     free(slots);
647     glfwTerminate();
648     exit(EXIT_SUCCESS);
649 }
650 
651