2
0

events.c 22 KB

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