diff --git a/src/clipboard.c b/src/clipboard.c index f74041ae..acf9c818 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -40,26 +40,14 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformSetClipboardString(window, string); } GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return _glfwPlatformGetClipboardString(window); } diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 929dc27d..38bb9380 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -930,13 +930,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(nil); return window->ns.object; } diff --git a/src/context.c b/src/context.c index 8c392013..0966f39c 100644 --- a/src/context.c +++ b/src/context.c @@ -364,11 +364,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (_glfwPlatformGetCurrentContext() == window) return; @@ -378,35 +374,20 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) GLFWAPI GLFWwindow* glfwGetCurrentContext(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return (GLFWwindow*) _glfwPlatformGetCurrentContext(); } GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformSwapBuffers(window); } GLFWAPI void glfwSwapInterval(int interval) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (!_glfwPlatformGetCurrentContext()) { @@ -422,11 +403,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension) const GLubyte* extensions; _GLFWwindow* window; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return GL_FALSE; - } + _GLFW_REQUIRE_INIT_OR_RETURN(GL_FALSE); window = _glfwPlatformGetCurrentContext(); if (!window) @@ -479,11 +456,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension) GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (!_glfwPlatformGetCurrentContext()) { diff --git a/src/egl_context.c b/src/egl_context.c index 8a478ead..a5f15bd5 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -461,38 +461,21 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) GLFWAPI EGLDisplay glfwGetEGLDisplay(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return _glfw.egl.display; } GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->egl.context; } GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(0); return window->egl.surface; } diff --git a/src/gamma.c b/src/gamma.c index d70227f6..39a11821 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -42,11 +42,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) int i, size = GLFW_GAMMA_RAMP_SIZE; GLFWgammaramp ramp; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (gamma <= 0.f) { @@ -81,13 +77,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) GLFWAPI void glfwGetGammaRamp(GLFWmonitor* handle, GLFWgammaramp* ramp) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformGetGammaRamp(monitor, ramp); } @@ -95,11 +85,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (!monitor->rampChanged) { diff --git a/src/glx_context.c b/src/glx_context.c index 2355632d..a4e57c5b 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -594,13 +594,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->glx.context; } diff --git a/src/input.c b/src/input.c index 75dca2d8..0347c9c5 100644 --- a/src/input.c +++ b/src/input.c @@ -208,11 +208,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } + _GLFW_REQUIRE_INIT_OR_RETURN(0); switch (mode) { @@ -232,11 +228,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); switch (mode) { @@ -259,11 +251,7 @@ GLFWAPI int glfwGetKey(GLFWwindow* handle, int key) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return GLFW_RELEASE; - } + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); if (key < 0 || key > GLFW_KEY_LAST) { @@ -285,11 +273,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return GLFW_RELEASE; - } + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) { @@ -312,16 +296,12 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); - if (xpos != NULL) + if (xpos) *xpos = window->cursorPosX; - if (ypos != NULL) + if (ypos) *ypos = window->cursorPosY; } @@ -329,11 +309,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (_glfw.focusedWindow != window) return; @@ -357,78 +333,42 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos) GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.key = cbfun; } GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.character = cbfun; } GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.mouseButton = cbfun; } GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.cursorPos = cbfun; } GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.cursorEnter = cbfun; } GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.scroll = cbfun; } diff --git a/src/internal.h b/src/internal.h index 71c7c330..e45a90b1 100644 --- a/src/internal.h +++ b/src/internal.h @@ -109,6 +109,20 @@ typedef struct _GLFWmonitor _GLFWmonitor; // Internal key state used for sticky keys #define _GLFW_STICK 3 +// Checks for whether the library has been intitalized +#define _GLFW_REQUIRE_INIT() \ + if (!_glfwInitialized) \ + { \ + _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ + return; \ + } +#define _GLFW_REQUIRE_INIT_OR_RETURN(x) \ + if (!_glfwInitialized) \ + { \ + _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ + return x; \ + } + //======================================================================== // Internal types diff --git a/src/joystick.c b/src/joystick.c index 8f94b11c..b25719b6 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -37,11 +37,7 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } + _GLFW_REQUIRE_INIT_OR_RETURN(0); if (joy < 0 || joy > GLFW_JOYSTICK_LAST) { @@ -56,11 +52,7 @@ GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes) { int i; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } + _GLFW_REQUIRE_INIT_OR_RETURN(0); if (joy < 0 || joy > GLFW_JOYSTICK_LAST) { @@ -87,11 +79,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy, { int i; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } + _GLFW_REQUIRE_INIT_OR_RETURN(0); if (joy < 0 || joy > GLFW_JOYSTICK_LAST) { @@ -114,11 +102,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy, GLFWAPI const char* glfwGetJoystickName(int joy) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (joy < 0 || joy > GLFW_JOYSTICK_LAST) { diff --git a/src/monitor.c b/src/monitor.c index f7dcfe5f..0068ae9a 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -266,24 +266,14 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); *count = _glfw.monitorCount; return (GLFWmonitor**) _glfw.monitors; } GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return (GLFWmonitor*) _glfw.monitors[0]; } @@ -291,11 +281,7 @@ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (xpos) *xpos = monitor->positionX; @@ -307,11 +293,7 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (width) *width = monitor->widthMM; @@ -322,24 +304,13 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return monitor->name; } GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfw.monitorCallback = cbfun; } @@ -347,11 +318,7 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (!refreshVideoModes(monitor)) return GL_FALSE; @@ -365,11 +332,7 @@ GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* handle) _GLFWmonitor* monitor = (_GLFWmonitor*) handle; GLFWvidmode mode = { 0, 0, 0, 0, 0 }; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return mode; - } + _GLFW_REQUIRE_INIT_OR_RETURN(mode); _glfwPlatformGetVideoMode(monitor, &mode); return mode; diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 2539b464..d447929e 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -292,13 +292,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(nil); return window->nsgl.context; } diff --git a/src/time.c b/src/time.c index 9483441b..24adde41 100644 --- a/src/time.c +++ b/src/time.c @@ -37,23 +37,13 @@ GLFWAPI double glfwGetTime(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0.0; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(0.0); return _glfwPlatformGetTime(); } GLFWAPI void glfwSetTime(double time) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformSetTime(time); } diff --git a/src/wgl_context.c b/src/wgl_context.c index fb6b4c1d..3f0260f0 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -579,13 +579,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->wgl.context; } diff --git a/src/win32_window.c b/src/win32_window.c index 225abded..28132ff4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1090,13 +1090,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->win32.handle; } diff --git a/src/window.c b/src/window.c index b076b23a..3a6aa299 100644 --- a/src/window.c +++ b/src/window.c @@ -147,11 +147,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, _GLFWwindow* window; _GLFWwindow* previous; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (width <= 0 || height <= 0) { @@ -271,11 +267,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, void glfwDefaultWindowHints(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); memset(&_glfw.hints, 0, sizeof(_glfw.hints)); @@ -298,11 +290,7 @@ void glfwDefaultWindowHints(void) GLFWAPI void glfwWindowHint(int target, int hint) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); switch (target) { @@ -385,11 +373,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); // Allow closing of NULL (to match the behavior of free) if (window == NULL) @@ -425,26 +409,14 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformSetWindowTitle(window, title); } GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformGetWindowPos(window, xpos, ypos); } @@ -452,11 +424,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (window->monitor) { @@ -471,13 +439,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformGetWindowSize(window, width, height); } @@ -485,11 +447,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (window->iconified) { @@ -510,11 +468,7 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (window->iconified) return; @@ -526,11 +480,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (!window->iconified) return; @@ -542,11 +492,7 @@ GLFWAPI void glfwShowWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (window->monitor) return; @@ -558,11 +504,7 @@ GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } + _GLFW_REQUIRE_INIT(); if (window->monitor) return; @@ -574,11 +516,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow* handle, int param) { _GLFWwindow* window = (_GLFWwindow*) handle; - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } + _GLFW_REQUIRE_INIT_OR_RETURN(0); switch (param) { @@ -617,139 +555,75 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow* handle, int param) GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return (GLFWmonitor*) window->monitor; } GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->userPointer = pointer; } GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->userPointer; } GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.pos = cbfun; } GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.size = cbfun; } GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.close = cbfun; } GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.refresh = cbfun; } GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.focus = cbfun; } GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); window->callbacks.iconify = cbfun; } GLFWAPI void glfwPollEvents(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformPollEvents(); } GLFWAPI void glfwWaitEvents(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return; - } - + _GLFW_REQUIRE_INIT(); _glfwPlatformWaitEvents(); } diff --git a/src/x11_window.c b/src/x11_window.c index 3d14627a..43cd4be3 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1037,25 +1037,14 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) GLFWAPI Display* glfwGetX11Display(void) { - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return NULL; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return _glfw.x11.display; } GLFWAPI Window glfwGetX11Window(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwInputError(GLFW_NOT_INITIALIZED, NULL); - return 0; - } - + _GLFW_REQUIRE_INIT_OR_RETURN(None); return window->x11.handle; }