From dfd8a69cf23f7a09bb032c020225746d0a7ee1e8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Nov 2017 10:41:19 +0530 Subject: [PATCH] Build kitty against bundled glfw --- .gitattributes | 5 +- count-lines-of-code | 2 +- glfw/glfw.py | 114 ++- kitty/gl.h | 2 +- kitty/glfw-wrapper.c | 350 +++++++++ kitty/glfw-wrapper.h | 1786 ++++++++++++++++++++++++++++++++++++++++++ kitty/glfw.c | 41 +- kitty/keys.c | 2 +- kitty/main.py | 16 +- kitty/mouse.c | 2 +- setup.py | 9 +- 11 files changed, 2273 insertions(+), 56 deletions(-) create mode 100644 kitty/glfw-wrapper.c create mode 100644 kitty/glfw-wrapper.h diff --git a/.gitattributes b/.gitattributes index 7b76321d2..1b5a56bde 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,5 +5,6 @@ kitty/key_encoding.py linguist-generated=true kitty/rgb.py linguist-generated=true kitty/gl-wrapper.* linguist-generated=true kitty/khrplatform.h linguist-generated=true -glfw/*.c linguist-vendored -glfw/*.h linguist-vendored +kitty/glfw-wrapper.* linguist-generated=true +glfw/*.c linguist-vendored=true +glfw/*.h linguist-vendored=true diff --git a/count-lines-of-code b/count-lines-of-code index 00b8805fd..0d5c4b1a3 100755 --- a/count-lines-of-code +++ b/count-lines-of-code @@ -1,2 +1,2 @@ #!/bin/bash -cloc --exclude-list-file <(echo -e 'kitty/wcwidth9.h\nkitty/glfw.c\nkitty/keys.h\nkitty/charsets.c\nkitty/key_encoding.py\nkitty/rgb.py\nkitty/gl.h\nkitty/gl-wrapper.h\nkitty/gl-wrapper.c\nkitty/khrplatform.h') kitty +cloc --exclude-list-file <(echo -e 'kitty/wcwidth9.h\nkitty/glfw.c\nkitty/keys.h\nkitty/charsets.c\nkitty/key_encoding.py\nkitty/rgb.py\nkitty/gl.h\nkitty/gl-wrapper.h\nkitty/gl-wrapper.c\nkitty/khrplatform.h\nkitty/glfw-wrapper.h\nkitty/glfw-wrapper.c') kitty diff --git a/glfw/glfw.py b/glfw/glfw.py index 15f3594fc..0545fe5f2 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -15,7 +15,10 @@ def init_env(env, pkg_config, at_least_version, module='x11'): ans = env.copy() - ans.cflags = [x for x in ans.cflags if x not in '-Wpedantic -Wextra -pedantic-errors'.split()] + ans.cflags = [ + x for x in ans.cflags + if x not in '-Wpedantic -Wextra -pedantic-errors'.split() + ] ans.cflags.append('-pthread') ans.cflags.append('-fpic') ans.ldpaths.append('-pthread') @@ -75,6 +78,113 @@ def patch_in_file(path, pfunc): f.write(nraw) +class Arg: + + def __init__(self, decl): + self.type, self.name = decl.rsplit(' ', 1) + self.type = self.type.strip() + self.name = self.name.strip() + while self.name.startswith('*'): + self.name = self.name[1:] + self.type = self.type + '*' + + def __repr__(self): + return 'Arg({}, {})'.format(self.type, self.name) + + +class Function: + + def __init__(self, declaration): + m = re.match( + r'(.+?)\s+(glfw[A-Z][a-zA-Z0-9]+)[(](.+)[)]$', declaration + ) + if m is None: + raise SystemExit('Failed to parse ' + declaration) + self.restype = m.group(1).strip() + self.name = m.group(2) + args = m.group(3).strip().split(',') + args = [x.strip() for x in args] + self.args = [] + for a in args: + if a == 'void': + continue + self.args.append(Arg(a)) + + def declaration(self): + return 'typedef {restype} (*{name}_func)({args});\n{name}_func {name}_impl;\n#define {name} {name}_impl'.format( + restype=self.restype, + name=self.name, + args=', '.join(a.type for a in self.args) + ) + + def load(self): + ans = '*(void **) (&{name}_impl) = dlsym(handle, "{name}");'.format( + name=self.name + ) + ans += '\n if ({name}_impl == NULL) fail("Failed to load glfw function {name} with error: %s", dlerror());'.format( + name=self.name + ) + return ans + + +def generate_wrappers(glfw_header, glfw_native_header): + src = open(glfw_header).read() + functions = [] + first = None + for m in re.finditer(r'^GLFWAPI\s+(.+[)]);\s*$', src, flags=re.MULTILINE): + if first is None: + first = m.start() + decl = m.group(1) + if 'VkInstance' in decl: + continue + functions.append(Function(decl)) + declarations = [f.declaration() for f in functions] + p = src.find(' * GLFW API tokens') + p = src.find('*/', p) + preamble = src[p + 2:first] + header = '''\ +#pragma once +#include +#include +{} + +{} + +const char* load_glfw(const char* path); +'''.format(preamble, '\n\n'.join(declarations)) + with open('../kitty/glfw-wrapper.h', 'w') as f: + f.write(header) + + code = ''' +#include +#include "data-types.h" +#include "glfw-wrapper.h" + +static void* handle = NULL; + +#define fail(msg, ...) { snprintf(buf, sizeof(buf), msg, __VA_ARGS__); return buf; } + +const char* +load_glfw(const char* path) { + static char buf[2048]; + handle = dlopen(path, RTLD_LAZY); + if (handle == NULL) fail("Failed to dlopen %s with error: %s", path, dlerror()); + dlerror(); + + LOAD + + return NULL; +} + +void +unload_glfw() { + if (handle) { dlclose(handle); handle = NULL; } +} +'''.replace('LOAD', '\n\n '.join(f.load() for f in functions)) + with open('../kitty/glfw-wrapper.c', 'w') as f: + f.write(code) + + def main(): os.chdir(sys.argv[-1]) sinfo = collect_source_information() @@ -84,6 +194,7 @@ def main(): for name in headers + sources: files_to_copy.add(os.path.abspath(os.path.join('src', name))) glfw_header = os.path.abspath('include/GLFW/glfw3.h') + glfw_native_header = os.path.abspath('include/GLFW/glfw3native.h') os.chdir(base) for x in os.listdir('.'): if x.rpartition('.') in ('c', 'h'): @@ -99,6 +210,7 @@ def main(): ensure_ascii=False, sort_keys=True ) + generate_wrappers(glfw_header, glfw_native_header) if __name__ == '__main__': diff --git a/kitty/gl.h b/kitty/gl.h index 2fbc8bee8..aefdec151 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -11,7 +11,7 @@ #include "screen.h" #include #include -#include +#include "glfw-wrapper.h" static char glbuf[4096]; diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c new file mode 100644 index 000000000..a40d38c8e --- /dev/null +++ b/kitty/glfw-wrapper.c @@ -0,0 +1,350 @@ + +#include +#include "data-types.h" +#include "glfw-wrapper.h" + +static void* handle = NULL; + +#define fail(msg, ...) { snprintf(buf, sizeof(buf), msg, __VA_ARGS__); return buf; } + +const char* +load_glfw(const char* path) { + static char buf[2048]; + handle = dlopen(path, RTLD_LAZY); + if (handle == NULL) fail("Failed to dlopen %s with error: %s", path, dlerror()); + dlerror(); + + *(void **) (&glfwInit_impl) = dlsym(handle, "glfwInit"); + if (glfwInit_impl == NULL) fail("Failed to load glfw function glfwInit with error: %s", dlerror()); + + *(void **) (&glfwTerminate_impl) = dlsym(handle, "glfwTerminate"); + if (glfwTerminate_impl == NULL) fail("Failed to load glfw function glfwTerminate with error: %s", dlerror()); + + *(void **) (&glfwInitHint_impl) = dlsym(handle, "glfwInitHint"); + if (glfwInitHint_impl == NULL) fail("Failed to load glfw function glfwInitHint with error: %s", dlerror()); + + *(void **) (&glfwInitHintString_impl) = dlsym(handle, "glfwInitHintString"); + if (glfwInitHintString_impl == NULL) fail("Failed to load glfw function glfwInitHintString with error: %s", dlerror()); + + *(void **) (&glfwGetVersion_impl) = dlsym(handle, "glfwGetVersion"); + if (glfwGetVersion_impl == NULL) fail("Failed to load glfw function glfwGetVersion with error: %s", dlerror()); + + *(void **) (&glfwGetVersionString_impl) = dlsym(handle, "glfwGetVersionString"); + if (glfwGetVersionString_impl == NULL) fail("Failed to load glfw function glfwGetVersionString with error: %s", dlerror()); + + *(void **) (&glfwGetError_impl) = dlsym(handle, "glfwGetError"); + if (glfwGetError_impl == NULL) fail("Failed to load glfw function glfwGetError with error: %s", dlerror()); + + *(void **) (&glfwSetErrorCallback_impl) = dlsym(handle, "glfwSetErrorCallback"); + if (glfwSetErrorCallback_impl == NULL) fail("Failed to load glfw function glfwSetErrorCallback with error: %s", dlerror()); + + *(void **) (&glfwGetMonitors_impl) = dlsym(handle, "glfwGetMonitors"); + if (glfwGetMonitors_impl == NULL) fail("Failed to load glfw function glfwGetMonitors with error: %s", dlerror()); + + *(void **) (&glfwGetPrimaryMonitor_impl) = dlsym(handle, "glfwGetPrimaryMonitor"); + if (glfwGetPrimaryMonitor_impl == NULL) fail("Failed to load glfw function glfwGetPrimaryMonitor with error: %s", dlerror()); + + *(void **) (&glfwGetMonitorPos_impl) = dlsym(handle, "glfwGetMonitorPos"); + if (glfwGetMonitorPos_impl == NULL) fail("Failed to load glfw function glfwGetMonitorPos with error: %s", dlerror()); + + *(void **) (&glfwGetMonitorPhysicalSize_impl) = dlsym(handle, "glfwGetMonitorPhysicalSize"); + if (glfwGetMonitorPhysicalSize_impl == NULL) fail("Failed to load glfw function glfwGetMonitorPhysicalSize with error: %s", dlerror()); + + *(void **) (&glfwGetMonitorContentScale_impl) = dlsym(handle, "glfwGetMonitorContentScale"); + if (glfwGetMonitorContentScale_impl == NULL) fail("Failed to load glfw function glfwGetMonitorContentScale with error: %s", dlerror()); + + *(void **) (&glfwGetMonitorName_impl) = dlsym(handle, "glfwGetMonitorName"); + if (glfwGetMonitorName_impl == NULL) fail("Failed to load glfw function glfwGetMonitorName with error: %s", dlerror()); + + *(void **) (&glfwSetMonitorCallback_impl) = dlsym(handle, "glfwSetMonitorCallback"); + if (glfwSetMonitorCallback_impl == NULL) fail("Failed to load glfw function glfwSetMonitorCallback with error: %s", dlerror()); + + *(void **) (&glfwGetVideoModes_impl) = dlsym(handle, "glfwGetVideoModes"); + if (glfwGetVideoModes_impl == NULL) fail("Failed to load glfw function glfwGetVideoModes with error: %s", dlerror()); + + *(void **) (&glfwGetVideoMode_impl) = dlsym(handle, "glfwGetVideoMode"); + if (glfwGetVideoMode_impl == NULL) fail("Failed to load glfw function glfwGetVideoMode with error: %s", dlerror()); + + *(void **) (&glfwSetGamma_impl) = dlsym(handle, "glfwSetGamma"); + if (glfwSetGamma_impl == NULL) fail("Failed to load glfw function glfwSetGamma with error: %s", dlerror()); + + *(void **) (&glfwGetGammaRamp_impl) = dlsym(handle, "glfwGetGammaRamp"); + if (glfwGetGammaRamp_impl == NULL) fail("Failed to load glfw function glfwGetGammaRamp with error: %s", dlerror()); + + *(void **) (&glfwSetGammaRamp_impl) = dlsym(handle, "glfwSetGammaRamp"); + if (glfwSetGammaRamp_impl == NULL) fail("Failed to load glfw function glfwSetGammaRamp with error: %s", dlerror()); + + *(void **) (&glfwDefaultWindowHints_impl) = dlsym(handle, "glfwDefaultWindowHints"); + if (glfwDefaultWindowHints_impl == NULL) fail("Failed to load glfw function glfwDefaultWindowHints with error: %s", dlerror()); + + *(void **) (&glfwWindowHint_impl) = dlsym(handle, "glfwWindowHint"); + if (glfwWindowHint_impl == NULL) fail("Failed to load glfw function glfwWindowHint with error: %s", dlerror()); + + *(void **) (&glfwCreateWindow_impl) = dlsym(handle, "glfwCreateWindow"); + if (glfwCreateWindow_impl == NULL) fail("Failed to load glfw function glfwCreateWindow with error: %s", dlerror()); + + *(void **) (&glfwDestroyWindow_impl) = dlsym(handle, "glfwDestroyWindow"); + if (glfwDestroyWindow_impl == NULL) fail("Failed to load glfw function glfwDestroyWindow with error: %s", dlerror()); + + *(void **) (&glfwWindowShouldClose_impl) = dlsym(handle, "glfwWindowShouldClose"); + if (glfwWindowShouldClose_impl == NULL) fail("Failed to load glfw function glfwWindowShouldClose with error: %s", dlerror()); + + *(void **) (&glfwSetWindowShouldClose_impl) = dlsym(handle, "glfwSetWindowShouldClose"); + if (glfwSetWindowShouldClose_impl == NULL) fail("Failed to load glfw function glfwSetWindowShouldClose with error: %s", dlerror()); + + *(void **) (&glfwSetWindowTitle_impl) = dlsym(handle, "glfwSetWindowTitle"); + if (glfwSetWindowTitle_impl == NULL) fail("Failed to load glfw function glfwSetWindowTitle with error: %s", dlerror()); + + *(void **) (&glfwSetWindowIcon_impl) = dlsym(handle, "glfwSetWindowIcon"); + if (glfwSetWindowIcon_impl == NULL) fail("Failed to load glfw function glfwSetWindowIcon with error: %s", dlerror()); + + *(void **) (&glfwGetWindowPos_impl) = dlsym(handle, "glfwGetWindowPos"); + if (glfwGetWindowPos_impl == NULL) fail("Failed to load glfw function glfwGetWindowPos with error: %s", dlerror()); + + *(void **) (&glfwSetWindowPos_impl) = dlsym(handle, "glfwSetWindowPos"); + if (glfwSetWindowPos_impl == NULL) fail("Failed to load glfw function glfwSetWindowPos with error: %s", dlerror()); + + *(void **) (&glfwGetWindowSize_impl) = dlsym(handle, "glfwGetWindowSize"); + if (glfwGetWindowSize_impl == NULL) fail("Failed to load glfw function glfwGetWindowSize with error: %s", dlerror()); + + *(void **) (&glfwSetWindowSizeLimits_impl) = dlsym(handle, "glfwSetWindowSizeLimits"); + if (glfwSetWindowSizeLimits_impl == NULL) fail("Failed to load glfw function glfwSetWindowSizeLimits with error: %s", dlerror()); + + *(void **) (&glfwSetWindowAspectRatio_impl) = dlsym(handle, "glfwSetWindowAspectRatio"); + if (glfwSetWindowAspectRatio_impl == NULL) fail("Failed to load glfw function glfwSetWindowAspectRatio with error: %s", dlerror()); + + *(void **) (&glfwSetWindowSize_impl) = dlsym(handle, "glfwSetWindowSize"); + if (glfwSetWindowSize_impl == NULL) fail("Failed to load glfw function glfwSetWindowSize with error: %s", dlerror()); + + *(void **) (&glfwGetFramebufferSize_impl) = dlsym(handle, "glfwGetFramebufferSize"); + if (glfwGetFramebufferSize_impl == NULL) fail("Failed to load glfw function glfwGetFramebufferSize with error: %s", dlerror()); + + *(void **) (&glfwGetWindowFrameSize_impl) = dlsym(handle, "glfwGetWindowFrameSize"); + if (glfwGetWindowFrameSize_impl == NULL) fail("Failed to load glfw function glfwGetWindowFrameSize with error: %s", dlerror()); + + *(void **) (&glfwGetWindowContentScale_impl) = dlsym(handle, "glfwGetWindowContentScale"); + if (glfwGetWindowContentScale_impl == NULL) fail("Failed to load glfw function glfwGetWindowContentScale with error: %s", dlerror()); + + *(void **) (&glfwGetWindowOpacity_impl) = dlsym(handle, "glfwGetWindowOpacity"); + if (glfwGetWindowOpacity_impl == NULL) fail("Failed to load glfw function glfwGetWindowOpacity with error: %s", dlerror()); + + *(void **) (&glfwSetWindowOpacity_impl) = dlsym(handle, "glfwSetWindowOpacity"); + if (glfwSetWindowOpacity_impl == NULL) fail("Failed to load glfw function glfwSetWindowOpacity with error: %s", dlerror()); + + *(void **) (&glfwIconifyWindow_impl) = dlsym(handle, "glfwIconifyWindow"); + if (glfwIconifyWindow_impl == NULL) fail("Failed to load glfw function glfwIconifyWindow with error: %s", dlerror()); + + *(void **) (&glfwRestoreWindow_impl) = dlsym(handle, "glfwRestoreWindow"); + if (glfwRestoreWindow_impl == NULL) fail("Failed to load glfw function glfwRestoreWindow with error: %s", dlerror()); + + *(void **) (&glfwMaximizeWindow_impl) = dlsym(handle, "glfwMaximizeWindow"); + if (glfwMaximizeWindow_impl == NULL) fail("Failed to load glfw function glfwMaximizeWindow with error: %s", dlerror()); + + *(void **) (&glfwShowWindow_impl) = dlsym(handle, "glfwShowWindow"); + if (glfwShowWindow_impl == NULL) fail("Failed to load glfw function glfwShowWindow with error: %s", dlerror()); + + *(void **) (&glfwHideWindow_impl) = dlsym(handle, "glfwHideWindow"); + if (glfwHideWindow_impl == NULL) fail("Failed to load glfw function glfwHideWindow with error: %s", dlerror()); + + *(void **) (&glfwFocusWindow_impl) = dlsym(handle, "glfwFocusWindow"); + if (glfwFocusWindow_impl == NULL) fail("Failed to load glfw function glfwFocusWindow with error: %s", dlerror()); + + *(void **) (&glfwRequestWindowAttention_impl) = dlsym(handle, "glfwRequestWindowAttention"); + if (glfwRequestWindowAttention_impl == NULL) fail("Failed to load glfw function glfwRequestWindowAttention with error: %s", dlerror()); + + *(void **) (&glfwGetWindowMonitor_impl) = dlsym(handle, "glfwGetWindowMonitor"); + if (glfwGetWindowMonitor_impl == NULL) fail("Failed to load glfw function glfwGetWindowMonitor with error: %s", dlerror()); + + *(void **) (&glfwSetWindowMonitor_impl) = dlsym(handle, "glfwSetWindowMonitor"); + if (glfwSetWindowMonitor_impl == NULL) fail("Failed to load glfw function glfwSetWindowMonitor with error: %s", dlerror()); + + *(void **) (&glfwGetWindowAttrib_impl) = dlsym(handle, "glfwGetWindowAttrib"); + if (glfwGetWindowAttrib_impl == NULL) fail("Failed to load glfw function glfwGetWindowAttrib with error: %s", dlerror()); + + *(void **) (&glfwSetWindowAttrib_impl) = dlsym(handle, "glfwSetWindowAttrib"); + if (glfwSetWindowAttrib_impl == NULL) fail("Failed to load glfw function glfwSetWindowAttrib with error: %s", dlerror()); + + *(void **) (&glfwSetWindowUserPointer_impl) = dlsym(handle, "glfwSetWindowUserPointer"); + if (glfwSetWindowUserPointer_impl == NULL) fail("Failed to load glfw function glfwSetWindowUserPointer with error: %s", dlerror()); + + *(void **) (&glfwGetWindowUserPointer_impl) = dlsym(handle, "glfwGetWindowUserPointer"); + if (glfwGetWindowUserPointer_impl == NULL) fail("Failed to load glfw function glfwGetWindowUserPointer with error: %s", dlerror()); + + *(void **) (&glfwSetWindowPosCallback_impl) = dlsym(handle, "glfwSetWindowPosCallback"); + if (glfwSetWindowPosCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowPosCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowSizeCallback_impl) = dlsym(handle, "glfwSetWindowSizeCallback"); + if (glfwSetWindowSizeCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowSizeCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowCloseCallback_impl) = dlsym(handle, "glfwSetWindowCloseCallback"); + if (glfwSetWindowCloseCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowCloseCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowRefreshCallback_impl) = dlsym(handle, "glfwSetWindowRefreshCallback"); + if (glfwSetWindowRefreshCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowRefreshCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowFocusCallback_impl) = dlsym(handle, "glfwSetWindowFocusCallback"); + if (glfwSetWindowFocusCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowFocusCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowIconifyCallback_impl) = dlsym(handle, "glfwSetWindowIconifyCallback"); + if (glfwSetWindowIconifyCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowIconifyCallback with error: %s", dlerror()); + + *(void **) (&glfwSetWindowMaximizeCallback_impl) = dlsym(handle, "glfwSetWindowMaximizeCallback"); + if (glfwSetWindowMaximizeCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowMaximizeCallback with error: %s", dlerror()); + + *(void **) (&glfwSetFramebufferSizeCallback_impl) = dlsym(handle, "glfwSetFramebufferSizeCallback"); + if (glfwSetFramebufferSizeCallback_impl == NULL) fail("Failed to load glfw function glfwSetFramebufferSizeCallback with error: %s", dlerror()); + + *(void **) (&glfwPollEvents_impl) = dlsym(handle, "glfwPollEvents"); + if (glfwPollEvents_impl == NULL) fail("Failed to load glfw function glfwPollEvents with error: %s", dlerror()); + + *(void **) (&glfwWaitEvents_impl) = dlsym(handle, "glfwWaitEvents"); + if (glfwWaitEvents_impl == NULL) fail("Failed to load glfw function glfwWaitEvents with error: %s", dlerror()); + + *(void **) (&glfwWaitEventsTimeout_impl) = dlsym(handle, "glfwWaitEventsTimeout"); + if (glfwWaitEventsTimeout_impl == NULL) fail("Failed to load glfw function glfwWaitEventsTimeout with error: %s", dlerror()); + + *(void **) (&glfwPostEmptyEvent_impl) = dlsym(handle, "glfwPostEmptyEvent"); + if (glfwPostEmptyEvent_impl == NULL) fail("Failed to load glfw function glfwPostEmptyEvent with error: %s", dlerror()); + + *(void **) (&glfwGetInputMode_impl) = dlsym(handle, "glfwGetInputMode"); + if (glfwGetInputMode_impl == NULL) fail("Failed to load glfw function glfwGetInputMode with error: %s", dlerror()); + + *(void **) (&glfwSetInputMode_impl) = dlsym(handle, "glfwSetInputMode"); + if (glfwSetInputMode_impl == NULL) fail("Failed to load glfw function glfwSetInputMode with error: %s", dlerror()); + + *(void **) (&glfwGetKeyName_impl) = dlsym(handle, "glfwGetKeyName"); + if (glfwGetKeyName_impl == NULL) fail("Failed to load glfw function glfwGetKeyName with error: %s", dlerror()); + + *(void **) (&glfwGetKeyScancode_impl) = dlsym(handle, "glfwGetKeyScancode"); + if (glfwGetKeyScancode_impl == NULL) fail("Failed to load glfw function glfwGetKeyScancode with error: %s", dlerror()); + + *(void **) (&glfwGetKey_impl) = dlsym(handle, "glfwGetKey"); + if (glfwGetKey_impl == NULL) fail("Failed to load glfw function glfwGetKey with error: %s", dlerror()); + + *(void **) (&glfwGetMouseButton_impl) = dlsym(handle, "glfwGetMouseButton"); + if (glfwGetMouseButton_impl == NULL) fail("Failed to load glfw function glfwGetMouseButton with error: %s", dlerror()); + + *(void **) (&glfwGetCursorPos_impl) = dlsym(handle, "glfwGetCursorPos"); + if (glfwGetCursorPos_impl == NULL) fail("Failed to load glfw function glfwGetCursorPos with error: %s", dlerror()); + + *(void **) (&glfwSetCursorPos_impl) = dlsym(handle, "glfwSetCursorPos"); + if (glfwSetCursorPos_impl == NULL) fail("Failed to load glfw function glfwSetCursorPos with error: %s", dlerror()); + + *(void **) (&glfwCreateCursor_impl) = dlsym(handle, "glfwCreateCursor"); + if (glfwCreateCursor_impl == NULL) fail("Failed to load glfw function glfwCreateCursor with error: %s", dlerror()); + + *(void **) (&glfwCreateStandardCursor_impl) = dlsym(handle, "glfwCreateStandardCursor"); + if (glfwCreateStandardCursor_impl == NULL) fail("Failed to load glfw function glfwCreateStandardCursor with error: %s", dlerror()); + + *(void **) (&glfwDestroyCursor_impl) = dlsym(handle, "glfwDestroyCursor"); + if (glfwDestroyCursor_impl == NULL) fail("Failed to load glfw function glfwDestroyCursor with error: %s", dlerror()); + + *(void **) (&glfwSetCursor_impl) = dlsym(handle, "glfwSetCursor"); + if (glfwSetCursor_impl == NULL) fail("Failed to load glfw function glfwSetCursor with error: %s", dlerror()); + + *(void **) (&glfwSetKeyCallback_impl) = dlsym(handle, "glfwSetKeyCallback"); + if (glfwSetKeyCallback_impl == NULL) fail("Failed to load glfw function glfwSetKeyCallback with error: %s", dlerror()); + + *(void **) (&glfwSetCharCallback_impl) = dlsym(handle, "glfwSetCharCallback"); + if (glfwSetCharCallback_impl == NULL) fail("Failed to load glfw function glfwSetCharCallback with error: %s", dlerror()); + + *(void **) (&glfwSetCharModsCallback_impl) = dlsym(handle, "glfwSetCharModsCallback"); + if (glfwSetCharModsCallback_impl == NULL) fail("Failed to load glfw function glfwSetCharModsCallback with error: %s", dlerror()); + + *(void **) (&glfwSetMouseButtonCallback_impl) = dlsym(handle, "glfwSetMouseButtonCallback"); + if (glfwSetMouseButtonCallback_impl == NULL) fail("Failed to load glfw function glfwSetMouseButtonCallback with error: %s", dlerror()); + + *(void **) (&glfwSetCursorPosCallback_impl) = dlsym(handle, "glfwSetCursorPosCallback"); + if (glfwSetCursorPosCallback_impl == NULL) fail("Failed to load glfw function glfwSetCursorPosCallback with error: %s", dlerror()); + + *(void **) (&glfwSetCursorEnterCallback_impl) = dlsym(handle, "glfwSetCursorEnterCallback"); + if (glfwSetCursorEnterCallback_impl == NULL) fail("Failed to load glfw function glfwSetCursorEnterCallback with error: %s", dlerror()); + + *(void **) (&glfwSetScrollCallback_impl) = dlsym(handle, "glfwSetScrollCallback"); + if (glfwSetScrollCallback_impl == NULL) fail("Failed to load glfw function glfwSetScrollCallback with error: %s", dlerror()); + + *(void **) (&glfwSetDropCallback_impl) = dlsym(handle, "glfwSetDropCallback"); + if (glfwSetDropCallback_impl == NULL) fail("Failed to load glfw function glfwSetDropCallback with error: %s", dlerror()); + + *(void **) (&glfwJoystickPresent_impl) = dlsym(handle, "glfwJoystickPresent"); + if (glfwJoystickPresent_impl == NULL) fail("Failed to load glfw function glfwJoystickPresent with error: %s", dlerror()); + + *(void **) (&glfwGetJoystickAxes_impl) = dlsym(handle, "glfwGetJoystickAxes"); + if (glfwGetJoystickAxes_impl == NULL) fail("Failed to load glfw function glfwGetJoystickAxes with error: %s", dlerror()); + + *(void **) (&glfwGetJoystickButtons_impl) = dlsym(handle, "glfwGetJoystickButtons"); + if (glfwGetJoystickButtons_impl == NULL) fail("Failed to load glfw function glfwGetJoystickButtons with error: %s", dlerror()); + + *(void **) (&glfwGetJoystickHats_impl) = dlsym(handle, "glfwGetJoystickHats"); + if (glfwGetJoystickHats_impl == NULL) fail("Failed to load glfw function glfwGetJoystickHats with error: %s", dlerror()); + + *(void **) (&glfwGetJoystickName_impl) = dlsym(handle, "glfwGetJoystickName"); + if (glfwGetJoystickName_impl == NULL) fail("Failed to load glfw function glfwGetJoystickName with error: %s", dlerror()); + + *(void **) (&glfwGetJoystickGUID_impl) = dlsym(handle, "glfwGetJoystickGUID"); + if (glfwGetJoystickGUID_impl == NULL) fail("Failed to load glfw function glfwGetJoystickGUID with error: %s", dlerror()); + + *(void **) (&glfwJoystickIsGamepad_impl) = dlsym(handle, "glfwJoystickIsGamepad"); + if (glfwJoystickIsGamepad_impl == NULL) fail("Failed to load glfw function glfwJoystickIsGamepad with error: %s", dlerror()); + + *(void **) (&glfwSetJoystickCallback_impl) = dlsym(handle, "glfwSetJoystickCallback"); + if (glfwSetJoystickCallback_impl == NULL) fail("Failed to load glfw function glfwSetJoystickCallback with error: %s", dlerror()); + + *(void **) (&glfwUpdateGamepadMappings_impl) = dlsym(handle, "glfwUpdateGamepadMappings"); + if (glfwUpdateGamepadMappings_impl == NULL) fail("Failed to load glfw function glfwUpdateGamepadMappings with error: %s", dlerror()); + + *(void **) (&glfwGetGamepadName_impl) = dlsym(handle, "glfwGetGamepadName"); + if (glfwGetGamepadName_impl == NULL) fail("Failed to load glfw function glfwGetGamepadName with error: %s", dlerror()); + + *(void **) (&glfwGetGamepadState_impl) = dlsym(handle, "glfwGetGamepadState"); + if (glfwGetGamepadState_impl == NULL) fail("Failed to load glfw function glfwGetGamepadState with error: %s", dlerror()); + + *(void **) (&glfwSetClipboardString_impl) = dlsym(handle, "glfwSetClipboardString"); + if (glfwSetClipboardString_impl == NULL) fail("Failed to load glfw function glfwSetClipboardString with error: %s", dlerror()); + + *(void **) (&glfwGetClipboardString_impl) = dlsym(handle, "glfwGetClipboardString"); + if (glfwGetClipboardString_impl == NULL) fail("Failed to load glfw function glfwGetClipboardString with error: %s", dlerror()); + + *(void **) (&glfwGetTime_impl) = dlsym(handle, "glfwGetTime"); + if (glfwGetTime_impl == NULL) fail("Failed to load glfw function glfwGetTime with error: %s", dlerror()); + + *(void **) (&glfwSetTime_impl) = dlsym(handle, "glfwSetTime"); + if (glfwSetTime_impl == NULL) fail("Failed to load glfw function glfwSetTime with error: %s", dlerror()); + + *(void **) (&glfwGetTimerValue_impl) = dlsym(handle, "glfwGetTimerValue"); + if (glfwGetTimerValue_impl == NULL) fail("Failed to load glfw function glfwGetTimerValue with error: %s", dlerror()); + + *(void **) (&glfwGetTimerFrequency_impl) = dlsym(handle, "glfwGetTimerFrequency"); + if (glfwGetTimerFrequency_impl == NULL) fail("Failed to load glfw function glfwGetTimerFrequency with error: %s", dlerror()); + + *(void **) (&glfwMakeContextCurrent_impl) = dlsym(handle, "glfwMakeContextCurrent"); + if (glfwMakeContextCurrent_impl == NULL) fail("Failed to load glfw function glfwMakeContextCurrent with error: %s", dlerror()); + + *(void **) (&glfwGetCurrentContext_impl) = dlsym(handle, "glfwGetCurrentContext"); + if (glfwGetCurrentContext_impl == NULL) fail("Failed to load glfw function glfwGetCurrentContext with error: %s", dlerror()); + + *(void **) (&glfwSwapBuffers_impl) = dlsym(handle, "glfwSwapBuffers"); + if (glfwSwapBuffers_impl == NULL) fail("Failed to load glfw function glfwSwapBuffers with error: %s", dlerror()); + + *(void **) (&glfwSwapInterval_impl) = dlsym(handle, "glfwSwapInterval"); + if (glfwSwapInterval_impl == NULL) fail("Failed to load glfw function glfwSwapInterval with error: %s", dlerror()); + + *(void **) (&glfwExtensionSupported_impl) = dlsym(handle, "glfwExtensionSupported"); + if (glfwExtensionSupported_impl == NULL) fail("Failed to load glfw function glfwExtensionSupported with error: %s", dlerror()); + + *(void **) (&glfwGetProcAddress_impl) = dlsym(handle, "glfwGetProcAddress"); + if (glfwGetProcAddress_impl == NULL) fail("Failed to load glfw function glfwGetProcAddress with error: %s", dlerror()); + + *(void **) (&glfwVulkanSupported_impl) = dlsym(handle, "glfwVulkanSupported"); + if (glfwVulkanSupported_impl == NULL) fail("Failed to load glfw function glfwVulkanSupported with error: %s", dlerror()); + + *(void **) (&glfwGetRequiredInstanceExtensions_impl) = dlsym(handle, "glfwGetRequiredInstanceExtensions"); + if (glfwGetRequiredInstanceExtensions_impl == NULL) fail("Failed to load glfw function glfwGetRequiredInstanceExtensions with error: %s", dlerror()); + + return NULL; +} + +void +unload_glfw() { + if (handle) { dlclose(handle); handle = NULL; } +} diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h new file mode 100644 index 000000000..9cb4d61a1 --- /dev/null +++ b/kitty/glfw-wrapper.h @@ -0,0 +1,1786 @@ +#pragma once +#include +#include + + +/*! @name GLFW version macros + * @{ */ +/*! @brief The major version number of the GLFW library. + * + * This is incremented when the API is changed in non-compatible ways. + * @ingroup init + */ +#define GLFW_VERSION_MAJOR 3 +/*! @brief The minor version number of the GLFW library. + * + * This is incremented when features are added to the API but it remains + * backward-compatible. + * @ingroup init + */ +#define GLFW_VERSION_MINOR 3 +/*! @brief The revision number of the GLFW library. + * + * This is incremented when a bug fix release is made that does not contain any + * API changes. + * @ingroup init + */ +#define GLFW_VERSION_REVISION 0 +/*! @} */ + +/*! @name Boolean values + * @{ */ +/*! @brief One. + * + * One. Seriously. You don't _need_ to use this symbol in your code. It's + * semantic sugar for the number 1. You can also use `1` or `true` or `_True` + * or `GL_TRUE` or whatever you want. + */ +#define GLFW_TRUE 1 +/*! @brief Zero. + * + * Zero. Seriously. You don't _need_ to use this symbol in your code. It's + * semantic sugar for the number 0. You can also use `0` or `false` or + * `_False` or `GL_FALSE` or whatever you want. + */ +#define GLFW_FALSE 0 +/*! @} */ + +/*! @name Key and button actions + * @{ */ +/*! @brief The key or mouse button was released. + * + * The key or mouse button was released. + * + * @ingroup input + */ +#define GLFW_RELEASE 0 +/*! @brief The key or mouse button was pressed. + * + * The key or mouse button was pressed. + * + * @ingroup input + */ +#define GLFW_PRESS 1 +/*! @brief The key was held down until it repeated. + * + * The key was held down until it repeated. + * + * @ingroup input + */ +#define GLFW_REPEAT 2 +/*! @} */ + +/*! @defgroup hat_state Joystick hat states + * + * See [joystick hat input](@ref joystick_hat) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_HAT_CENTERED 0 +#define GLFW_HAT_UP 1 +#define GLFW_HAT_RIGHT 2 +#define GLFW_HAT_DOWN 4 +#define GLFW_HAT_LEFT 8 +#define GLFW_HAT_RIGHT_UP (GLFW_HAT_RIGHT | GLFW_HAT_UP) +#define GLFW_HAT_RIGHT_DOWN (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) +#define GLFW_HAT_LEFT_UP (GLFW_HAT_LEFT | GLFW_HAT_UP) +#define GLFW_HAT_LEFT_DOWN (GLFW_HAT_LEFT | GLFW_HAT_DOWN) +/*! @} */ + +/*! @defgroup keys Keyboard keys + * @brief Keyboard key IDs. + * + * See [key input](@ref input_key) for how these are used. + * + * These key codes are inspired by the _USB HID Usage Tables v1.12_ (p. 53-60), + * but re-arranged to map to 7-bit ASCII for printable keys (function keys are + * put in the 256+ range). + * + * The naming of the key codes follow these rules: + * - The US keyboard layout is used + * - Names of printable alpha-numeric characters are used (e.g. "A", "R", + * "3", etc.) + * - For non-alphanumeric characters, Unicode:ish names are used (e.g. + * "COMMA", "LEFT_SQUARE_BRACKET", etc.). Note that some names do not + * correspond to the Unicode standard (usually for brevity) + * - Keys that lack a clear US mapping are named "WORLD_x" + * - For non-printable keys, custom names are used (e.g. "F4", + * "BACKSPACE", etc.) + * + * @ingroup input + * @{ + */ + +/* The unknown key */ +#define GLFW_KEY_UNKNOWN -1 + +/* Printable keys */ +#define GLFW_KEY_SPACE 32 +#define GLFW_KEY_APOSTROPHE 39 /* ' */ +#define GLFW_KEY_COMMA 44 /* , */ +#define GLFW_KEY_MINUS 45 /* - */ +#define GLFW_KEY_PERIOD 46 /* . */ +#define GLFW_KEY_SLASH 47 /* / */ +#define GLFW_KEY_0 48 +#define GLFW_KEY_1 49 +#define GLFW_KEY_2 50 +#define GLFW_KEY_3 51 +#define GLFW_KEY_4 52 +#define GLFW_KEY_5 53 +#define GLFW_KEY_6 54 +#define GLFW_KEY_7 55 +#define GLFW_KEY_8 56 +#define GLFW_KEY_9 57 +#define GLFW_KEY_SEMICOLON 59 /* ; */ +#define GLFW_KEY_EQUAL 61 /* = */ +#define GLFW_KEY_A 65 +#define GLFW_KEY_B 66 +#define GLFW_KEY_C 67 +#define GLFW_KEY_D 68 +#define GLFW_KEY_E 69 +#define GLFW_KEY_F 70 +#define GLFW_KEY_G 71 +#define GLFW_KEY_H 72 +#define GLFW_KEY_I 73 +#define GLFW_KEY_J 74 +#define GLFW_KEY_K 75 +#define GLFW_KEY_L 76 +#define GLFW_KEY_M 77 +#define GLFW_KEY_N 78 +#define GLFW_KEY_O 79 +#define GLFW_KEY_P 80 +#define GLFW_KEY_Q 81 +#define GLFW_KEY_R 82 +#define GLFW_KEY_S 83 +#define GLFW_KEY_T 84 +#define GLFW_KEY_U 85 +#define GLFW_KEY_V 86 +#define GLFW_KEY_W 87 +#define GLFW_KEY_X 88 +#define GLFW_KEY_Y 89 +#define GLFW_KEY_Z 90 +#define GLFW_KEY_LEFT_BRACKET 91 /* [ */ +#define GLFW_KEY_BACKSLASH 92 /* \ */ +#define GLFW_KEY_RIGHT_BRACKET 93 /* ] */ +#define GLFW_KEY_GRAVE_ACCENT 96 /* ` */ +#define GLFW_KEY_WORLD_1 161 /* non-US #1 */ +#define GLFW_KEY_WORLD_2 162 /* non-US #2 */ + +/* Function keys */ +#define GLFW_KEY_ESCAPE 256 +#define GLFW_KEY_ENTER 257 +#define GLFW_KEY_TAB 258 +#define GLFW_KEY_BACKSPACE 259 +#define GLFW_KEY_INSERT 260 +#define GLFW_KEY_DELETE 261 +#define GLFW_KEY_RIGHT 262 +#define GLFW_KEY_LEFT 263 +#define GLFW_KEY_DOWN 264 +#define GLFW_KEY_UP 265 +#define GLFW_KEY_PAGE_UP 266 +#define GLFW_KEY_PAGE_DOWN 267 +#define GLFW_KEY_HOME 268 +#define GLFW_KEY_END 269 +#define GLFW_KEY_CAPS_LOCK 280 +#define GLFW_KEY_SCROLL_LOCK 281 +#define GLFW_KEY_NUM_LOCK 282 +#define GLFW_KEY_PRINT_SCREEN 283 +#define GLFW_KEY_PAUSE 284 +#define GLFW_KEY_F1 290 +#define GLFW_KEY_F2 291 +#define GLFW_KEY_F3 292 +#define GLFW_KEY_F4 293 +#define GLFW_KEY_F5 294 +#define GLFW_KEY_F6 295 +#define GLFW_KEY_F7 296 +#define GLFW_KEY_F8 297 +#define GLFW_KEY_F9 298 +#define GLFW_KEY_F10 299 +#define GLFW_KEY_F11 300 +#define GLFW_KEY_F12 301 +#define GLFW_KEY_F13 302 +#define GLFW_KEY_F14 303 +#define GLFW_KEY_F15 304 +#define GLFW_KEY_F16 305 +#define GLFW_KEY_F17 306 +#define GLFW_KEY_F18 307 +#define GLFW_KEY_F19 308 +#define GLFW_KEY_F20 309 +#define GLFW_KEY_F21 310 +#define GLFW_KEY_F22 311 +#define GLFW_KEY_F23 312 +#define GLFW_KEY_F24 313 +#define GLFW_KEY_F25 314 +#define GLFW_KEY_KP_0 320 +#define GLFW_KEY_KP_1 321 +#define GLFW_KEY_KP_2 322 +#define GLFW_KEY_KP_3 323 +#define GLFW_KEY_KP_4 324 +#define GLFW_KEY_KP_5 325 +#define GLFW_KEY_KP_6 326 +#define GLFW_KEY_KP_7 327 +#define GLFW_KEY_KP_8 328 +#define GLFW_KEY_KP_9 329 +#define GLFW_KEY_KP_DECIMAL 330 +#define GLFW_KEY_KP_DIVIDE 331 +#define GLFW_KEY_KP_MULTIPLY 332 +#define GLFW_KEY_KP_SUBTRACT 333 +#define GLFW_KEY_KP_ADD 334 +#define GLFW_KEY_KP_ENTER 335 +#define GLFW_KEY_KP_EQUAL 336 +#define GLFW_KEY_LEFT_SHIFT 340 +#define GLFW_KEY_LEFT_CONTROL 341 +#define GLFW_KEY_LEFT_ALT 342 +#define GLFW_KEY_LEFT_SUPER 343 +#define GLFW_KEY_RIGHT_SHIFT 344 +#define GLFW_KEY_RIGHT_CONTROL 345 +#define GLFW_KEY_RIGHT_ALT 346 +#define GLFW_KEY_RIGHT_SUPER 347 +#define GLFW_KEY_MENU 348 + +#define GLFW_KEY_LAST GLFW_KEY_MENU + +/*! @} */ + +/*! @defgroup mods Modifier key flags + * @brief Modifier key flags. + * + * See [key input](@ref input_key) for how these are used. + * + * @ingroup input + * @{ */ + +/*! @brief If this bit is set one or more Shift keys were held down. + */ +#define GLFW_MOD_SHIFT 0x0001 +/*! @brief If this bit is set one or more Control keys were held down. + */ +#define GLFW_MOD_CONTROL 0x0002 +/*! @brief If this bit is set one or more Alt keys were held down. + */ +#define GLFW_MOD_ALT 0x0004 +/*! @brief If this bit is set one or more Super keys were held down. + */ +#define GLFW_MOD_SUPER 0x0008 + +/*! @} */ + +/*! @defgroup buttons Mouse buttons + * @brief Mouse button IDs. + * + * See [mouse button input](@ref input_mouse_button) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_MOUSE_BUTTON_1 0 +#define GLFW_MOUSE_BUTTON_2 1 +#define GLFW_MOUSE_BUTTON_3 2 +#define GLFW_MOUSE_BUTTON_4 3 +#define GLFW_MOUSE_BUTTON_5 4 +#define GLFW_MOUSE_BUTTON_6 5 +#define GLFW_MOUSE_BUTTON_7 6 +#define GLFW_MOUSE_BUTTON_8 7 +#define GLFW_MOUSE_BUTTON_LAST GLFW_MOUSE_BUTTON_8 +#define GLFW_MOUSE_BUTTON_LEFT GLFW_MOUSE_BUTTON_1 +#define GLFW_MOUSE_BUTTON_RIGHT GLFW_MOUSE_BUTTON_2 +#define GLFW_MOUSE_BUTTON_MIDDLE GLFW_MOUSE_BUTTON_3 +/*! @} */ + +/*! @defgroup joysticks Joysticks + * @brief Joystick IDs. + * + * See [joystick input](@ref joystick) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_JOYSTICK_1 0 +#define GLFW_JOYSTICK_2 1 +#define GLFW_JOYSTICK_3 2 +#define GLFW_JOYSTICK_4 3 +#define GLFW_JOYSTICK_5 4 +#define GLFW_JOYSTICK_6 5 +#define GLFW_JOYSTICK_7 6 +#define GLFW_JOYSTICK_8 7 +#define GLFW_JOYSTICK_9 8 +#define GLFW_JOYSTICK_10 9 +#define GLFW_JOYSTICK_11 10 +#define GLFW_JOYSTICK_12 11 +#define GLFW_JOYSTICK_13 12 +#define GLFW_JOYSTICK_14 13 +#define GLFW_JOYSTICK_15 14 +#define GLFW_JOYSTICK_16 15 +#define GLFW_JOYSTICK_LAST GLFW_JOYSTICK_16 +/*! @} */ + +/*! @defgroup gamepad_buttons Gamepad buttons + * @brief Gamepad buttons. + * + * See @ref gamepad for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_GAMEPAD_BUTTON_A 0 +#define GLFW_GAMEPAD_BUTTON_B 1 +#define GLFW_GAMEPAD_BUTTON_X 2 +#define GLFW_GAMEPAD_BUTTON_Y 3 +#define GLFW_GAMEPAD_BUTTON_LEFT_BUMPER 4 +#define GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER 5 +#define GLFW_GAMEPAD_BUTTON_BACK 6 +#define GLFW_GAMEPAD_BUTTON_START 7 +#define GLFW_GAMEPAD_BUTTON_GUIDE 8 +#define GLFW_GAMEPAD_BUTTON_LEFT_THUMB 9 +#define GLFW_GAMEPAD_BUTTON_RIGHT_THUMB 10 +#define GLFW_GAMEPAD_BUTTON_DPAD_UP 11 +#define GLFW_GAMEPAD_BUTTON_DPAD_RIGHT 12 +#define GLFW_GAMEPAD_BUTTON_DPAD_DOWN 13 +#define GLFW_GAMEPAD_BUTTON_DPAD_LEFT 14 +#define GLFW_GAMEPAD_BUTTON_LAST GLFW_GAMEPAD_BUTTON_DPAD_LEFT + +#define GLFW_GAMEPAD_BUTTON_CROSS GLFW_GAMEPAD_BUTTON_A +#define GLFW_GAMEPAD_BUTTON_CIRCLE GLFW_GAMEPAD_BUTTON_B +#define GLFW_GAMEPAD_BUTTON_SQUARE GLFW_GAMEPAD_BUTTON_X +#define GLFW_GAMEPAD_BUTTON_TRIANGLE GLFW_GAMEPAD_BUTTON_Y +/*! @} */ + +/*! @defgroup gamepad_axes Gamepad axes + * @brief Gamepad axes. + * + * See @ref gamepad for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_GAMEPAD_AXIS_LEFT_X 0 +#define GLFW_GAMEPAD_AXIS_LEFT_Y 1 +#define GLFW_GAMEPAD_AXIS_RIGHT_X 2 +#define GLFW_GAMEPAD_AXIS_RIGHT_Y 3 +#define GLFW_GAMEPAD_AXIS_LEFT_TRIGGER 4 +#define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 5 +#define GLFW_GAMEPAD_AXIS_LAST GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER +/*! @} */ + +/*! @defgroup errors Error codes + * @brief Error codes. + * + * See [error handling](@ref error_handling) for how these are used. + * + * @ingroup init + * @{ */ +/*! @brief No error has occurred. + * + * No error has occurred. + * + * @analysis Yay. + */ +#define GLFW_NO_ERROR 0 +/*! @brief GLFW has not been initialized. + * + * This occurs if a GLFW function was called that must not be called unless the + * library is [initialized](@ref intro_init). + * + * @analysis Application programmer error. Initialize GLFW before calling any + * function that requires initialization. + */ +#define GLFW_NOT_INITIALIZED 0x00010001 +/*! @brief No context is current for this thread. + * + * This occurs if a GLFW function was called that needs and operates on the + * current OpenGL or OpenGL ES context but no context is current on the calling + * thread. One such function is @ref glfwSwapInterval. + * + * @analysis Application programmer error. Ensure a context is current before + * calling functions that require a current context. + */ +#define GLFW_NO_CURRENT_CONTEXT 0x00010002 +/*! @brief One of the arguments to the function was an invalid enum value. + * + * One of the arguments to the function was an invalid enum value, for example + * requesting @ref GLFW_RED_BITS with @ref glfwGetWindowAttrib. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_INVALID_ENUM 0x00010003 +/*! @brief One of the arguments to the function was an invalid value. + * + * One of the arguments to the function was an invalid value, for example + * requesting a non-existent OpenGL or OpenGL ES version like 2.7. + * + * Requesting a valid but unavailable OpenGL or OpenGL ES version will instead + * result in a @ref GLFW_VERSION_UNAVAILABLE error. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_INVALID_VALUE 0x00010004 +/*! @brief A memory allocation failed. + * + * A memory allocation failed. + * + * @analysis A bug in GLFW or the underlying operating system. Report the bug + * to our [issue tracker](https://github.com/glfw/glfw/issues). + */ +#define GLFW_OUT_OF_MEMORY 0x00010005 +/*! @brief GLFW could not find support for the requested API on the system. + * + * GLFW could not find support for the requested API on the system. + * + * @analysis The installed graphics driver does not support the requested + * API, or does not support it via the chosen context creation backend. + * Below are a few examples. + * + * @par + * Some pre-installed Windows graphics drivers do not support OpenGL. AMD only + * supports OpenGL ES via EGL, while Nvidia and Intel only support it via + * a WGL or GLX extension. macOS does not provide OpenGL ES at all. The Mesa + * EGL, OpenGL and OpenGL ES libraries do not interface with the Nvidia binary + * driver. Older graphics drivers do not support Vulkan. + */ +#define GLFW_API_UNAVAILABLE 0x00010006 +/*! @brief The requested OpenGL or OpenGL ES version is not available. + * + * The requested OpenGL or OpenGL ES version (including any requested context + * or framebuffer hints) is not available on this machine. + * + * @analysis The machine does not support your requirements. If your + * application is sufficiently flexible, downgrade your requirements and try + * again. Otherwise, inform the user that their machine does not match your + * requirements. + * + * @par + * Future invalid OpenGL and OpenGL ES versions, for example OpenGL 4.8 if 5.0 + * comes out before the 4.x series gets that far, also fail with this error and + * not @ref GLFW_INVALID_VALUE, because GLFW cannot know what future versions + * will exist. + */ +#define GLFW_VERSION_UNAVAILABLE 0x00010007 +/*! @brief A platform-specific error occurred that does not match any of the + * more specific categories. + * + * A platform-specific error occurred that does not match any of the more + * specific categories. + * + * @analysis A bug or configuration error in GLFW, the underlying operating + * system or its drivers, or a lack of required resources. Report the issue to + * our [issue tracker](https://github.com/glfw/glfw/issues). + */ +#define GLFW_PLATFORM_ERROR 0x00010008 +/*! @brief The requested format is not supported or available. + * + * If emitted during window creation, the requested pixel format is not + * supported. + * + * If emitted when querying the clipboard, the contents of the clipboard could + * not be converted to the requested format. + * + * @analysis If emitted during window creation, one or more + * [hard constraints](@ref window_hints_hard) did not match any of the + * available pixel formats. If your application is sufficiently flexible, + * downgrade your requirements and try again. Otherwise, inform the user that + * their machine does not match your requirements. + * + * @par + * If emitted when querying the clipboard, ignore the error or report it to + * the user, as appropriate. + */ +#define GLFW_FORMAT_UNAVAILABLE 0x00010009 +/*! @brief The specified window does not have an OpenGL or OpenGL ES context. + * + * A window that does not have an OpenGL or OpenGL ES context was passed to + * a function that requires it to have one. + * + * @analysis Application programmer error. Fix the offending call. + */ +#define GLFW_NO_WINDOW_CONTEXT 0x0001000A +/*! @} */ + +/*! @addtogroup window + * @{ */ +/*! @brief Input focus window hint and attribute + * + * Input focus [window hint](@ref GLFW_FOCUSED_hint) or + * [window attribute](@ref GLFW_FOCUSED_attrib). + */ +#define GLFW_FOCUSED 0x00020001 +/*! @brief Window iconification window attribute + * + * Window iconification [window attribute](@ref GLFW_ICONIFIED_attrib). + */ +#define GLFW_ICONIFIED 0x00020002 +/*! @brief Window resize-ability window hint and attribute + * + * Window resize-ability [window hint](@ref GLFW_RESIZABLE_hint) and + * [window attribute](@ref GLFW_RESIZABLE_attrib). + */ +#define GLFW_RESIZABLE 0x00020003 +/*! @brief Window visibility window hint and attribute + * + * Window visibility [window hint](@ref GLFW_VISIBLE_hint) and + * [window attribute](@ref GLFW_VISIBLE_attrib). + */ +#define GLFW_VISIBLE 0x00020004 +/*! @brief Window decoration window hint and attribute + * + * Window decoration [window hint](@ref GLFW_DECORATED_hint) and + * [window attribute](@ref GLFW_DECORATED_attrib). + */ +#define GLFW_DECORATED 0x00020005 +/*! @brief Window auto-iconification window hint and attribute + * + * Window auto-iconification [window hint](@ref GLFW_AUTO_ICONIFY_hint) and + * [window attribute](@ref GLFW_AUTO_ICONIFY_attrib). + */ +#define GLFW_AUTO_ICONIFY 0x00020006 +/*! @brief Window decoration window hint and attribute + * + * Window decoration [window hint](@ref GLFW_FLOATING_hint) and + * [window attribute](@ref GLFW_FLOATING_attrib). + */ +#define GLFW_FLOATING 0x00020007 +/*! @brief Window maximization window hint and attribute + * + * Window maximization [window hint](@ref GLFW_MAXIMIZED_hint) and + * [window attribute](@ref GLFW_MAXIMIZED_attrib). + */ +#define GLFW_MAXIMIZED 0x00020008 +/*! @brief Cursor centering window hint + * + * Cursor centering [window hint](@ref GLFW_CENTER_CURSOR_hint). + */ +#define GLFW_CENTER_CURSOR 0x00020009 +/*! @brief Window framebuffer transparency hint and attribute + * + * Window framebuffer transparency + * [window hint](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint) and + * [window attribute](@ref GLFW_TRANSPARENT_FRAMEBUFFER_attrib). + */ +#define GLFW_TRANSPARENT_FRAMEBUFFER 0x0002000A + +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_RED_BITS). + */ +#define GLFW_RED_BITS 0x00021001 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_GREEN_BITS). + */ +#define GLFW_GREEN_BITS 0x00021002 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_BLUE_BITS). + */ +#define GLFW_BLUE_BITS 0x00021003 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ALPHA_BITS). + */ +#define GLFW_ALPHA_BITS 0x00021004 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_DEPTH_BITS). + */ +#define GLFW_DEPTH_BITS 0x00021005 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_STENCIL_BITS). + */ +#define GLFW_STENCIL_BITS 0x00021006 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_RED_BITS). + */ +#define GLFW_ACCUM_RED_BITS 0x00021007 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_GREEN_BITS). + */ +#define GLFW_ACCUM_GREEN_BITS 0x00021008 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_BLUE_BITS). + */ +#define GLFW_ACCUM_BLUE_BITS 0x00021009 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_ALPHA_BITS). + */ +#define GLFW_ACCUM_ALPHA_BITS 0x0002100A +/*! @brief Framebuffer auxiliary buffer hint. + * + * Framebuffer auxiliary buffer [hint](@ref GLFW_AUX_BUFFERS). + */ +#define GLFW_AUX_BUFFERS 0x0002100B +/*! @brief OpenGL stereoscopic rendering hint. + * + * OpenGL stereoscopic rendering [hint](@ref GLFW_STEREO). + */ +#define GLFW_STEREO 0x0002100C +/*! @brief Framebuffer MSAA samples hint. + * + * Framebuffer MSAA samples [hint](@ref GLFW_SAMPLES). + */ +#define GLFW_SAMPLES 0x0002100D +/*! @brief Framebuffer sRGB hint. + * + * Framebuffer sRGB [hint](@ref GLFW_SRGB_CAPABLE). + */ +#define GLFW_SRGB_CAPABLE 0x0002100E +/*! @brief Monitor refresh rate hint. + * + * Monitor refresh rate [hint](@ref GLFW_REFRESH_RATE). + */ +#define GLFW_REFRESH_RATE 0x0002100F +/*! @brief Framebuffer double buffering hint. + * + * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER). + */ +#define GLFW_DOUBLEBUFFER 0x00021010 + +/*! @brief Context client API hint and attribute. + * + * Context client API [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CLIENT_API 0x00022001 +/*! @brief Context client API major version hint and attribute. + * + * Context client API major version [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_VERSION_MAJOR 0x00022002 +/*! @brief Context client API minor version hint and attribute. + * + * Context client API minor version [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_VERSION_MINOR 0x00022003 +/*! @brief Context client API revision number hint and attribute. + * + * Context client API revision number [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_REVISION 0x00022004 +/*! @brief Context robustness hint and attribute. + * + * Context client API revision number [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_ROBUSTNESS 0x00022005 +/*! @brief OpenGL forward-compatibility hint and attribute. + * + * OpenGL forward-compatibility [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_OPENGL_FORWARD_COMPAT 0x00022006 +/*! @brief OpenGL debug context hint and attribute. + * + * OpenGL debug context [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_OPENGL_DEBUG_CONTEXT 0x00022007 +/*! @brief OpenGL profile hint and attribute. + * + * OpenGL profile [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_OPENGL_PROFILE 0x00022008 +/*! @brief Context flush-on-release hint and attribute. + * + * Context flush-on-release [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 +/*! @brief Context error suppression hint and attribute. + * + * Context error suppression [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_NO_ERROR 0x0002200A +/*! @brief Context creation API hint and attribute. + * + * Context creation API [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ +#define GLFW_CONTEXT_CREATION_API 0x0002200B + +#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 +#define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002 +#define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 +/*! @} */ + +#define GLFW_NO_API 0 +#define GLFW_OPENGL_API 0x00030001 +#define GLFW_OPENGL_ES_API 0x00030002 + +#define GLFW_NO_ROBUSTNESS 0 +#define GLFW_NO_RESET_NOTIFICATION 0x00031001 +#define GLFW_LOSE_CONTEXT_ON_RESET 0x00031002 + +#define GLFW_OPENGL_ANY_PROFILE 0 +#define GLFW_OPENGL_CORE_PROFILE 0x00032001 +#define GLFW_OPENGL_COMPAT_PROFILE 0x00032002 + +#define GLFW_CURSOR 0x00033001 +#define GLFW_STICKY_KEYS 0x00033002 +#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003 + +#define GLFW_CURSOR_NORMAL 0x00034001 +#define GLFW_CURSOR_HIDDEN 0x00034002 +#define GLFW_CURSOR_DISABLED 0x00034003 + +#define GLFW_ANY_RELEASE_BEHAVIOR 0 +#define GLFW_RELEASE_BEHAVIOR_FLUSH 0x00035001 +#define GLFW_RELEASE_BEHAVIOR_NONE 0x00035002 + +#define GLFW_NATIVE_CONTEXT_API 0x00036001 +#define GLFW_EGL_CONTEXT_API 0x00036002 +#define GLFW_OSMESA_CONTEXT_API 0x00036003 + +/*! @defgroup shapes Standard cursor shapes + * @brief Standard system cursor shapes. + * + * See [standard cursor creation](@ref cursor_standard) for how these are used. + * + * @ingroup input + * @{ */ + +/*! @brief The regular arrow cursor shape. + * + * The regular arrow cursor. + */ +#define GLFW_ARROW_CURSOR 0x00036001 +/*! @brief The text input I-beam cursor shape. + * + * The text input I-beam cursor shape. + */ +#define GLFW_IBEAM_CURSOR 0x00036002 +/*! @brief The crosshair shape. + * + * The crosshair shape. + */ +#define GLFW_CROSSHAIR_CURSOR 0x00036003 +/*! @brief The hand shape. + * + * The hand shape. + */ +#define GLFW_HAND_CURSOR 0x00036004 +/*! @brief The horizontal resize arrow shape. + * + * The horizontal resize arrow shape. + */ +#define GLFW_HRESIZE_CURSOR 0x00036005 +/*! @brief The vertical resize arrow shape. + * + * The vertical resize arrow shape. + */ +#define GLFW_VRESIZE_CURSOR 0x00036006 +/*! @} */ + +#define GLFW_CONNECTED 0x00040001 +#define GLFW_DISCONNECTED 0x00040002 + +/*! @addtogroup init + * @{ */ +#define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 + +#define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 +#define GLFW_COCOA_MENUBAR 0x00051002 + +#define GLFW_X11_WM_CLASS_NAME 0x00052001 +#define GLFW_X11_WM_CLASS_CLASS 0x00052002 +/*! @} */ + +#define GLFW_DONT_CARE -1 + + +/************************************************************************* + * GLFW API types + *************************************************************************/ + +/*! @brief Client API function pointer type. + * + * Generic function pointer used for returning client API function pointers + * without forcing a cast from a regular pointer. + * + * @sa @ref context_glext + * @sa @ref glfwGetProcAddress + * + * @since Added in version 3.0. + + * @ingroup context + */ +typedef void (*GLFWglproc)(void); + +/*! @brief Vulkan API function pointer type. + * + * Generic function pointer used for returning Vulkan API function pointers + * without forcing a cast from a regular pointer. + * + * @sa @ref vulkan_proc + * @sa @ref glfwGetInstanceProcAddress + * + * @since Added in version 3.2. + * + * @ingroup vulkan + */ +typedef void (*GLFWvkproc)(void); + +/*! @brief Opaque monitor object. + * + * Opaque monitor object. + * + * @see @ref monitor_object + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef struct GLFWmonitor GLFWmonitor; + +/*! @brief Opaque window object. + * + * Opaque window object. + * + * @see @ref window_object + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef struct GLFWwindow GLFWwindow; + +/*! @brief Opaque cursor object. + * + * Opaque cursor object. + * + * @see @ref cursor_object + * + * @since Added in version 3.1. + * + * @ingroup cursor + */ +typedef struct GLFWcursor GLFWcursor; + +/*! @brief The function signature for error callbacks. + * + * This is the function signature for error callback functions. + * + * @param[in] error An [error code](@ref errors). + * @param[in] description A UTF-8 encoded string describing the error. + * + * @sa @ref error_handling + * @sa @ref glfwSetErrorCallback + * + * @since Added in version 3.0. + * + * @ingroup init + */ +typedef void (* GLFWerrorfun)(int,const char*); + +/*! @brief The function signature for window position callbacks. + * + * This is the function signature for window position callback functions. + * + * @param[in] window The window that was moved. + * @param[in] xpos The new x-coordinate, in screen coordinates, of the + * upper-left corner of the client area of the window. + * @param[in] ypos The new y-coordinate, in screen coordinates, of the + * upper-left corner of the client area of the window. + * + * @sa @ref window_pos + * @sa @ref glfwSetWindowPosCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowposfun)(GLFWwindow*,int,int); + +/*! @brief The function signature for window resize callbacks. + * + * This is the function signature for window size callback functions. + * + * @param[in] window The window that was resized. + * @param[in] width The new width, in screen coordinates, of the window. + * @param[in] height The new height, in screen coordinates, of the window. + * + * @sa @ref window_size + * @sa @ref glfwSetWindowSizeCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int); + +/*! @brief The function signature for window close callbacks. + * + * This is the function signature for window close callback functions. + * + * @param[in] window The window that the user attempted to close. + * + * @sa @ref window_close + * @sa @ref glfwSetWindowCloseCallback + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowclosefun)(GLFWwindow*); + +/*! @brief The function signature for window content refresh callbacks. + * + * This is the function signature for window refresh callback functions. + * + * @param[in] window The window whose content needs to be refreshed. + * + * @sa @ref window_refresh + * @sa @ref glfwSetWindowRefreshCallback + * + * @since Added in version 2.5. + * @glfw3 Added window handle parameter. + * + * @ingroup window + */ +typedef void (* GLFWwindowrefreshfun)(GLFWwindow*); + +/*! @brief The function signature for window focus/defocus callbacks. + * + * This is the function signature for window focus callback functions. + * + * @param[in] window The window that gained or lost input focus. + * @param[in] focused `GLFW_TRUE` if the window was given input focus, or + * `GLFW_FALSE` if it lost it. + * + * @sa @ref window_focus + * @sa @ref glfwSetWindowFocusCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int); + +/*! @brief The function signature for window iconify/restore callbacks. + * + * This is the function signature for window iconify/restore callback + * functions. + * + * @param[in] window The window that was iconified or restored. + * @param[in] iconified `GLFW_TRUE` if the window was iconified, or + * `GLFW_FALSE` if it was restored. + * + * @sa @ref window_iconify + * @sa @ref glfwSetWindowIconifyCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int); + +/*! @brief The function signature for window maximize/restore callbacks. + * + * This is the function signature for window maximize/restore callback + * functions. + * + * @param[in] window The window that was maximized or restored. + * @param[in] iconified `GLFW_TRUE` if the window was maximized, or + * `GLFW_FALSE` if it was restored. + * + * @sa @ref window_maximize + * @sa glfwSetWindowMaximizeCallback + * + * @since Added in version 3.3. + * + * @ingroup window + */ +typedef void (* GLFWwindowmaximizefun)(GLFWwindow*,int); + +/*! @brief The function signature for framebuffer resize callbacks. + * + * This is the function signature for framebuffer resize callback + * functions. + * + * @param[in] window The window whose framebuffer was resized. + * @param[in] width The new width, in pixels, of the framebuffer. + * @param[in] height The new height, in pixels, of the framebuffer. + * + * @sa @ref window_fbsize + * @sa @ref glfwSetFramebufferSizeCallback + * + * @since Added in version 3.0. + * + * @ingroup window + */ +typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int); + +/*! @brief The function signature for mouse button callbacks. + * + * This is the function signature for mouse button callback functions. + * + * @param[in] window The window that received the event. + * @param[in] button The [mouse button](@ref buttons) that was pressed or + * released. + * @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_mouse_button + * @sa @ref glfwSetMouseButtonCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle and modifier mask parameters. + * + * @ingroup input + */ +typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); + +/*! @brief The function signature for cursor position callbacks. + * + * This is the function signature for cursor position callback functions. + * + * @param[in] window The window that received the event. + * @param[in] xpos The new cursor x-coordinate, relative to the left edge of + * the client area. + * @param[in] ypos The new cursor y-coordinate, relative to the top edge of the + * client area. + * + * @sa @ref cursor_pos + * @sa @ref glfwSetCursorPosCallback + * + * @since Added in version 3.0. Replaces `GLFWmouseposfun`. + * + * @ingroup input + */ +typedef void (* GLFWcursorposfun)(GLFWwindow*,double,double); + +/*! @brief The function signature for cursor enter/leave callbacks. + * + * This is the function signature for cursor enter/leave callback functions. + * + * @param[in] window The window that received the event. + * @param[in] entered `GLFW_TRUE` if the cursor entered the window's client + * area, or `GLFW_FALSE` if it left it. + * + * @sa @ref cursor_enter + * @sa @ref glfwSetCursorEnterCallback + * + * @since Added in version 3.0. + * + * @ingroup input + */ +typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); + +/*! @brief The function signature for scroll callbacks. + * + * This is the function signature for scroll callback functions. + * + * @param[in] window The window that received the event. + * @param[in] xoffset The scroll offset along the x-axis. + * @param[in] yoffset The scroll offset along the y-axis. + * + * @sa @ref scrolling + * @sa @ref glfwSetScrollCallback + * + * @since Added in version 3.0. Replaces `GLFWmousewheelfun`. + * + * @ingroup input + */ +typedef void (* GLFWscrollfun)(GLFWwindow*,double,double); + +/*! @brief The function signature for keyboard key callbacks. + * + * This is the function signature for keyboard key callback functions. + * + * @param[in] window The window that received the event. + * @param[in] key The [keyboard key](@ref keys) that was pressed or released. + * @param[in] scancode The system-specific scancode of the key. + * @param[in] action `GLFW_PRESS`, `GLFW_RELEASE` or `GLFW_REPEAT`. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_key + * @sa @ref glfwSetKeyCallback + * + * @since Added in version 1.0. + * @glfw3 Added window handle, scancode and modifier mask parameters. + * + * @ingroup input + */ +typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); + +/*! @brief The function signature for Unicode character callbacks. + * + * This is the function signature for Unicode character callback functions. + * + * @param[in] window The window that received the event. + * @param[in] codepoint The Unicode code point of the character. + * + * @sa @ref input_char + * @sa @ref glfwSetCharCallback + * + * @since Added in version 2.4. + * @glfw3 Added window handle parameter. + * + * @ingroup input + */ +typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); + +/*! @brief The function signature for Unicode character with modifiers + * callbacks. + * + * This is the function signature for Unicode character with modifiers callback + * functions. It is called for each input character, regardless of what + * modifier keys are held down. + * + * @param[in] window The window that received the event. + * @param[in] codepoint The Unicode code point of the character. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. + * + * @sa @ref input_char + * @sa @ref glfwSetCharModsCallback + * + * @deprecated Scheduled for removal in version 4.0. + * + * @since Added in version 3.1. + * + * @ingroup input + */ +typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); + +/*! @brief The function signature for file drop callbacks. + * + * This is the function signature for file drop callbacks. + * + * @param[in] window The window that received the event. + * @param[in] count The number of dropped files. + * @param[in] paths The UTF-8 encoded file and/or directory path names. + * + * @sa @ref path_drop + * @sa @ref glfwSetDropCallback + * + * @since Added in version 3.1. + * + * @ingroup input + */ +typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); + +/*! @brief The function signature for monitor configuration callbacks. + * + * This is the function signature for monitor configuration callback functions. + * + * @param[in] monitor The monitor that was connected or disconnected. + * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. + * + * @sa @ref monitor_event + * @sa @ref glfwSetMonitorCallback + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef void (* GLFWmonitorfun)(GLFWmonitor*,int); + +/*! @brief The function signature for joystick configuration callbacks. + * + * This is the function signature for joystick configuration callback + * functions. + * + * @param[in] jid The joystick that was connected or disconnected. + * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. + * + * @sa @ref joystick_event + * @sa @ref glfwSetJoystickCallback + * + * @since Added in version 3.2. + * + * @ingroup input + */ +typedef void (* GLFWjoystickfun)(int,int); + +/*! @brief Video mode type. + * + * This describes a single video mode. + * + * @sa @ref monitor_modes + * @sa @ref glfwGetVideoMode + * @sa @ref glfwGetVideoModes + * + * @since Added in version 1.0. + * @glfw3 Added refresh rate member. + * + * @ingroup monitor + */ +typedef struct GLFWvidmode +{ + /*! The width, in screen coordinates, of the video mode. + */ + int width; + /*! The height, in screen coordinates, of the video mode. + */ + int height; + /*! The bit depth of the red channel of the video mode. + */ + int redBits; + /*! The bit depth of the green channel of the video mode. + */ + int greenBits; + /*! The bit depth of the blue channel of the video mode. + */ + int blueBits; + /*! The refresh rate, in Hz, of the video mode. + */ + int refreshRate; +} GLFWvidmode; + +/*! @brief Gamma ramp. + * + * This describes the gamma ramp for a monitor. + * + * @sa @ref monitor_gamma + * @sa @ref glfwGetGammaRamp + * @sa @ref glfwSetGammaRamp + * + * @since Added in version 3.0. + * + * @ingroup monitor + */ +typedef struct GLFWgammaramp +{ + /*! An array of value describing the response of the red channel. + */ + unsigned short* red; + /*! An array of value describing the response of the green channel. + */ + unsigned short* green; + /*! An array of value describing the response of the blue channel. + */ + unsigned short* blue; + /*! The number of elements in each array. + */ + unsigned int size; +} GLFWgammaramp; + +/*! @brief Image data. + * + * This describes a single 2D image. See the documentation for each related + * function what the expected pixel format is. + * + * @sa @ref cursor_custom + * @sa @ref window_icon + * + * @since Added in version 2.1. + * @glfw3 Removed format and bytes-per-pixel members. + */ +typedef struct GLFWimage +{ + /*! The width, in pixels, of this image. + */ + int width; + /*! The height, in pixels, of this image. + */ + int height; + /*! The pixel data of this image, arranged left-to-right, top-to-bottom. + */ + unsigned char* pixels; +} GLFWimage; + +/*! @brief Gamepad input state + * + * This describes the input state of a gamepad. + * + * @sa @ref gamepad + * @sa @ref glfwGetGamepadState + * + * @since Added in version 3.3. + */ +typedef struct GLFWgamepadstate +{ + /*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS` + * or `GLFW_RELEASE`. + */ + unsigned char buttons[15]; + /*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0 + * to 1.0 inclusive. + */ + float axes[6]; +} GLFWgamepadstate; + + +/************************************************************************* + * GLFW API functions + *************************************************************************/ + +/*! @brief Initializes the GLFW library. + * + * This function initializes the GLFW library. Before most GLFW functions can + * be used, GLFW must be initialized, and before an application terminates GLFW + * should be terminated in order to free any resources allocated during or + * after initialization. + * + * If this function fails, it calls @ref glfwTerminate before returning. If it + * succeeds, you should call @ref glfwTerminate before the application exits. + * + * Additional calls to this function after successful initialization but before + * termination will return `GLFW_TRUE` immediately. + * + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_PLATFORM_ERROR. + * + * @remark @macos This function will change the current directory of the + * application to the `Contents/Resources` subdirectory of the application's + * bundle, if present. This can be disabled with the @ref + * GLFW_COCOA_CHDIR_RESOURCES init hint. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref intro_init + * @sa @ref glfwTerminate + * + * @since Added in version 1.0. + * + * @ingroup init + */ + + +typedef int (*glfwInit_func)(); +glfwInit_func glfwInit_impl; +#define glfwInit glfwInit_impl + +typedef void (*glfwTerminate_func)(); +glfwTerminate_func glfwTerminate_impl; +#define glfwTerminate glfwTerminate_impl + +typedef void (*glfwInitHint_func)(int, int); +glfwInitHint_func glfwInitHint_impl; +#define glfwInitHint glfwInitHint_impl + +typedef void (*glfwInitHintString_func)(int, const char*); +glfwInitHintString_func glfwInitHintString_impl; +#define glfwInitHintString glfwInitHintString_impl + +typedef void (*glfwGetVersion_func)(int*, int*, int*); +glfwGetVersion_func glfwGetVersion_impl; +#define glfwGetVersion glfwGetVersion_impl + +typedef const char* (*glfwGetVersionString_func)(); +glfwGetVersionString_func glfwGetVersionString_impl; +#define glfwGetVersionString glfwGetVersionString_impl + +typedef int (*glfwGetError_func)(const char**); +glfwGetError_func glfwGetError_impl; +#define glfwGetError glfwGetError_impl + +typedef GLFWerrorfun (*glfwSetErrorCallback_func)(GLFWerrorfun); +glfwSetErrorCallback_func glfwSetErrorCallback_impl; +#define glfwSetErrorCallback glfwSetErrorCallback_impl + +typedef GLFWmonitor** (*glfwGetMonitors_func)(int*); +glfwGetMonitors_func glfwGetMonitors_impl; +#define glfwGetMonitors glfwGetMonitors_impl + +typedef GLFWmonitor* (*glfwGetPrimaryMonitor_func)(); +glfwGetPrimaryMonitor_func glfwGetPrimaryMonitor_impl; +#define glfwGetPrimaryMonitor glfwGetPrimaryMonitor_impl + +typedef void (*glfwGetMonitorPos_func)(GLFWmonitor*, int*, int*); +glfwGetMonitorPos_func glfwGetMonitorPos_impl; +#define glfwGetMonitorPos glfwGetMonitorPos_impl + +typedef void (*glfwGetMonitorPhysicalSize_func)(GLFWmonitor*, int*, int*); +glfwGetMonitorPhysicalSize_func glfwGetMonitorPhysicalSize_impl; +#define glfwGetMonitorPhysicalSize glfwGetMonitorPhysicalSize_impl + +typedef void (*glfwGetMonitorContentScale_func)(GLFWmonitor*, float*, float*); +glfwGetMonitorContentScale_func glfwGetMonitorContentScale_impl; +#define glfwGetMonitorContentScale glfwGetMonitorContentScale_impl + +typedef const char* (*glfwGetMonitorName_func)(GLFWmonitor*); +glfwGetMonitorName_func glfwGetMonitorName_impl; +#define glfwGetMonitorName glfwGetMonitorName_impl + +typedef GLFWmonitorfun (*glfwSetMonitorCallback_func)(GLFWmonitorfun); +glfwSetMonitorCallback_func glfwSetMonitorCallback_impl; +#define glfwSetMonitorCallback glfwSetMonitorCallback_impl + +typedef const GLFWvidmode* (*glfwGetVideoModes_func)(GLFWmonitor*, int*); +glfwGetVideoModes_func glfwGetVideoModes_impl; +#define glfwGetVideoModes glfwGetVideoModes_impl + +typedef const GLFWvidmode* (*glfwGetVideoMode_func)(GLFWmonitor*); +glfwGetVideoMode_func glfwGetVideoMode_impl; +#define glfwGetVideoMode glfwGetVideoMode_impl + +typedef void (*glfwSetGamma_func)(GLFWmonitor*, float); +glfwSetGamma_func glfwSetGamma_impl; +#define glfwSetGamma glfwSetGamma_impl + +typedef const GLFWgammaramp* (*glfwGetGammaRamp_func)(GLFWmonitor*); +glfwGetGammaRamp_func glfwGetGammaRamp_impl; +#define glfwGetGammaRamp glfwGetGammaRamp_impl + +typedef void (*glfwSetGammaRamp_func)(GLFWmonitor*, const GLFWgammaramp*); +glfwSetGammaRamp_func glfwSetGammaRamp_impl; +#define glfwSetGammaRamp glfwSetGammaRamp_impl + +typedef void (*glfwDefaultWindowHints_func)(); +glfwDefaultWindowHints_func glfwDefaultWindowHints_impl; +#define glfwDefaultWindowHints glfwDefaultWindowHints_impl + +typedef void (*glfwWindowHint_func)(int, int); +glfwWindowHint_func glfwWindowHint_impl; +#define glfwWindowHint glfwWindowHint_impl + +typedef GLFWwindow* (*glfwCreateWindow_func)(int, int, const char*, GLFWmonitor*, GLFWwindow*); +glfwCreateWindow_func glfwCreateWindow_impl; +#define glfwCreateWindow glfwCreateWindow_impl + +typedef void (*glfwDestroyWindow_func)(GLFWwindow*); +glfwDestroyWindow_func glfwDestroyWindow_impl; +#define glfwDestroyWindow glfwDestroyWindow_impl + +typedef int (*glfwWindowShouldClose_func)(GLFWwindow*); +glfwWindowShouldClose_func glfwWindowShouldClose_impl; +#define glfwWindowShouldClose glfwWindowShouldClose_impl + +typedef void (*glfwSetWindowShouldClose_func)(GLFWwindow*, int); +glfwSetWindowShouldClose_func glfwSetWindowShouldClose_impl; +#define glfwSetWindowShouldClose glfwSetWindowShouldClose_impl + +typedef void (*glfwSetWindowTitle_func)(GLFWwindow*, const char*); +glfwSetWindowTitle_func glfwSetWindowTitle_impl; +#define glfwSetWindowTitle glfwSetWindowTitle_impl + +typedef void (*glfwSetWindowIcon_func)(GLFWwindow*, int, const GLFWimage*); +glfwSetWindowIcon_func glfwSetWindowIcon_impl; +#define glfwSetWindowIcon glfwSetWindowIcon_impl + +typedef void (*glfwGetWindowPos_func)(GLFWwindow*, int*, int*); +glfwGetWindowPos_func glfwGetWindowPos_impl; +#define glfwGetWindowPos glfwGetWindowPos_impl + +typedef void (*glfwSetWindowPos_func)(GLFWwindow*, int, int); +glfwSetWindowPos_func glfwSetWindowPos_impl; +#define glfwSetWindowPos glfwSetWindowPos_impl + +typedef void (*glfwGetWindowSize_func)(GLFWwindow*, int*, int*); +glfwGetWindowSize_func glfwGetWindowSize_impl; +#define glfwGetWindowSize glfwGetWindowSize_impl + +typedef void (*glfwSetWindowSizeLimits_func)(GLFWwindow*, int, int, int, int); +glfwSetWindowSizeLimits_func glfwSetWindowSizeLimits_impl; +#define glfwSetWindowSizeLimits glfwSetWindowSizeLimits_impl + +typedef void (*glfwSetWindowAspectRatio_func)(GLFWwindow*, int, int); +glfwSetWindowAspectRatio_func glfwSetWindowAspectRatio_impl; +#define glfwSetWindowAspectRatio glfwSetWindowAspectRatio_impl + +typedef void (*glfwSetWindowSize_func)(GLFWwindow*, int, int); +glfwSetWindowSize_func glfwSetWindowSize_impl; +#define glfwSetWindowSize glfwSetWindowSize_impl + +typedef void (*glfwGetFramebufferSize_func)(GLFWwindow*, int*, int*); +glfwGetFramebufferSize_func glfwGetFramebufferSize_impl; +#define glfwGetFramebufferSize glfwGetFramebufferSize_impl + +typedef void (*glfwGetWindowFrameSize_func)(GLFWwindow*, int*, int*, int*, int*); +glfwGetWindowFrameSize_func glfwGetWindowFrameSize_impl; +#define glfwGetWindowFrameSize glfwGetWindowFrameSize_impl + +typedef void (*glfwGetWindowContentScale_func)(GLFWwindow*, float*, float*); +glfwGetWindowContentScale_func glfwGetWindowContentScale_impl; +#define glfwGetWindowContentScale glfwGetWindowContentScale_impl + +typedef float (*glfwGetWindowOpacity_func)(GLFWwindow*); +glfwGetWindowOpacity_func glfwGetWindowOpacity_impl; +#define glfwGetWindowOpacity glfwGetWindowOpacity_impl + +typedef void (*glfwSetWindowOpacity_func)(GLFWwindow*, float); +glfwSetWindowOpacity_func glfwSetWindowOpacity_impl; +#define glfwSetWindowOpacity glfwSetWindowOpacity_impl + +typedef void (*glfwIconifyWindow_func)(GLFWwindow*); +glfwIconifyWindow_func glfwIconifyWindow_impl; +#define glfwIconifyWindow glfwIconifyWindow_impl + +typedef void (*glfwRestoreWindow_func)(GLFWwindow*); +glfwRestoreWindow_func glfwRestoreWindow_impl; +#define glfwRestoreWindow glfwRestoreWindow_impl + +typedef void (*glfwMaximizeWindow_func)(GLFWwindow*); +glfwMaximizeWindow_func glfwMaximizeWindow_impl; +#define glfwMaximizeWindow glfwMaximizeWindow_impl + +typedef void (*glfwShowWindow_func)(GLFWwindow*); +glfwShowWindow_func glfwShowWindow_impl; +#define glfwShowWindow glfwShowWindow_impl + +typedef void (*glfwHideWindow_func)(GLFWwindow*); +glfwHideWindow_func glfwHideWindow_impl; +#define glfwHideWindow glfwHideWindow_impl + +typedef void (*glfwFocusWindow_func)(GLFWwindow*); +glfwFocusWindow_func glfwFocusWindow_impl; +#define glfwFocusWindow glfwFocusWindow_impl + +typedef void (*glfwRequestWindowAttention_func)(GLFWwindow*); +glfwRequestWindowAttention_func glfwRequestWindowAttention_impl; +#define glfwRequestWindowAttention glfwRequestWindowAttention_impl + +typedef GLFWmonitor* (*glfwGetWindowMonitor_func)(GLFWwindow*); +glfwGetWindowMonitor_func glfwGetWindowMonitor_impl; +#define glfwGetWindowMonitor glfwGetWindowMonitor_impl + +typedef void (*glfwSetWindowMonitor_func)(GLFWwindow*, GLFWmonitor*, int, int, int, int, int); +glfwSetWindowMonitor_func glfwSetWindowMonitor_impl; +#define glfwSetWindowMonitor glfwSetWindowMonitor_impl + +typedef int (*glfwGetWindowAttrib_func)(GLFWwindow*, int); +glfwGetWindowAttrib_func glfwGetWindowAttrib_impl; +#define glfwGetWindowAttrib glfwGetWindowAttrib_impl + +typedef void (*glfwSetWindowAttrib_func)(GLFWwindow*, int, int); +glfwSetWindowAttrib_func glfwSetWindowAttrib_impl; +#define glfwSetWindowAttrib glfwSetWindowAttrib_impl + +typedef void (*glfwSetWindowUserPointer_func)(GLFWwindow*, void*); +glfwSetWindowUserPointer_func glfwSetWindowUserPointer_impl; +#define glfwSetWindowUserPointer glfwSetWindowUserPointer_impl + +typedef void* (*glfwGetWindowUserPointer_func)(GLFWwindow*); +glfwGetWindowUserPointer_func glfwGetWindowUserPointer_impl; +#define glfwGetWindowUserPointer glfwGetWindowUserPointer_impl + +typedef GLFWwindowposfun (*glfwSetWindowPosCallback_func)(GLFWwindow*, GLFWwindowposfun); +glfwSetWindowPosCallback_func glfwSetWindowPosCallback_impl; +#define glfwSetWindowPosCallback glfwSetWindowPosCallback_impl + +typedef GLFWwindowsizefun (*glfwSetWindowSizeCallback_func)(GLFWwindow*, GLFWwindowsizefun); +glfwSetWindowSizeCallback_func glfwSetWindowSizeCallback_impl; +#define glfwSetWindowSizeCallback glfwSetWindowSizeCallback_impl + +typedef GLFWwindowclosefun (*glfwSetWindowCloseCallback_func)(GLFWwindow*, GLFWwindowclosefun); +glfwSetWindowCloseCallback_func glfwSetWindowCloseCallback_impl; +#define glfwSetWindowCloseCallback glfwSetWindowCloseCallback_impl + +typedef GLFWwindowrefreshfun (*glfwSetWindowRefreshCallback_func)(GLFWwindow*, GLFWwindowrefreshfun); +glfwSetWindowRefreshCallback_func glfwSetWindowRefreshCallback_impl; +#define glfwSetWindowRefreshCallback glfwSetWindowRefreshCallback_impl + +typedef GLFWwindowfocusfun (*glfwSetWindowFocusCallback_func)(GLFWwindow*, GLFWwindowfocusfun); +glfwSetWindowFocusCallback_func glfwSetWindowFocusCallback_impl; +#define glfwSetWindowFocusCallback glfwSetWindowFocusCallback_impl + +typedef GLFWwindowiconifyfun (*glfwSetWindowIconifyCallback_func)(GLFWwindow*, GLFWwindowiconifyfun); +glfwSetWindowIconifyCallback_func glfwSetWindowIconifyCallback_impl; +#define glfwSetWindowIconifyCallback glfwSetWindowIconifyCallback_impl + +typedef GLFWwindowmaximizefun (*glfwSetWindowMaximizeCallback_func)(GLFWwindow*, GLFWwindowmaximizefun); +glfwSetWindowMaximizeCallback_func glfwSetWindowMaximizeCallback_impl; +#define glfwSetWindowMaximizeCallback glfwSetWindowMaximizeCallback_impl + +typedef GLFWframebuffersizefun (*glfwSetFramebufferSizeCallback_func)(GLFWwindow*, GLFWframebuffersizefun); +glfwSetFramebufferSizeCallback_func glfwSetFramebufferSizeCallback_impl; +#define glfwSetFramebufferSizeCallback glfwSetFramebufferSizeCallback_impl + +typedef void (*glfwPollEvents_func)(); +glfwPollEvents_func glfwPollEvents_impl; +#define glfwPollEvents glfwPollEvents_impl + +typedef void (*glfwWaitEvents_func)(); +glfwWaitEvents_func glfwWaitEvents_impl; +#define glfwWaitEvents glfwWaitEvents_impl + +typedef void (*glfwWaitEventsTimeout_func)(double); +glfwWaitEventsTimeout_func glfwWaitEventsTimeout_impl; +#define glfwWaitEventsTimeout glfwWaitEventsTimeout_impl + +typedef void (*glfwPostEmptyEvent_func)(); +glfwPostEmptyEvent_func glfwPostEmptyEvent_impl; +#define glfwPostEmptyEvent glfwPostEmptyEvent_impl + +typedef int (*glfwGetInputMode_func)(GLFWwindow*, int); +glfwGetInputMode_func glfwGetInputMode_impl; +#define glfwGetInputMode glfwGetInputMode_impl + +typedef void (*glfwSetInputMode_func)(GLFWwindow*, int, int); +glfwSetInputMode_func glfwSetInputMode_impl; +#define glfwSetInputMode glfwSetInputMode_impl + +typedef const char* (*glfwGetKeyName_func)(int, int); +glfwGetKeyName_func glfwGetKeyName_impl; +#define glfwGetKeyName glfwGetKeyName_impl + +typedef int (*glfwGetKeyScancode_func)(int); +glfwGetKeyScancode_func glfwGetKeyScancode_impl; +#define glfwGetKeyScancode glfwGetKeyScancode_impl + +typedef int (*glfwGetKey_func)(GLFWwindow*, int); +glfwGetKey_func glfwGetKey_impl; +#define glfwGetKey glfwGetKey_impl + +typedef int (*glfwGetMouseButton_func)(GLFWwindow*, int); +glfwGetMouseButton_func glfwGetMouseButton_impl; +#define glfwGetMouseButton glfwGetMouseButton_impl + +typedef void (*glfwGetCursorPos_func)(GLFWwindow*, double*, double*); +glfwGetCursorPos_func glfwGetCursorPos_impl; +#define glfwGetCursorPos glfwGetCursorPos_impl + +typedef void (*glfwSetCursorPos_func)(GLFWwindow*, double, double); +glfwSetCursorPos_func glfwSetCursorPos_impl; +#define glfwSetCursorPos glfwSetCursorPos_impl + +typedef GLFWcursor* (*glfwCreateCursor_func)(const GLFWimage*, int, int); +glfwCreateCursor_func glfwCreateCursor_impl; +#define glfwCreateCursor glfwCreateCursor_impl + +typedef GLFWcursor* (*glfwCreateStandardCursor_func)(int); +glfwCreateStandardCursor_func glfwCreateStandardCursor_impl; +#define glfwCreateStandardCursor glfwCreateStandardCursor_impl + +typedef void (*glfwDestroyCursor_func)(GLFWcursor*); +glfwDestroyCursor_func glfwDestroyCursor_impl; +#define glfwDestroyCursor glfwDestroyCursor_impl + +typedef void (*glfwSetCursor_func)(GLFWwindow*, GLFWcursor*); +glfwSetCursor_func glfwSetCursor_impl; +#define glfwSetCursor glfwSetCursor_impl + +typedef GLFWkeyfun (*glfwSetKeyCallback_func)(GLFWwindow*, GLFWkeyfun); +glfwSetKeyCallback_func glfwSetKeyCallback_impl; +#define glfwSetKeyCallback glfwSetKeyCallback_impl + +typedef GLFWcharfun (*glfwSetCharCallback_func)(GLFWwindow*, GLFWcharfun); +glfwSetCharCallback_func glfwSetCharCallback_impl; +#define glfwSetCharCallback glfwSetCharCallback_impl + +typedef GLFWcharmodsfun (*glfwSetCharModsCallback_func)(GLFWwindow*, GLFWcharmodsfun); +glfwSetCharModsCallback_func glfwSetCharModsCallback_impl; +#define glfwSetCharModsCallback glfwSetCharModsCallback_impl + +typedef GLFWmousebuttonfun (*glfwSetMouseButtonCallback_func)(GLFWwindow*, GLFWmousebuttonfun); +glfwSetMouseButtonCallback_func glfwSetMouseButtonCallback_impl; +#define glfwSetMouseButtonCallback glfwSetMouseButtonCallback_impl + +typedef GLFWcursorposfun (*glfwSetCursorPosCallback_func)(GLFWwindow*, GLFWcursorposfun); +glfwSetCursorPosCallback_func glfwSetCursorPosCallback_impl; +#define glfwSetCursorPosCallback glfwSetCursorPosCallback_impl + +typedef GLFWcursorenterfun (*glfwSetCursorEnterCallback_func)(GLFWwindow*, GLFWcursorenterfun); +glfwSetCursorEnterCallback_func glfwSetCursorEnterCallback_impl; +#define glfwSetCursorEnterCallback glfwSetCursorEnterCallback_impl + +typedef GLFWscrollfun (*glfwSetScrollCallback_func)(GLFWwindow*, GLFWscrollfun); +glfwSetScrollCallback_func glfwSetScrollCallback_impl; +#define glfwSetScrollCallback glfwSetScrollCallback_impl + +typedef GLFWdropfun (*glfwSetDropCallback_func)(GLFWwindow*, GLFWdropfun); +glfwSetDropCallback_func glfwSetDropCallback_impl; +#define glfwSetDropCallback glfwSetDropCallback_impl + +typedef int (*glfwJoystickPresent_func)(int); +glfwJoystickPresent_func glfwJoystickPresent_impl; +#define glfwJoystickPresent glfwJoystickPresent_impl + +typedef const float* (*glfwGetJoystickAxes_func)(int, int*); +glfwGetJoystickAxes_func glfwGetJoystickAxes_impl; +#define glfwGetJoystickAxes glfwGetJoystickAxes_impl + +typedef const unsigned char* (*glfwGetJoystickButtons_func)(int, int*); +glfwGetJoystickButtons_func glfwGetJoystickButtons_impl; +#define glfwGetJoystickButtons glfwGetJoystickButtons_impl + +typedef const unsigned char* (*glfwGetJoystickHats_func)(int, int*); +glfwGetJoystickHats_func glfwGetJoystickHats_impl; +#define glfwGetJoystickHats glfwGetJoystickHats_impl + +typedef const char* (*glfwGetJoystickName_func)(int); +glfwGetJoystickName_func glfwGetJoystickName_impl; +#define glfwGetJoystickName glfwGetJoystickName_impl + +typedef const char* (*glfwGetJoystickGUID_func)(int); +glfwGetJoystickGUID_func glfwGetJoystickGUID_impl; +#define glfwGetJoystickGUID glfwGetJoystickGUID_impl + +typedef int (*glfwJoystickIsGamepad_func)(int); +glfwJoystickIsGamepad_func glfwJoystickIsGamepad_impl; +#define glfwJoystickIsGamepad glfwJoystickIsGamepad_impl + +typedef GLFWjoystickfun (*glfwSetJoystickCallback_func)(GLFWjoystickfun); +glfwSetJoystickCallback_func glfwSetJoystickCallback_impl; +#define glfwSetJoystickCallback glfwSetJoystickCallback_impl + +typedef int (*glfwUpdateGamepadMappings_func)(const char*); +glfwUpdateGamepadMappings_func glfwUpdateGamepadMappings_impl; +#define glfwUpdateGamepadMappings glfwUpdateGamepadMappings_impl + +typedef const char* (*glfwGetGamepadName_func)(int); +glfwGetGamepadName_func glfwGetGamepadName_impl; +#define glfwGetGamepadName glfwGetGamepadName_impl + +typedef int (*glfwGetGamepadState_func)(int, GLFWgamepadstate*); +glfwGetGamepadState_func glfwGetGamepadState_impl; +#define glfwGetGamepadState glfwGetGamepadState_impl + +typedef void (*glfwSetClipboardString_func)(GLFWwindow*, const char*); +glfwSetClipboardString_func glfwSetClipboardString_impl; +#define glfwSetClipboardString glfwSetClipboardString_impl + +typedef const char* (*glfwGetClipboardString_func)(GLFWwindow*); +glfwGetClipboardString_func glfwGetClipboardString_impl; +#define glfwGetClipboardString glfwGetClipboardString_impl + +typedef double (*glfwGetTime_func)(); +glfwGetTime_func glfwGetTime_impl; +#define glfwGetTime glfwGetTime_impl + +typedef void (*glfwSetTime_func)(double); +glfwSetTime_func glfwSetTime_impl; +#define glfwSetTime glfwSetTime_impl + +typedef uint64_t (*glfwGetTimerValue_func)(); +glfwGetTimerValue_func glfwGetTimerValue_impl; +#define glfwGetTimerValue glfwGetTimerValue_impl + +typedef uint64_t (*glfwGetTimerFrequency_func)(); +glfwGetTimerFrequency_func glfwGetTimerFrequency_impl; +#define glfwGetTimerFrequency glfwGetTimerFrequency_impl + +typedef void (*glfwMakeContextCurrent_func)(GLFWwindow*); +glfwMakeContextCurrent_func glfwMakeContextCurrent_impl; +#define glfwMakeContextCurrent glfwMakeContextCurrent_impl + +typedef GLFWwindow* (*glfwGetCurrentContext_func)(); +glfwGetCurrentContext_func glfwGetCurrentContext_impl; +#define glfwGetCurrentContext glfwGetCurrentContext_impl + +typedef void (*glfwSwapBuffers_func)(GLFWwindow*); +glfwSwapBuffers_func glfwSwapBuffers_impl; +#define glfwSwapBuffers glfwSwapBuffers_impl + +typedef void (*glfwSwapInterval_func)(int); +glfwSwapInterval_func glfwSwapInterval_impl; +#define glfwSwapInterval glfwSwapInterval_impl + +typedef int (*glfwExtensionSupported_func)(const char*); +glfwExtensionSupported_func glfwExtensionSupported_impl; +#define glfwExtensionSupported glfwExtensionSupported_impl + +typedef GLFWglproc (*glfwGetProcAddress_func)(const char*); +glfwGetProcAddress_func glfwGetProcAddress_impl; +#define glfwGetProcAddress glfwGetProcAddress_impl + +typedef int (*glfwVulkanSupported_func)(); +glfwVulkanSupported_func glfwVulkanSupported_impl; +#define glfwVulkanSupported glfwVulkanSupported_impl + +typedef const char** (*glfwGetRequiredInstanceExtensions_func)(uint32_t*); +glfwGetRequiredInstanceExtensions_func glfwGetRequiredInstanceExtensions_impl; +#define glfwGetRequiredInstanceExtensions glfwGetRequiredInstanceExtensions_impl + +const char* load_glfw(const char* path); diff --git a/kitty/glfw.c b/kitty/glfw.c index 76989187c..0b5740c29 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -6,23 +6,11 @@ #include "state.h" #include -#include +#include "glfw-wrapper.h" #if defined(__APPLE__) -#define GLFW_EXPOSE_NATIVE_COCOA -#include extern bool cocoa_make_window_resizable(void *w); #endif -#if GLFW_VERSION_MAJOR < 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR < 2) -#error "glfw >= 3.2 required" -#endif - -#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR > 2) -#define has_request_attention -#define has_init_hint_string -#define has_content_scale_query -#endif - #if GLFW_KEY_LAST >= MAX_KEY_COUNT #error "glfw has too many keys, you should increase MAX_KEY_COUNT" #endif @@ -316,7 +304,11 @@ error_callback(int error, const char* description) { PyObject* -glfw_init(PyObject UNUSED *self) { +glfw_init(PyObject UNUSED *self, PyObject *args) { + const char* path; + if (!PyArg_ParseTuple(args, "s", &path)) return NULL; + const char* err = load_glfw(path); + if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; } glfwSetErrorCallback(error_callback); PyObject *ans = glfwInit() ? Py_True: Py_False; Py_INCREF(ans); @@ -386,9 +378,7 @@ glfw_init_hint_string(PyObject UNUSED *self, PyObject *args) { int hint_id; char *hint; if (!PyArg_ParseTuple(args, "is", &hint_id, &hint)) return NULL; -#ifdef has_init_hint_string glfwInitHintString(hint_id, hint); -#endif Py_RETURN_NONE; } @@ -404,16 +394,10 @@ get_clipboard_string(PyObject UNUSED *self) { static PyObject* get_content_scale_for_window(PyObject UNUSED *self) { -#ifdef has_content_scale_query OSWindow *w = global_state.callback_os_window ? global_state.callback_os_window : global_state.os_windows; float xscale, yscale; glfwGetWindowContentScale(w->handle, &xscale, &yscale); return Py_BuildValue("ff", xscale, yscale); -#else - (void)self; - PyErr_SetString(PyExc_NotImplementedError, "glfw version is too old"); - return NULL; -#endif } static PyObject* @@ -488,9 +472,7 @@ void request_window_attention(id_type kitty_window_id) { OSWindow *w = os_window_for_kitty_window(kitty_window_id); if (w) { -#ifdef has_request_attention glfwRequestWindowAttention(w->handle); -#endif glfwPostEmptyEvent(); } } @@ -549,15 +531,10 @@ primary_monitor_size(PyObject UNUSED *self) { static PyObject* primary_monitor_content_scale(PyObject UNUSED *self) { -#ifdef has_content_scale_query GLFWmonitor* monitor = glfwGetPrimaryMonitor(); float xscale, yscale; glfwGetMonitorContentScale(monitor, &xscale, &yscale); return Py_BuildValue("ff", xscale, yscale); -#else - PyErr_SetString(PyExc_NotImplementedError, "glfw version is too old"); - return NULL; -#endif } static PyObject* @@ -572,7 +549,7 @@ os_window_should_close(PyObject UNUSED *self, PyObject *args) { if (should_os_window_close(w)) Py_RETURN_TRUE; Py_RETURN_FALSE; } - glfwSetWindowShouldClose(w->handle, q ? GLFW_TRUE : GL_FALSE); + glfwSetWindowShouldClose(w->handle, q ? GLFW_TRUE : GLFW_FALSE); Py_RETURN_NONE; } } @@ -607,7 +584,7 @@ static PyMethodDef module_methods[] = { METHODB(glfw_window_hint, METH_VARARGS), METHODB(os_window_should_close, METH_VARARGS), METHODB(os_window_swap_buffers, METH_VARARGS), - {"glfw_init", (PyCFunction)glfw_init, METH_NOARGS, ""}, + {"glfw_init", (PyCFunction)glfw_init, METH_VARARGS, ""}, {"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""}, {"glfw_wait_events", (PyCFunction)glfw_wait_events, METH_VARARGS, ""}, {"glfw_post_empty_event", (PyCFunction)glfw_post_empty_event, METH_NOARGS, ""}, @@ -624,10 +601,8 @@ bool init_glfw(PyObject *m) { if (PyModule_AddFunctions(m, module_methods) != 0) return false; #define ADDC(n) if(PyModule_AddIntConstant(m, #n, n) != 0) return false; -#ifdef GLFW_X11_WM_CLASS_NAME ADDC(GLFW_X11_WM_CLASS_NAME) ADDC(GLFW_X11_WM_CLASS_CLASS) -#endif ADDC(GLFW_RELEASE); ADDC(GLFW_PRESS); ADDC(GLFW_REPEAT); diff --git a/kitty/keys.c b/kitty/keys.c index 9798faa57..98b635ae3 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -8,7 +8,7 @@ #include "keys.h" #include "state.h" #include "screen.h" -#include +#include "glfw-wrapper.h" const char* key_to_bytes(int glfw_key, bool smkx, bool extended, int mods, int action) { diff --git a/kitty/main.py b/kitty/main.py index d83b0f78a..4e57e04e8 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -16,7 +16,7 @@ from .fast_data_types import ( change_wcwidth, create_os_window, glfw_init, glfw_init_hint_string, glfw_terminate, install_sigchld_handler, set_default_window_icon, - set_logical_dpi, set_options + set_logical_dpi, set_options, GLFW_X11_WM_CLASS_NAME, GLFW_X11_WM_CLASS_CLASS ) from .fonts.box_drawing import set_scale from .utils import ( @@ -25,11 +25,6 @@ ) from .window import load_shader_programs -try: - from .fast_data_types import GLFW_X11_WM_CLASS_NAME, GLFW_X11_WM_CLASS_CLASS -except ImportError: - GLFW_X11_WM_CLASS_NAME = GLFW_X11_WM_CLASS_CLASS = None - def load_all_shaders(): load_shader_programs() @@ -99,6 +94,7 @@ def main(): sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading + base = os.path.dirname(os.path.abspath(__file__)) if isosx: ensure_osx_locale() try: @@ -137,10 +133,12 @@ def main(): return opts = create_opts(args) change_wcwidth(not opts.use_system_wcwidth) - if GLFW_X11_WM_CLASS_CLASS is not None: - glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, args.cls) - if not glfw_init(): + glfw_module = 'cocoa' if isosx else 'x11' + if not glfw_init(os.path.join(base, 'glfw-{}.so'.format(glfw_module))): raise SystemExit('GLFW initialization failed') + if glfw_module == 'x11': + glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, args.cls) + glfw_init_hint_string(GLFW_X11_WM_CLASS_NAME, args.cls) try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies diff --git a/kitty/mouse.c b/kitty/mouse.c index 277ba012a..6c11a453b 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -10,7 +10,7 @@ #include "lineops.h" #include #include -#include +#include "glfw-wrapper.h" static MouseShape mouse_cursor_shape = BEAM; typedef enum MouseActions { PRESS, RELEASE, DRAG, MOVE } MouseAction; diff --git a/setup.py b/setup.py index 2893e6ae0..d21eb8cd3 100755 --- a/setup.py +++ b/setup.py @@ -202,15 +202,10 @@ def kitty_env(): font_libs = pkg_config('fontconfig', '--libs') cflags.extend(pkg_config('harfbuzz', '--cflags-only-I')) font_libs.extend(pkg_config('harfbuzz', '--libs')) - cflags.extend(pkg_config('glfw3', '--cflags-only-I')) pylib = get_python_flags(cflags) - if isosx: - glfw_ldflags = pkg_config('--libs', '--static', 'glfw3' - ) + ['-framework', 'OpenGL'] - else: - glfw_ldflags = pkg_config('glfw3', '--libs') + gl_libs = ['-framework', 'OpenGL'] if isosx else pkg_config('gl', '--libs') libpng = pkg_config('libpng', '--libs') - ans.ldpaths += pylib + font_libs + glfw_ldflags + libpng + [ + ans.ldpaths += pylib + font_libs + gl_libs + libpng + [ '-lunistring' ] if not isosx: