window.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. //========================================================================
  2. // GLFW 3.4 - www.glfw.org
  3. //------------------------------------------------------------------------
  4. // Copyright (c) 2002-2006 Marcus Geelnard
  5. // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
  6. // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
  7. //
  8. // This software is provided 'as-is', without any express or implied
  9. // warranty. In no event will the authors be held liable for any damages
  10. // arising from the use of this software.
  11. //
  12. // Permission is granted to anyone to use this software for any purpose,
  13. // including commercial applications, and to alter it and redistribute it
  14. // freely, subject to the following restrictions:
  15. //
  16. // 1. The origin of this software must not be misrepresented; you must not
  17. // claim that you wrote the original software. If you use this software
  18. // in a product, an acknowledgment in the product documentation would
  19. // be appreciated but is not required.
  20. //
  21. // 2. Altered source versions must be plainly marked as such, and must not
  22. // be misrepresented as being the original software.
  23. //
  24. // 3. This notice may not be removed or altered from any source
  25. // distribution.
  26. //
  27. //========================================================================
  28. // Please use C89 style variable declarations in this file because VS 2010
  29. //========================================================================
  30. #include "internal.h"
  31. #include "../kitty/monotonic.h"
  32. #include <assert.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. //////////////////////////////////////////////////////////////////////////
  36. ////// GLFW event API //////
  37. //////////////////////////////////////////////////////////////////////////
  38. // Notifies shared code that a window has lost or received input focus
  39. //
  40. void _glfwInputWindowFocus(_GLFWwindow* window, bool focused)
  41. {
  42. if (window->callbacks.focus)
  43. window->callbacks.focus((GLFWwindow*) window, focused);
  44. if (!focused)
  45. {
  46. _glfw.focusedWindowId = 0;
  47. for (unsigned i = 0; i < arraysz(window->activated_keys); i++)
  48. {
  49. if (window->activated_keys[i].key > 0 && window->activated_keys[i].action == GLFW_PRESS)
  50. {
  51. const int native_key = _glfwPlatformGetNativeKeyForKey(window->activated_keys[i].key);
  52. GLFWkeyevent ev = {.key = window->activated_keys[i].key, .native_key = native_key, .action = GLFW_RELEASE, .fake_event_on_focus_change = true};
  53. _glfwInputKeyboard(window, &ev);
  54. }
  55. }
  56. for (int button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++)
  57. {
  58. if (window->mouseButtons[button] == GLFW_PRESS)
  59. _glfwInputMouseClick(window, button, GLFW_RELEASE, 0);
  60. }
  61. } else
  62. _glfw.focusedWindowId = window->id;
  63. }
  64. _GLFWwindow* _glfwFocusedWindow(void) {
  65. if (_glfw.focusedWindowId) {
  66. _GLFWwindow *w = _glfw.windowListHead;
  67. while (w) {
  68. if (w->id == _glfw.focusedWindowId) return w;
  69. w = w->next;
  70. }
  71. }
  72. return NULL;
  73. }
  74. _GLFWwindow* _glfwWindowForId(GLFWid id) {
  75. _GLFWwindow *w = _glfw.windowListHead;
  76. while (w) {
  77. if (w->id == id) return w;
  78. w = w->next;
  79. }
  80. return NULL;
  81. }
  82. // Notifies shared code that a window's occlusion state has changed
  83. //
  84. void _glfwInputWindowOcclusion(_GLFWwindow* window, bool occluded)
  85. {
  86. if (window->callbacks.occlusion)
  87. window->callbacks.occlusion((GLFWwindow*) window, occluded);
  88. }
  89. // Notifies shared code that a window has moved
  90. // The position is specified in content area relative screen coordinates
  91. //
  92. void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
  93. {
  94. if (window->callbacks.pos)
  95. window->callbacks.pos((GLFWwindow*) window, x, y);
  96. }
  97. // Notifies shared code that a window has been resized
  98. // The size is specified in screen coordinates
  99. //
  100. void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
  101. {
  102. if (window->callbacks.size)
  103. window->callbacks.size((GLFWwindow*) window, width, height);
  104. }
  105. // Notifies shared code that a window has been iconified or restored
  106. //
  107. void _glfwInputWindowIconify(_GLFWwindow* window, bool iconified)
  108. {
  109. if (window->callbacks.iconify)
  110. window->callbacks.iconify((GLFWwindow*) window, iconified);
  111. }
  112. // Notifies shared code that a window has been maximized or restored
  113. //
  114. void _glfwInputWindowMaximize(_GLFWwindow* window, bool maximized)
  115. {
  116. if (window->callbacks.maximize)
  117. window->callbacks.maximize((GLFWwindow*) window, maximized);
  118. }
  119. // Notifies shared code that a window framebuffer has been resized
  120. // The size is specified in pixels
  121. //
  122. void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
  123. {
  124. if (window->callbacks.fbsize)
  125. window->callbacks.fbsize((GLFWwindow*) window, width, height);
  126. }
  127. // Notifies shared code that a window live resize is in progress
  128. //
  129. void _glfwInputLiveResize(_GLFWwindow* window, bool started)
  130. {
  131. if (window && window->callbacks.liveResize)
  132. window->callbacks.liveResize((GLFWwindow*) window, started);
  133. }
  134. // Notifies shared code that a window content scale has changed
  135. // The scale is specified as the ratio between the current and default DPI
  136. //
  137. void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale)
  138. {
  139. if (window->callbacks.scale)
  140. window->callbacks.scale((GLFWwindow*) window, xscale, yscale);
  141. }
  142. // Notifies shared code that the window contents needs updating
  143. //
  144. void _glfwInputWindowDamage(_GLFWwindow* window)
  145. {
  146. if (window->callbacks.refresh)
  147. window->callbacks.refresh((GLFWwindow*) window);
  148. }
  149. // Notifies shared code that the user wishes to close a window
  150. //
  151. void _glfwInputWindowCloseRequest(_GLFWwindow* window)
  152. {
  153. window->shouldClose = true;
  154. if (window->callbacks.close)
  155. window->callbacks.close((GLFWwindow*) window);
  156. }
  157. // Notifies shared code that a window has changed its desired monitor
  158. //
  159. void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor)
  160. {
  161. window->monitor = monitor;
  162. }
  163. //////////////////////////////////////////////////////////////////////////
  164. ////// GLFW public API //////
  165. //////////////////////////////////////////////////////////////////////////
  166. GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share, const GLFWLayerShellConfig *lsc) {
  167. _GLFWfbconfig fbconfig;
  168. _GLFWctxconfig ctxconfig;
  169. _GLFWwndconfig wndconfig;
  170. _GLFWwindow* window;
  171. assert(title != NULL);
  172. assert(width >= 0);
  173. assert(height >= 0);
  174. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  175. if (width <= 0 || height <= 0)
  176. {
  177. _glfwInputError(GLFW_INVALID_VALUE,
  178. "Invalid window size %ix%i",
  179. width, height);
  180. return NULL;
  181. }
  182. fbconfig = _glfw.hints.framebuffer;
  183. ctxconfig = _glfw.hints.context;
  184. wndconfig = _glfw.hints.window;
  185. wndconfig.width = width;
  186. wndconfig.height = height;
  187. wndconfig.title = title;
  188. ctxconfig.share = (_GLFWwindow*) share;
  189. if (!_glfwIsValidContextConfig(&ctxconfig))
  190. return NULL;
  191. static GLFWid windowIdCounter = 0;
  192. window = calloc(1, sizeof(_GLFWwindow));
  193. window->next = _glfw.windowListHead;
  194. window->id = ++windowIdCounter;
  195. _glfw.windowListHead = window;
  196. window->videoMode.width = width;
  197. window->videoMode.height = height;
  198. window->videoMode.redBits = fbconfig.redBits;
  199. window->videoMode.greenBits = fbconfig.greenBits;
  200. window->videoMode.blueBits = fbconfig.blueBits;
  201. window->videoMode.refreshRate = _glfw.hints.refreshRate;
  202. window->monitor = (_GLFWmonitor*) monitor;
  203. window->resizable = wndconfig.resizable;
  204. window->decorated = wndconfig.decorated;
  205. window->autoIconify = wndconfig.autoIconify;
  206. window->floating = wndconfig.floating;
  207. window->focusOnShow = wndconfig.focusOnShow;
  208. window->mousePassthrough = wndconfig.mousePassthrough;
  209. window->cursorMode = GLFW_CURSOR_NORMAL;
  210. window->minwidth = GLFW_DONT_CARE;
  211. window->minheight = GLFW_DONT_CARE;
  212. window->maxwidth = GLFW_DONT_CARE;
  213. window->maxheight = GLFW_DONT_CARE;
  214. window->numer = GLFW_DONT_CARE;
  215. window->denom = GLFW_DONT_CARE;
  216. window->widthincr = GLFW_DONT_CARE;
  217. window->heightincr = GLFW_DONT_CARE;
  218. // Open the actual window and create its context
  219. if (!_glfwPlatformCreateWindow(window, &wndconfig, &ctxconfig, &fbconfig, lsc))
  220. {
  221. glfwDestroyWindow((GLFWwindow*) window);
  222. return NULL;
  223. }
  224. if (ctxconfig.client != GLFW_NO_API)
  225. {
  226. if (!_glfwRefreshContextAttribs(window, &ctxconfig))
  227. {
  228. glfwDestroyWindow((GLFWwindow*) window);
  229. return NULL;
  230. }
  231. }
  232. if (wndconfig.mousePassthrough)
  233. _glfwPlatformSetWindowMousePassthrough(window, true);
  234. if (window->monitor)
  235. {
  236. if (wndconfig.centerCursor)
  237. _glfwCenterCursorInContentArea(window);
  238. }
  239. else
  240. {
  241. if (wndconfig.visible)
  242. {
  243. _glfwPlatformShowWindow(window);
  244. #ifndef _GLFW_WAYLAND
  245. if (wndconfig.focused)
  246. _glfwPlatformFocusWindow(window);
  247. #endif
  248. }
  249. }
  250. return (GLFWwindow*) window;
  251. }
  252. void glfwDefaultWindowHints(void)
  253. {
  254. _GLFW_REQUIRE_INIT();
  255. // The default is OpenGL with minimum version 1.0
  256. memset(&_glfw.hints.context, 0, sizeof(_glfw.hints.context));
  257. _glfw.hints.context.client = GLFW_OPENGL_API;
  258. _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API;
  259. _glfw.hints.context.major = 1;
  260. _glfw.hints.context.minor = 0;
  261. // The default is a focused, visible, resizable window with decorations
  262. memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window));
  263. _glfw.hints.window.resizable = true;
  264. _glfw.hints.window.visible = true;
  265. _glfw.hints.window.decorated = true;
  266. _glfw.hints.window.focused = true;
  267. _glfw.hints.window.autoIconify = true;
  268. _glfw.hints.window.centerCursor = true;
  269. _glfw.hints.window.focusOnShow = true;
  270. _glfw.hints.window.blur_radius = 0;
  271. // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
  272. // double buffered
  273. memset(&_glfw.hints.framebuffer, 0, sizeof(_glfw.hints.framebuffer));
  274. _glfw.hints.framebuffer.redBits = 8;
  275. _glfw.hints.framebuffer.greenBits = 8;
  276. _glfw.hints.framebuffer.blueBits = 8;
  277. _glfw.hints.framebuffer.alphaBits = 8;
  278. _glfw.hints.framebuffer.depthBits = 24;
  279. _glfw.hints.framebuffer.stencilBits = 8;
  280. _glfw.hints.framebuffer.doublebuffer = true;
  281. // The default is to select the highest available refresh rate
  282. _glfw.hints.refreshRate = GLFW_DONT_CARE;
  283. // The default is to use full Retina resolution framebuffers
  284. _glfw.hints.window.ns.retina = true;
  285. // use the default colorspace assigned by the system
  286. _glfw.hints.window.ns.color_space = 0;
  287. }
  288. GLFWAPI void glfwWindowHint(int hint, int value)
  289. {
  290. _GLFW_REQUIRE_INIT();
  291. switch (hint)
  292. {
  293. case GLFW_RED_BITS:
  294. _glfw.hints.framebuffer.redBits = value;
  295. return;
  296. case GLFW_GREEN_BITS:
  297. _glfw.hints.framebuffer.greenBits = value;
  298. return;
  299. case GLFW_BLUE_BITS:
  300. _glfw.hints.framebuffer.blueBits = value;
  301. return;
  302. case GLFW_ALPHA_BITS:
  303. _glfw.hints.framebuffer.alphaBits = value;
  304. return;
  305. case GLFW_DEPTH_BITS:
  306. _glfw.hints.framebuffer.depthBits = value;
  307. return;
  308. case GLFW_STENCIL_BITS:
  309. _glfw.hints.framebuffer.stencilBits = value;
  310. return;
  311. case GLFW_ACCUM_RED_BITS:
  312. _glfw.hints.framebuffer.accumRedBits = value;
  313. return;
  314. case GLFW_ACCUM_GREEN_BITS:
  315. _glfw.hints.framebuffer.accumGreenBits = value;
  316. return;
  317. case GLFW_ACCUM_BLUE_BITS:
  318. _glfw.hints.framebuffer.accumBlueBits = value;
  319. return;
  320. case GLFW_ACCUM_ALPHA_BITS:
  321. _glfw.hints.framebuffer.accumAlphaBits = value;
  322. return;
  323. case GLFW_AUX_BUFFERS:
  324. _glfw.hints.framebuffer.auxBuffers = value;
  325. return;
  326. case GLFW_STEREO:
  327. _glfw.hints.framebuffer.stereo = value ? true : false;
  328. return;
  329. case GLFW_DOUBLEBUFFER:
  330. _glfw.hints.framebuffer.doublebuffer = value ? true : false;
  331. return;
  332. case GLFW_TRANSPARENT_FRAMEBUFFER:
  333. _glfw.hints.framebuffer.transparent = value ? true : false;
  334. return;
  335. case GLFW_SAMPLES:
  336. _glfw.hints.framebuffer.samples = value;
  337. return;
  338. case GLFW_SRGB_CAPABLE:
  339. _glfw.hints.framebuffer.sRGB = value ? true : false;
  340. return;
  341. case GLFW_RESIZABLE:
  342. _glfw.hints.window.resizable = value ? true : false;
  343. return;
  344. case GLFW_DECORATED:
  345. _glfw.hints.window.decorated = value ? true : false;
  346. return;
  347. case GLFW_FOCUSED:
  348. _glfw.hints.window.focused = value ? true : false;
  349. return;
  350. case GLFW_AUTO_ICONIFY:
  351. _glfw.hints.window.autoIconify = value ? true : false;
  352. return;
  353. case GLFW_FLOATING:
  354. _glfw.hints.window.floating = value ? true : false;
  355. return;
  356. case GLFW_MAXIMIZED:
  357. _glfw.hints.window.maximized = value ? true : false;
  358. return;
  359. case GLFW_VISIBLE:
  360. _glfw.hints.window.visible = value ? true : false;
  361. return;
  362. case GLFW_COCOA_RETINA_FRAMEBUFFER:
  363. _glfw.hints.window.ns.retina = value ? true : false;
  364. return;
  365. case GLFW_COCOA_COLOR_SPACE:
  366. _glfw.hints.window.ns.color_space = value;
  367. return;
  368. case GLFW_BLUR_RADIUS:
  369. _glfw.hints.window.blur_radius = value;
  370. return;
  371. case GLFW_COCOA_GRAPHICS_SWITCHING:
  372. _glfw.hints.context.nsgl.offline = value ? true : false;
  373. return;
  374. case GLFW_SCALE_TO_MONITOR:
  375. _glfw.hints.window.scaleToMonitor = value ? true : false;
  376. return;
  377. case GLFW_CENTER_CURSOR:
  378. _glfw.hints.window.centerCursor = value ? true : false;
  379. return;
  380. case GLFW_FOCUS_ON_SHOW:
  381. _glfw.hints.window.focusOnShow = value ? true : false;
  382. return;
  383. case GLFW_MOUSE_PASSTHROUGH:
  384. _glfw.hints.window.mousePassthrough = value ? true : false;
  385. return;
  386. case GLFW_CLIENT_API:
  387. _glfw.hints.context.client = value;
  388. return;
  389. case GLFW_CONTEXT_CREATION_API:
  390. _glfw.hints.context.source = value;
  391. return;
  392. case GLFW_CONTEXT_VERSION_MAJOR:
  393. _glfw.hints.context.major = value;
  394. return;
  395. case GLFW_CONTEXT_VERSION_MINOR:
  396. _glfw.hints.context.minor = value;
  397. return;
  398. case GLFW_CONTEXT_ROBUSTNESS:
  399. _glfw.hints.context.robustness = value;
  400. return;
  401. case GLFW_OPENGL_FORWARD_COMPAT:
  402. _glfw.hints.context.forward = value ? true : false;
  403. return;
  404. case GLFW_CONTEXT_DEBUG:
  405. _glfw.hints.context.debug = value ? true : false;
  406. return;
  407. case GLFW_CONTEXT_NO_ERROR:
  408. _glfw.hints.context.noerror = value ? true : false;
  409. return;
  410. case GLFW_OPENGL_PROFILE:
  411. _glfw.hints.context.profile = value;
  412. return;
  413. case GLFW_CONTEXT_RELEASE_BEHAVIOR:
  414. _glfw.hints.context.release = value;
  415. return;
  416. case GLFW_REFRESH_RATE:
  417. _glfw.hints.refreshRate = value;
  418. return;
  419. case GLFW_WAYLAND_BGCOLOR:
  420. _glfw.hints.window.wl.bgcolor = value;
  421. return;
  422. }
  423. _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint);
  424. }
  425. GLFWAPI void glfwWindowHintString(int hint, const char* value)
  426. {
  427. assert(value != NULL);
  428. _GLFW_REQUIRE_INIT();
  429. switch (hint)
  430. {
  431. case GLFW_COCOA_FRAME_NAME:
  432. strncpy(_glfw.hints.window.ns.frameName, value,
  433. sizeof(_glfw.hints.window.ns.frameName) - 1);
  434. return;
  435. case GLFW_X11_CLASS_NAME:
  436. strncpy(_glfw.hints.window.x11.className, value,
  437. sizeof(_glfw.hints.window.x11.className) - 1);
  438. return;
  439. case GLFW_X11_INSTANCE_NAME:
  440. strncpy(_glfw.hints.window.x11.instanceName, value,
  441. sizeof(_glfw.hints.window.x11.instanceName) - 1);
  442. return;
  443. case GLFW_WAYLAND_APP_ID:
  444. strncpy(_glfw.hints.window.wl.appId, value,
  445. sizeof(_glfw.hints.window.wl.appId) - 1);
  446. return;
  447. }
  448. _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint);
  449. }
  450. GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
  451. {
  452. _GLFWwindow* window = (_GLFWwindow*) handle;
  453. _GLFW_REQUIRE_INIT();
  454. // Allow closing of NULL (to match the behavior of free)
  455. if (window == NULL)
  456. return;
  457. // Clear all callbacks to avoid exposing a half torn-down window object
  458. memset(&window->callbacks, 0, sizeof(window->callbacks));
  459. // The window's context must not be current on another thread when the
  460. // window is destroyed
  461. if (window == _glfwPlatformGetTls(&_glfw.contextSlot))
  462. glfwMakeContextCurrent(NULL);
  463. _glfwPlatformDestroyWindow(window);
  464. // Unlink window from global linked list
  465. {
  466. _GLFWwindow** prev = &_glfw.windowListHead;
  467. while (*prev != window)
  468. prev = &((*prev)->next);
  469. *prev = window->next;
  470. }
  471. free(window);
  472. }
  473. GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle)
  474. {
  475. _GLFWwindow* window = (_GLFWwindow*) handle;
  476. assert(window != NULL);
  477. _GLFW_REQUIRE_INIT_OR_RETURN(0);
  478. return window->shouldClose;
  479. }
  480. GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
  481. {
  482. _GLFWwindow* window = (_GLFWwindow*) handle;
  483. assert(window != NULL);
  484. _GLFW_REQUIRE_INIT();
  485. window->shouldClose = value;
  486. }
  487. GLFWAPI const GLFWLayerShellConfig* glfwGetLayerShellConfig(GLFWwindow* handle) {
  488. _GLFWwindow* window = (_GLFWwindow*) handle;
  489. assert(window != NULL);
  490. _GLFW_REQUIRE_INIT_OR_RETURN(false);
  491. return _glfwPlatformGetLayerShellConfig(window);
  492. }
  493. GLFWAPI bool glfwSetLayerShellConfig(GLFWwindow* handle, const GLFWLayerShellConfig *value) {
  494. _GLFWwindow* window = (_GLFWwindow*) handle;
  495. assert(window != NULL);
  496. _GLFW_REQUIRE_INIT_OR_RETURN(false);
  497. return _glfwPlatformSetLayerShellConfig(window, value);
  498. }
  499. GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
  500. {
  501. _GLFWwindow* window = (_GLFWwindow*) handle;
  502. assert(window != NULL);
  503. assert(title != NULL);
  504. _GLFW_REQUIRE_INIT();
  505. _glfwPlatformSetWindowTitle(window, title);
  506. }
  507. GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle,
  508. int count, const GLFWimage* images)
  509. {
  510. _GLFWwindow* window = (_GLFWwindow*) handle;
  511. assert(window != NULL);
  512. assert(count >= 0);
  513. assert(count == 0 || images != NULL);
  514. _GLFW_REQUIRE_INIT();
  515. _glfwPlatformSetWindowIcon(window, count, images);
  516. }
  517. GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
  518. {
  519. _GLFWwindow* window = (_GLFWwindow*) handle;
  520. assert(window != NULL);
  521. if (xpos)
  522. *xpos = 0;
  523. if (ypos)
  524. *ypos = 0;
  525. _GLFW_REQUIRE_INIT();
  526. _glfwPlatformGetWindowPos(window, xpos, ypos);
  527. }
  528. GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
  529. {
  530. _GLFWwindow* window = (_GLFWwindow*) handle;
  531. assert(window != NULL);
  532. _GLFW_REQUIRE_INIT();
  533. if (window->monitor)
  534. return;
  535. _glfwPlatformSetWindowPos(window, xpos, ypos);
  536. }
  537. GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
  538. {
  539. _GLFWwindow* window = (_GLFWwindow*) handle;
  540. assert(window != NULL);
  541. if (width)
  542. *width = 0;
  543. if (height)
  544. *height = 0;
  545. _GLFW_REQUIRE_INIT();
  546. _glfwPlatformGetWindowSize(window, width, height);
  547. }
  548. GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
  549. {
  550. _GLFWwindow* window = (_GLFWwindow*) handle;
  551. assert(window != NULL);
  552. assert(width >= 0);
  553. assert(height >= 0);
  554. _GLFW_REQUIRE_INIT();
  555. window->videoMode.width = width;
  556. window->videoMode.height = height;
  557. _glfwPlatformSetWindowSize(window, width, height);
  558. }
  559. GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle,
  560. int minwidth, int minheight,
  561. int maxwidth, int maxheight)
  562. {
  563. _GLFWwindow* window = (_GLFWwindow*) handle;
  564. assert(window != NULL);
  565. _GLFW_REQUIRE_INIT();
  566. if (minwidth != GLFW_DONT_CARE && minheight != GLFW_DONT_CARE)
  567. {
  568. if (minwidth < 0 || minheight < 0)
  569. {
  570. _glfwInputError(GLFW_INVALID_VALUE,
  571. "Invalid window minimum size %ix%i",
  572. minwidth, minheight);
  573. return;
  574. }
  575. }
  576. if (maxwidth != GLFW_DONT_CARE && maxheight != GLFW_DONT_CARE)
  577. {
  578. if (maxwidth < 0 || maxheight < 0 ||
  579. maxwidth < minwidth || maxheight < minheight)
  580. {
  581. _glfwInputError(GLFW_INVALID_VALUE,
  582. "Invalid window maximum size %ix%i",
  583. maxwidth, maxheight);
  584. return;
  585. }
  586. }
  587. window->minwidth = minwidth;
  588. window->minheight = minheight;
  589. window->maxwidth = maxwidth;
  590. window->maxheight = maxheight;
  591. if (window->monitor || !window->resizable)
  592. return;
  593. _glfwPlatformSetWindowSizeLimits(window,
  594. minwidth, minheight,
  595. maxwidth, maxheight);
  596. }
  597. GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom)
  598. {
  599. _GLFWwindow* window = (_GLFWwindow*) handle;
  600. assert(window != NULL);
  601. assert(numer != 0);
  602. assert(denom != 0);
  603. _GLFW_REQUIRE_INIT();
  604. if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE)
  605. {
  606. if (numer <= 0 || denom <= 0)
  607. {
  608. _glfwInputError(GLFW_INVALID_VALUE,
  609. "Invalid window aspect ratio %i:%i",
  610. numer, denom);
  611. return;
  612. }
  613. }
  614. window->numer = numer;
  615. window->denom = denom;
  616. if (window->monitor || !window->resizable)
  617. return;
  618. _glfwPlatformSetWindowAspectRatio(window, numer, denom);
  619. }
  620. GLFWAPI void glfwSetWindowSizeIncrements(GLFWwindow* handle, int widthincr, int heightincr)
  621. {
  622. _GLFWwindow* window = (_GLFWwindow*) handle;
  623. assert(window != NULL);
  624. assert(widthincr >= 0 || widthincr == GLFW_DONT_CARE);
  625. assert(heightincr >= 0 || heightincr == GLFW_DONT_CARE);
  626. _GLFW_REQUIRE_INIT();
  627. window->widthincr = widthincr;
  628. window->heightincr = heightincr;
  629. _glfwPlatformSetWindowSizeIncrements(window, window->widthincr, window->heightincr);
  630. }
  631. GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height)
  632. {
  633. _GLFWwindow* window = (_GLFWwindow*) handle;
  634. assert(window != NULL);
  635. if (width)
  636. *width = 0;
  637. if (height)
  638. *height = 0;
  639. _GLFW_REQUIRE_INIT();
  640. _glfwPlatformGetFramebufferSize(window, width, height);
  641. }
  642. GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
  643. int* left, int* top,
  644. int* right, int* bottom)
  645. {
  646. _GLFWwindow* window = (_GLFWwindow*) handle;
  647. assert(window != NULL);
  648. if (left)
  649. *left = 0;
  650. if (top)
  651. *top = 0;
  652. if (right)
  653. *right = 0;
  654. if (bottom)
  655. *bottom = 0;
  656. _GLFW_REQUIRE_INIT();
  657. _glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
  658. }
  659. GLFWAPI void glfwGetWindowContentScale(GLFWwindow* handle,
  660. float* xscale, float* yscale)
  661. {
  662. _GLFWwindow* window = (_GLFWwindow*) handle;
  663. assert(window != NULL);
  664. if (xscale)
  665. *xscale = 0.f;
  666. if (yscale)
  667. *yscale = 0.f;
  668. _GLFW_REQUIRE_INIT();
  669. _glfwPlatformGetWindowContentScale(window, xscale, yscale);
  670. }
  671. GLFWAPI monotonic_t glfwGetDoubleClickInterval(GLFWwindow* handle)
  672. {
  673. _GLFWwindow* window = (_GLFWwindow*) handle;
  674. assert(window != NULL);
  675. _GLFW_REQUIRE_INIT_OR_RETURN(ms_to_monotonic_t(500ll));
  676. return _glfwPlatformGetDoubleClickInterval(window);
  677. }
  678. GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle)
  679. {
  680. _GLFWwindow* window = (_GLFWwindow*) handle;
  681. assert(window != NULL);
  682. _GLFW_REQUIRE_INIT_OR_RETURN(1.f);
  683. return _glfwPlatformGetWindowOpacity(window);
  684. }
  685. GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity)
  686. {
  687. _GLFWwindow* window = (_GLFWwindow*) handle;
  688. assert(window != NULL);
  689. assert(opacity == opacity);
  690. assert(opacity >= 0.f);
  691. assert(opacity <= 1.f);
  692. _GLFW_REQUIRE_INIT();
  693. if (opacity != opacity || opacity < 0.f || opacity > 1.f)
  694. {
  695. _glfwInputError(GLFW_INVALID_VALUE, "Invalid window opacity %f", opacity);
  696. return;
  697. }
  698. _glfwPlatformSetWindowOpacity(window, opacity);
  699. }
  700. GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
  701. {
  702. _GLFWwindow* window = (_GLFWwindow*) handle;
  703. assert(window != NULL);
  704. _GLFW_REQUIRE_INIT();
  705. _glfwPlatformIconifyWindow(window);
  706. }
  707. GLFWAPI void glfwRestoreWindow(GLFWwindow* handle)
  708. {
  709. _GLFWwindow* window = (_GLFWwindow*) handle;
  710. assert(window != NULL);
  711. _GLFW_REQUIRE_INIT();
  712. _glfwPlatformRestoreWindow(window);
  713. }
  714. GLFWAPI void glfwMaximizeWindow(GLFWwindow* handle)
  715. {
  716. _GLFWwindow* window = (_GLFWwindow*) handle;
  717. assert(window != NULL);
  718. _GLFW_REQUIRE_INIT();
  719. if (window->monitor)
  720. return;
  721. _glfwPlatformMaximizeWindow(window);
  722. }
  723. GLFWAPI void glfwShowWindow(GLFWwindow* handle)
  724. {
  725. _GLFWwindow* window = (_GLFWwindow*) handle;
  726. assert(window != NULL);
  727. _GLFW_REQUIRE_INIT();
  728. if (window->monitor)
  729. return;
  730. _glfwPlatformShowWindow(window);
  731. #ifndef _GLFW_WAYLAND
  732. if (window->focusOnShow)
  733. _glfwPlatformFocusWindow(window);
  734. #endif
  735. }
  736. GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
  737. {
  738. _GLFWwindow* window = (_GLFWwindow*) handle;
  739. assert(window != NULL);
  740. _GLFW_REQUIRE_INIT();
  741. _glfwPlatformRequestWindowAttention(window);
  742. }
  743. GLFWAPI int glfwWindowBell(GLFWwindow* handle)
  744. {
  745. _GLFWwindow* window = (_GLFWwindow*) handle;
  746. assert(window != NULL);
  747. _GLFW_REQUIRE_INIT_OR_RETURN(false);
  748. return _glfwPlatformWindowBell(window);
  749. }
  750. GLFWAPI void glfwHideWindow(GLFWwindow* handle)
  751. {
  752. _GLFWwindow* window = (_GLFWwindow*) handle;
  753. assert(window != NULL);
  754. _GLFW_REQUIRE_INIT();
  755. if (window->monitor)
  756. return;
  757. _glfwPlatformHideWindow(window);
  758. }
  759. GLFWAPI void glfwFocusWindow(GLFWwindow* handle)
  760. {
  761. _GLFWwindow* window = (_GLFWwindow*) handle;
  762. assert(window != NULL);
  763. _GLFW_REQUIRE_INIT();
  764. _glfwPlatformFocusWindow(window);
  765. }
  766. GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
  767. {
  768. _GLFWwindow* window = (_GLFWwindow*) handle;
  769. assert(window != NULL);
  770. _GLFW_REQUIRE_INIT_OR_RETURN(0);
  771. switch (attrib)
  772. {
  773. case GLFW_FOCUSED:
  774. return _glfwPlatformWindowFocused(window);
  775. case GLFW_ICONIFIED:
  776. return _glfwPlatformWindowIconified(window);
  777. case GLFW_VISIBLE:
  778. return _glfwPlatformWindowVisible(window);
  779. case GLFW_MAXIMIZED:
  780. return _glfwPlatformWindowMaximized(window);
  781. case GLFW_HOVERED:
  782. return _glfwPlatformWindowHovered(window);
  783. case GLFW_FOCUS_ON_SHOW:
  784. return window->focusOnShow;
  785. case GLFW_MOUSE_PASSTHROUGH:
  786. return window->mousePassthrough;
  787. case GLFW_TRANSPARENT_FRAMEBUFFER:
  788. return _glfwPlatformFramebufferTransparent(window);
  789. case GLFW_OCCLUDED:
  790. return _glfwPlatformWindowOccluded(window);
  791. case GLFW_RESIZABLE:
  792. return window->resizable;
  793. case GLFW_DECORATED:
  794. return window->decorated;
  795. case GLFW_FLOATING:
  796. return window->floating;
  797. case GLFW_AUTO_ICONIFY:
  798. return window->autoIconify;
  799. case GLFW_CLIENT_API:
  800. return window->context.client;
  801. case GLFW_CONTEXT_CREATION_API:
  802. return window->context.source;
  803. case GLFW_CONTEXT_VERSION_MAJOR:
  804. return window->context.major;
  805. case GLFW_CONTEXT_VERSION_MINOR:
  806. return window->context.minor;
  807. case GLFW_CONTEXT_REVISION:
  808. return window->context.revision;
  809. case GLFW_CONTEXT_ROBUSTNESS:
  810. return window->context.robustness;
  811. case GLFW_OPENGL_FORWARD_COMPAT:
  812. return window->context.forward;
  813. case GLFW_CONTEXT_DEBUG:
  814. return window->context.debug;
  815. case GLFW_OPENGL_PROFILE:
  816. return window->context.profile;
  817. case GLFW_CONTEXT_RELEASE_BEHAVIOR:
  818. return window->context.release;
  819. case GLFW_CONTEXT_NO_ERROR:
  820. return window->context.noerror;
  821. }
  822. _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib);
  823. return 0;
  824. }
  825. GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value)
  826. {
  827. _GLFWwindow* window = (_GLFWwindow*) handle;
  828. assert(window != NULL);
  829. _GLFW_REQUIRE_INIT();
  830. value = value ? true : false;
  831. if (attrib == GLFW_AUTO_ICONIFY)
  832. window->autoIconify = value;
  833. else if (attrib == GLFW_RESIZABLE)
  834. {
  835. if (window->resizable == value)
  836. return;
  837. window->resizable = value;
  838. if (!window->monitor)
  839. _glfwPlatformSetWindowResizable(window, value);
  840. }
  841. else if (attrib == GLFW_DECORATED)
  842. {
  843. if (window->decorated == value)
  844. return;
  845. window->decorated = value;
  846. if (!window->monitor)
  847. _glfwPlatformSetWindowDecorated(window, value);
  848. }
  849. else if (attrib == GLFW_FLOATING)
  850. {
  851. if (window->floating == value)
  852. return;
  853. window->floating = value;
  854. if (!window->monitor)
  855. _glfwPlatformSetWindowFloating(window, value);
  856. }
  857. else if (attrib == GLFW_FOCUS_ON_SHOW)
  858. window->focusOnShow = value;
  859. else if (attrib == GLFW_MOUSE_PASSTHROUGH)
  860. {
  861. if (window->mousePassthrough == value)
  862. return;
  863. window->mousePassthrough = value;
  864. _glfwPlatformSetWindowMousePassthrough(window, value);
  865. }
  866. else
  867. _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib);
  868. }
  869. GLFWAPI int glfwSetWindowBlur(GLFWwindow* handle, int value)
  870. {
  871. _GLFWwindow* window = (_GLFWwindow*) handle;
  872. assert(window != NULL);
  873. _GLFW_REQUIRE_INIT_OR_RETURN(0);
  874. return _glfwPlatformSetWindowBlur(window, value);
  875. }
  876. GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle)
  877. {
  878. _GLFWwindow* window = (_GLFWwindow*) handle;
  879. assert(window != NULL);
  880. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  881. return (GLFWmonitor*) window->monitor;
  882. }
  883. GLFWAPI void glfwSetWindowMonitor(GLFWwindow* wh,
  884. GLFWmonitor* mh,
  885. int xpos, int ypos,
  886. int width, int height,
  887. int refreshRate)
  888. {
  889. _GLFWwindow* window = (_GLFWwindow*) wh;
  890. _GLFWmonitor* monitor = (_GLFWmonitor*) mh;
  891. assert(window != NULL);
  892. assert(width >= 0);
  893. assert(height >= 0);
  894. _GLFW_REQUIRE_INIT();
  895. if (width <= 0 || height <= 0)
  896. {
  897. _glfwInputError(GLFW_INVALID_VALUE,
  898. "Invalid window size %ix%i",
  899. width, height);
  900. return;
  901. }
  902. if (refreshRate < 0 && refreshRate != GLFW_DONT_CARE)
  903. {
  904. _glfwInputError(GLFW_INVALID_VALUE,
  905. "Invalid refresh rate %i",
  906. refreshRate);
  907. return;
  908. }
  909. window->videoMode.width = width;
  910. window->videoMode.height = height;
  911. window->videoMode.refreshRate = refreshRate;
  912. _glfwPlatformSetWindowMonitor(window, monitor,
  913. xpos, ypos, width, height,
  914. refreshRate);
  915. }
  916. GLFWAPI bool glfwToggleFullscreen(GLFWwindow* wh, unsigned int flags) {
  917. _GLFWwindow* window = (_GLFWwindow*) wh;
  918. if (window) return _glfwPlatformToggleFullscreen(window, flags);
  919. return false;
  920. }
  921. GLFWAPI bool glfwIsFullscreen(GLFWwindow* wh, unsigned int flags) {
  922. return _glfwPlatformIsFullscreen((_GLFWwindow*)wh, flags);
  923. }
  924. GLFWAPI bool glfwAreSwapsAllowed(const GLFWwindow* wh) {
  925. return !(((_GLFWwindow*)wh)->swaps_disallowed);
  926. }
  927. GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
  928. {
  929. _GLFWwindow* window = (_GLFWwindow*) handle;
  930. assert(window != NULL);
  931. _GLFW_REQUIRE_INIT();
  932. window->userPointer = pointer;
  933. }
  934. GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
  935. {
  936. _GLFWwindow* window = (_GLFWwindow*) handle;
  937. assert(window != NULL);
  938. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  939. return window->userPointer;
  940. }
  941. GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
  942. GLFWwindowposfun cbfun)
  943. {
  944. _GLFWwindow* window = (_GLFWwindow*) handle;
  945. assert(window != NULL);
  946. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  947. _GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
  948. return cbfun;
  949. }
  950. GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
  951. GLFWwindowsizefun cbfun)
  952. {
  953. _GLFWwindow* window = (_GLFWwindow*) handle;
  954. assert(window != NULL);
  955. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  956. _GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
  957. return cbfun;
  958. }
  959. GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
  960. GLFWwindowclosefun cbfun)
  961. {
  962. _GLFWwindow* window = (_GLFWwindow*) handle;
  963. assert(window != NULL);
  964. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  965. _GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
  966. return cbfun;
  967. }
  968. GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
  969. GLFWwindowrefreshfun cbfun)
  970. {
  971. _GLFWwindow* window = (_GLFWwindow*) handle;
  972. assert(window != NULL);
  973. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  974. _GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
  975. return cbfun;
  976. }
  977. GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
  978. GLFWwindowfocusfun cbfun)
  979. {
  980. _GLFWwindow* window = (_GLFWwindow*) handle;
  981. assert(window != NULL);
  982. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  983. _GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
  984. return cbfun;
  985. }
  986. GLFWAPI GLFWwindowocclusionfun glfwSetWindowOcclusionCallback(GLFWwindow* handle,
  987. GLFWwindowocclusionfun cbfun)
  988. {
  989. _GLFWwindow* window = (_GLFWwindow*) handle;
  990. assert(window != NULL);
  991. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  992. _GLFW_SWAP_POINTERS(window->callbacks.occlusion, cbfun);
  993. return cbfun;
  994. }
  995. GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
  996. GLFWwindowiconifyfun cbfun)
  997. {
  998. _GLFWwindow* window = (_GLFWwindow*) handle;
  999. assert(window != NULL);
  1000. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  1001. _GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
  1002. return cbfun;
  1003. }
  1004. GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* handle,
  1005. GLFWwindowmaximizefun cbfun)
  1006. {
  1007. _GLFWwindow* window = (_GLFWwindow*) handle;
  1008. assert(window != NULL);
  1009. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  1010. _GLFW_SWAP_POINTERS(window->callbacks.maximize, cbfun);
  1011. return cbfun;
  1012. }
  1013. GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
  1014. GLFWframebuffersizefun cbfun)
  1015. {
  1016. _GLFWwindow* window = (_GLFWwindow*) handle;
  1017. assert(window != NULL);
  1018. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  1019. _GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
  1020. return cbfun;
  1021. }
  1022. GLFWAPI GLFWliveresizefun glfwSetLiveResizeCallback(GLFWwindow* handle,
  1023. GLFWliveresizefun cbfun)
  1024. {
  1025. _GLFWwindow* window = (_GLFWwindow*) handle;
  1026. assert(window != NULL);
  1027. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  1028. _GLFW_SWAP_POINTERS(window->callbacks.liveResize, cbfun);
  1029. return cbfun;
  1030. }
  1031. GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle,
  1032. GLFWwindowcontentscalefun cbfun)
  1033. {
  1034. _GLFWwindow* window = (_GLFWwindow*) handle;
  1035. assert(window != NULL);
  1036. _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
  1037. _GLFW_SWAP_POINTERS(window->callbacks.scale, cbfun);
  1038. return cbfun;
  1039. }
  1040. GLFWAPI void glfwPostEmptyEvent(void)
  1041. {
  1042. _GLFW_REQUIRE_INIT();
  1043. _glfwPlatformPostEmptyEvent();
  1044. }