events.c 21 KB

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