events.c 21 KB

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