From 8b574030a847febcf90f365a9084dec1f2157d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 7 Apr 2024 19:26:01 +0200 Subject: [PATCH 01/10] Cocoa: Remove support for OS X 10.10 Yosemite Fixes #2506 --- .github/workflows/build.yml | 2 +- README.md | 3 ++- include/GLFW/glfw3.h | 4 ++-- src/cocoa_monitor.m | 6 +++--- src/cocoa_window.m | 6 ------ src/nsgl_context.m | 5 +---- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e980c547..8ef9ed79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: timeout-minutes: 4 env: CFLAGS: -Werror - MACOSX_DEPLOYMENT_TARGET: 10.8 + MACOSX_DEPLOYMENT_TARGET: 10.11 CMAKE_OSX_ARCHITECTURES: x86_64;arm64 steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 2718e45e..ca8850e9 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ more information. ## System requirements -GLFW supports Windows XP and later and macOS 10.8 and later. Linux and other +GLFW supports Windows XP and later and macOS 10.11 and later. Linux and other Unix-like systems running the X Window System are supported even without a desktop environment or modern extensions, although some features require a running window or clipboard manager. The OSMesa backend requires Mesa 6.3. @@ -123,6 +123,7 @@ information on what to include when reporting a bug. - Added `GLFW_UNLIMITED_MOUSE_BUTTONS` input mode that allows mouse buttons beyond the limit of the mouse button tokens to be reported (#2423) + - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) - [Wayland] Bugfix: The fractional scaling related objects were not destroyed - [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517) - [Null] Added Vulkan 'window' surface creation via `VK_EXT_headless_surface` diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index bed739dc..79b06288 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3183,8 +3183,8 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value); * * [bundle-guide]: https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/ * - * @remark @macos On OS X 10.10 and later the window frame will not be rendered - * at full resolution on Retina displays unless the + * @remark @macos The window frame will not be rendered at full resolution on + * Retina displays unless the * [GLFW_SCALE_FRAMEBUFFER](@ref GLFW_SCALE_FRAMEBUFFER_hint) * hint is `GLFW_TRUE` and the `NSHighResolutionCapable` key is enabled in the * application bundle's `Info.plist`. For more information, see diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 1abf6ff5..6495e1f3 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -137,7 +137,7 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode) if (flags & kDisplayModeStretchedFlag) return GLFW_FALSE; -#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 +#if MAC_OS_X_VERSION_MAX_ALLOWED == 101100 CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) && CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0)) @@ -164,7 +164,7 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode, if (result.refreshRate == 0) result.refreshRate = (int) round(fallbackRefreshRate); -#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 +#if MAC_OS_X_VERSION_MAX_ALLOWED == 101100 CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0) { @@ -180,7 +180,7 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode, result.blueBits = 8; } -#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 +#if MAC_OS_X_VERSION_MAX_ALLOWED == 101100 CFRelease(format); #endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ return result; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 780bc7d3..97626a90 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -310,7 +310,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)windowDidChangeOcclusionState:(NSNotification* )notification { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 if ([window->ns.object respondsToSelector:@selector(occlusionState)]) { if ([window->ns.object occlusionState] & NSWindowOcclusionStateVisible) @@ -318,7 +317,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; else window->ns.occluded = GLFW_TRUE; } -#endif } @end @@ -1950,7 +1948,6 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, { @autoreleasepool { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 // HACK: Dynamically load Core Animation to avoid adding an extra // dependency for the majority who don't use MoltenVK NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"]; @@ -2027,9 +2024,6 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, } return err; -#else - return VK_ERROR_EXTENSION_NOT_PRESENT; -#endif } // autoreleasepool } diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 57f117ba..e728fc6e 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -218,14 +218,11 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, ADD_ATTRIB(kCGLPFASupportsAutomaticGraphicsSwitching); } -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 if (ctxconfig->major >= 4) { SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); } - else -#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ - if (ctxconfig->major >= 3) + else if (ctxconfig->major >= 3) { SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); } From 97892c60373f2e3c12e3f119d3788ad38a18c170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 7 Apr 2024 19:39:52 +0200 Subject: [PATCH 02/10] Cocoa: Add QuartzCore as a link-time dependency --- README.md | 1 + docs/build.md | 6 +++--- src/CMakeLists.txt | 5 +++-- src/cocoa_window.m | 14 +++----------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ca8850e9..9447dcf1 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ information on what to include when reporting a bug. - Added `GLFW_UNLIMITED_MOUSE_BUTTONS` input mode that allows mouse buttons beyond the limit of the mouse button tokens to be reported (#2423) + - [Cocoa] Added `QuartzCore` framework as link-time dependency - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) - [Wayland] Bugfix: The fractional scaling related objects were not destroyed - [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517) diff --git a/docs/build.md b/docs/build.md index ab4b6817..7b0f8bfe 100644 --- a/docs/build.md +++ b/docs/build.md @@ -390,8 +390,8 @@ If you are using the dynamic library version of GLFW, add it to the project dependencies. If you are using the static library version of GLFW, add it and the Cocoa, -OpenGL and IOKit frameworks to the project as dependencies. They can all be -found in `/System/Library/Frameworks`. +OpenGL, IOKit and QuartzCore frameworks to the project as dependencies. They +can all be found in `/System/Library/Frameworks`. ### With command-line or makefile on macOS {#build_link_osx} @@ -405,7 +405,7 @@ command-line yourself using the `-l` and `-framework` switches. If you are using the dynamic GLFW library, which is named `libglfw.3.dylib`, do: ```sh -cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit +cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework QuartzCore ``` If you are using the static library, named `libglfw3.a`, substitute `-lglfw3` diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1057a6f9..463b898d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -151,10 +151,11 @@ endif() if (GLFW_BUILD_COCOA) target_link_libraries(glfw PRIVATE "-framework Cocoa" "-framework IOKit" - "-framework CoreFoundation") + "-framework CoreFoundation" + "-framework QuartzCore") set(glfw_PKG_DEPS "") - set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation") + set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation -framework QuartzCore") endif() if (GLFW_BUILD_WAYLAND) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 97626a90..e69b5fe0 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -28,6 +28,8 @@ #if defined(_GLFW_COCOA) +#import + #include #include #include @@ -1948,18 +1950,8 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, { @autoreleasepool { - // HACK: Dynamically load Core Animation to avoid adding an extra - // dependency for the majority who don't use MoltenVK - NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"]; - if (!bundle) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Cocoa: Failed to find QuartzCore.framework"); - return VK_ERROR_EXTENSION_NOT_PRESENT; - } - // NOTE: Create the layer here as makeBackingLayer should not return nil - window->ns.layer = [[bundle classNamed:@"CAMetalLayer"] layer]; + window->ns.layer = [CAMetalLayer layer]; if (!window->ns.layer) { _glfwInputError(GLFW_PLATFORM_ERROR, From dfebad786d2bc00b2d63ff71b3fbeb75a1e513d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 7 Apr 2024 20:03:37 +0200 Subject: [PATCH 03/10] Update macOS OpenGL compatibility notes --- docs/compat.md | 35 +++++++++++++++++++---------------- src/nsgl_context.m | 8 ++++---- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/compat.md b/docs/compat.md index ef64b0cc..5072d5c1 100644 --- a/docs/compat.md +++ b/docs/compat.md @@ -242,24 +242,27 @@ extensions are unavailable, the `GLFW_SRGB_CAPABLE` hint will have no effect. ## OpenGL on macOS {#compat_osx} -Support for OpenGL 3.2 and above was introduced with OS X 10.7 and even then -only forward-compatible, core profile contexts are supported. Support for -OpenGL 4.1 was introduced with OS X 10.9, also limited to forward-compatible, -core profile contexts. There is also still no mechanism for requesting debug -contexts or no-error contexts. Versions of Mac OS X earlier than 10.7 support -at most OpenGL version 2.1. +macOS (as of version 14) still provides OpenGL but it has been deprecated by +Apple. While the API is still available, it is poorly maintained and frequently +develops new issues. On modern systems, OpenGL is implemented on top of Metal +and is not fully thread-safe. -Because of this, on OS X 10.7 and later, the `GLFW_CONTEXT_VERSION_MAJOR` and -`GLFW_CONTEXT_VERSION_MINOR` hints will cause @ref glfwCreateWindow to fail if -given version 3.0 or 3.1. The `GLFW_OPENGL_PROFILE` hint must be set to -`GLFW_OPENGL_CORE_PROFILE` when creating OpenGL 3.2 and later contexts. The -`GLFW_CONTEXT_DEBUG` and `GLFW_CONTEXT_NO_ERROR` hints are ignored. +macOS does not support OpenGL stereo rendering. If the `GLFW_STEREO` hint is +set to true, OpenGL context creation will always fail. -Also, on Mac OS X 10.6 and below, the `GLFW_CONTEXT_VERSION_MAJOR` and -`GLFW_CONTEXT_VERSION_MINOR` hints will fail if given a version above 2.1, -setting the `GLFW_OPENGL_PROFILE` or `GLFW_OPENGL_FORWARD_COMPAT` hints to -a non-default value will cause @ref glfwCreateWindow to fail and the -`GLFW_CONTEXT_DEBUG` hint is ignored. +macOS only supports OpenGL core profile contexts that are forward-compatible, +but the `GLFW_OPENGL_FORWARD_COMPAT` hint is ignored since GLFW 3.4. Even if +this hint is set to false (the default), a forward-compatible context will be +returned if available. + +macOS does not support OpenGL debug contexts, no-error contexts or robustness. +The `GLFW_CONTEXT_DEBUG`, `GLFW_CONTEXT_NO_ERROR` and `GLFW_CONTEXT_ROBUSTNESS` +hints will be ignored and a context without these features will be returned. + +macOS does not flush OpenGL contexts when they are made non-current. The +`GLFW_CONTEXT_RELEASE_BEHAVIOR` hint is ignored and the release behavior will +always be the equivalent of `GLFW_RELEASE_BEHAVIOR_NONE`. If you need a context +to be flushed, call `glFlush` before making it non-current. ## Vulkan loader and API {#compat_vulkan} diff --git a/src/nsgl_context.m b/src/nsgl_context.m index e728fc6e..df729800 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -183,16 +183,16 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, return GLFW_FALSE; } - // Context robustness modes (GL_KHR_robustness) are not yet supported by + // Context robustness modes (GL_KHR_robustness) are not supported by // macOS but are not a hard constraint, so ignore and continue - // Context release behaviors (GL_KHR_context_flush_control) are not yet + // Context release behaviors (GL_KHR_context_flush_control) are not // supported by macOS but are not a hard constraint, so ignore and continue - // Debug contexts (GL_KHR_debug) are not yet supported by macOS but are not + // Debug contexts (GL_KHR_debug) are not supported by macOS but are not // a hard constraint, so ignore and continue - // No-error contexts (GL_KHR_no_error) are not yet supported by macOS but + // No-error contexts (GL_KHR_no_error) are not supported by macOS but // are not a hard constraint, so ignore and continue #define ADD_ATTRIB(a) \ From 51b6434ac46a3a8b852679486f57b5e924b312dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 8 Apr 2024 18:50:08 +0200 Subject: [PATCH 04/10] Wayland: Fix possible segfault on drag enter Found with Clang static analysis. --- README.md | 1 + src/wl_window.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9447dcf1..10044faf 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ information on what to include when reporting a bug. - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) - [Wayland] Bugfix: The fractional scaling related objects were not destroyed - [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517) + - [Wayland] Bugfix: A drag entering a non-GLFW surface could cause a segfault - [Null] Added Vulkan 'window' surface creation via `VK_EXT_headless_surface` - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless` - [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to diff --git a/src/wl_window.c b/src/wl_window.c index dc7dcd07..7ace6b4b 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1986,7 +1986,7 @@ static void dataDeviceHandleEnter(void* userData, window = wl_surface_get_user_data(surface); } - if (surface == window->wl.surface && _glfw.wl.offers[i].text_uri_list) + if (window && surface == window->wl.surface && _glfw.wl.offers[i].text_uri_list) { _glfw.wl.dragOffer = offer; _glfw.wl.dragFocus = window; From 64906f8e64c873399025fc78133e8616173713cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 8 Apr 2024 18:50:08 +0200 Subject: [PATCH 05/10] Wayland: Cleanup --- src/wl_window.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 7ace6b4b..96f80399 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1974,41 +1974,41 @@ static void dataDeviceHandleEnter(void* userData, _glfw.wl.dragFocus = NULL; } - for (unsigned int i = 0; i < _glfw.wl.offerCount; i++) + unsigned int i; + + for (i = 0; i < _glfw.wl.offerCount; i++) { if (_glfw.wl.offers[i].offer == offer) + break; + } + + if (i == _glfw.wl.offerCount) + return; + + if (surface && wl_proxy_get_tag((struct wl_proxy*) surface) == &_glfw.wl.tag) + { + _GLFWwindow* window = wl_surface_get_user_data(surface); + if (window->wl.surface == surface) { - _GLFWwindow* window = NULL; - - if (surface) - { - if (wl_proxy_get_tag((struct wl_proxy*) surface) == &_glfw.wl.tag) - window = wl_surface_get_user_data(surface); - } - - if (window && surface == window->wl.surface && _glfw.wl.offers[i].text_uri_list) + if (_glfw.wl.offers[i].text_uri_list) { _glfw.wl.dragOffer = offer; _glfw.wl.dragFocus = window; _glfw.wl.dragSerial = serial; - } - _glfw.wl.offers[i] = _glfw.wl.offers[_glfw.wl.offerCount - 1]; - _glfw.wl.offerCount--; - break; + wl_data_offer_accept(offer, serial, "text/uri-list"); + } } } - if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) - return; - - if (_glfw.wl.dragOffer) - wl_data_offer_accept(offer, serial, "text/uri-list"); - else + if (!_glfw.wl.dragOffer) { wl_data_offer_accept(offer, serial, NULL); wl_data_offer_destroy(offer); } + + _glfw.wl.offers[i] = _glfw.wl.offers[_glfw.wl.offerCount - 1]; + _glfw.wl.offerCount--; } static void dataDeviceHandleLeave(void* userData, From b35641f4a3c62aa86a0b3c983d163bc0fe36026d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 12 Apr 2024 18:25:19 +0200 Subject: [PATCH 06/10] Wayland: Cleanup --- src/wl_window.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 96f80399..2e842aaa 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -2042,15 +2042,17 @@ static void dataDeviceHandleDrop(void* userData, int count; char** paths = _glfwParseUriList(string, &count); if (paths) + { _glfwInputDrop(_glfw.wl.dragFocus, count, (const char**) paths); - for (int i = 0; i < count; i++) - _glfw_free(paths[i]); + for (int i = 0; i < count; i++) + _glfw_free(paths[i]); - _glfw_free(paths); + _glfw_free(paths); + } + + _glfw_free(string); } - - _glfw_free(string); } static void dataDeviceHandleSelection(void* userData, From 043378876a67b092f5d0d3d9748660121a336dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 9 May 2024 17:18:39 +0200 Subject: [PATCH 07/10] Use CMakePushCheckState for check state management --- src/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 463b898d..7a8726d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -313,30 +313,34 @@ if (GLFW_BUILD_SHARED_LIBRARY) if (MINGW) # Enable link-time exploit mitigation features enabled by default on MSVC include(CheckCCompilerFlag) + include(CMakePushCheckState) # Compatibility with data execution prevention (DEP) + cmake_push_check_state() set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") check_c_compiler_flag("" _GLFW_HAS_DEP) if (_GLFW_HAS_DEP) target_link_libraries(glfw PRIVATE "-Wl,--nxcompat") endif() + cmake_pop_check_state() # Compatibility with address space layout randomization (ASLR) + cmake_push_check_state() set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") check_c_compiler_flag("" _GLFW_HAS_ASLR) if (_GLFW_HAS_ASLR) target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase") endif() + cmake_pop_check_state() # Compatibility with 64-bit address space layout randomization (ASLR) + cmake_push_check_state() set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va") check_c_compiler_flag("" _GLFW_HAS_64ASLR) if (_GLFW_HAS_64ASLR) target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va") endif() - - # Clear flags again to avoid breaking later tests - set(CMAKE_REQUIRED_FLAGS) + cmake_pop_check_state() endif() if (UNIX) From b850107a32e96ae36dc7b5f88cd337016e356404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 10 May 2024 15:15:12 +0200 Subject: [PATCH 08/10] Update minimum CMake version to 3.16 This replaces some workarounds and manual logic with new features available with CMake 3.16, including list(FILTER), list(JOIN), foreach(IN LISTS) and enable_language(OBJC). Policy settings no longer needed with 3.16 have been removed. Related to #2541 --- CMake/GenerateMappings.cmake | 36 +++++++++++++++++++----------------- CMakeLists.txt | 31 +++---------------------------- README.md | 3 ++- docs/compile.md | 4 ++-- src/CMakeLists.txt | 16 +++------------- 5 files changed, 29 insertions(+), 61 deletions(-) diff --git a/CMake/GenerateMappings.cmake b/CMake/GenerateMappings.cmake index c8c9e23f..9a95df6d 100644 --- a/CMake/GenerateMappings.cmake +++ b/CMake/GenerateMappings.cmake @@ -1,6 +1,8 @@ # Usage: # cmake -P GenerateMappings.cmake +cmake_policy(VERSION 3.16) + set(source_url "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt") set(source_path "${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt") set(template_path "${CMAKE_ARGV3}") @@ -22,24 +24,24 @@ if (status_code) endif() file(STRINGS "${source_path}" lines) -foreach(line ${lines}) - if (line MATCHES "^[0-9a-fA-F]") - if (line MATCHES "platform:Windows") - if (GLFW_WIN32_MAPPINGS) - string(APPEND GLFW_WIN32_MAPPINGS "\n") - endif() - string(APPEND GLFW_WIN32_MAPPINGS "\"${line}\",") - elseif (line MATCHES "platform:Mac OS X") - if (GLFW_COCOA_MAPPINGS) - string(APPEND GLFW_COCOA_MAPPINGS "\n") - endif() - string(APPEND GLFW_COCOA_MAPPINGS "\"${line}\",") - elseif (line MATCHES "platform:Linux") - if (GLFW_LINUX_MAPPINGS) - string(APPEND GLFW_LINUX_MAPPINGS "\n") - endif() - string(APPEND GLFW_LINUX_MAPPINGS "\"${line}\",") +list(FILTER lines INCLUDE REGEX "^[0-9a-fA-F]") + +foreach(line IN LISTS lines) + if (line MATCHES "platform:Windows") + if (GLFW_WIN32_MAPPINGS) + string(APPEND GLFW_WIN32_MAPPINGS "\n") endif() + string(APPEND GLFW_WIN32_MAPPINGS "\"${line}\",") + elseif (line MATCHES "platform:Mac OS X") + if (GLFW_COCOA_MAPPINGS) + string(APPEND GLFW_COCOA_MAPPINGS "\n") + endif() + string(APPEND GLFW_COCOA_MAPPINGS "\"${line}\",") + elseif (line MATCHES "platform:Linux") + if (GLFW_LINUX_MAPPINGS) + string(APPEND GLFW_LINUX_MAPPINGS "\n") + endif() + string(APPEND GLFW_LINUX_MAPPINGS "\"${line}\",") endif() endforeach() diff --git a/CMakeLists.txt b/CMakeLists.txt index 830f8fd9..398b36eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,6 @@ -cmake_minimum_required(VERSION 3.4...3.28 FATAL_ERROR) +cmake_minimum_required(VERSION 3.16...3.28 FATAL_ERROR) -project(GLFW VERSION 3.5.0 LANGUAGES C) - -if (POLICY CMP0069) - cmake_policy(SET CMP0069 NEW) -endif() - -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() +project(GLFW VERSION 3.5.0 LANGUAGES C HOMEPAGE_URL "https://www.glfw.org/") set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -80,24 +72,7 @@ endif() # This is here because it also applies to tests and examples #-------------------------------------------------------------------- if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) - if (CMAKE_VERSION VERSION_LESS 3.15) - foreach (flag CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELWITHDEBINFO) - - if (flag MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") - endif() - if (flag MATCHES "/MDd") - string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") - endif() - - endforeach() - else() - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() #-------------------------------------------------------------------- diff --git a/README.md b/README.md index 10044faf..fb77b9dd 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ in the documentation for more information. ## Dependencies -GLFW itself needs only CMake 3.4 or later and the headers and libraries for your +GLFW itself needs only CMake 3.16 or later and the headers and libraries for your OS and window system. The examples and test programs depend on a number of tiny libraries. These are @@ -123,6 +123,7 @@ information on what to include when reporting a bug. - Added `GLFW_UNLIMITED_MOUSE_BUTTONS` input mode that allows mouse buttons beyond the limit of the mouse button tokens to be reported (#2423) + - Updated minimum CMake version to 3.16 (#2541) - [Cocoa] Added `QuartzCore` framework as link-time dependency - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) - [Wayland] Bugfix: The fractional scaling related objects were not destroyed diff --git a/docs/compile.md b/docs/compile.md index f8385fef..6b0b7122 100644 --- a/docs/compile.md +++ b/docs/compile.md @@ -264,8 +264,8 @@ __USE_MSVC_RUNTIME_LIBRARY_DLL__ determines whether to use the DLL version or th static library version of the Visual C++ runtime library. When enabled, the DLL version of the Visual C++ library is used. This is enabled by default. -On CMake 3.15 and later you can set the standard CMake [CMAKE_MSVC_RUNTIME_LIBRARY][] -variable instead of this GLFW-specific option. +It is recommended to set the standard CMake variable [CMAKE_MSVC_RUNTIME_LIBRARY][] +instead of this GLFW-specific option. [CMAKE_MSVC_RUNTIME_LIBRARY]: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a8726d1..fc4e17cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,6 +30,7 @@ add_custom_target(update_mappings set_target_properties(update_mappings PROPERTIES FOLDER "GLFW3") if (GLFW_BUILD_COCOA) + enable_language(OBJC) target_compile_definitions(glfw PRIVATE _GLFW_COCOA) target_sources(glfw PRIVATE cocoa_platform.h cocoa_joystick.h cocoa_init.m cocoa_joystick.m cocoa_monitor.m cocoa_window.m @@ -137,13 +138,6 @@ target_include_directories(glfw PRIVATE "${GLFW_BINARY_DIR}/src") target_link_libraries(glfw PRIVATE Threads::Threads) -# Workaround for CMake not knowing about .m files before version 3.16 -if (CMAKE_VERSION VERSION_LESS "3.16" AND APPLE) - set_source_files_properties(cocoa_init.m cocoa_joystick.m cocoa_monitor.m - cocoa_window.m nsgl_context.m PROPERTIES - LANGUAGE C) -endif() - if (GLFW_BUILD_WIN32) list(APPEND glfw_PKG_LIBS "-lgdi32") endif() @@ -349,12 +343,8 @@ if (GLFW_BUILD_SHARED_LIBRARY) endif() endif() -foreach(arg ${glfw_PKG_DEPS}) - string(APPEND deps " ${arg}") -endforeach() -foreach(arg ${glfw_PKG_LIBS}) - string(APPEND libs " ${arg}") -endforeach() +list(JOIN glfw_PKG_DEPS " " deps) +list(JOIN glfw_PKG_LIBS " " libs) set(GLFW_PKG_CONFIG_REQUIRES_PRIVATE "${deps}" CACHE INTERNAL "GLFW pkg-config Requires.private") From a576a56a8d6a3f17569e3d46f85365dc159c7408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 10 May 2024 17:05:49 +0200 Subject: [PATCH 09/10] Remove unused CMake find module for OSMesa --- CMake/modules/FindOSMesa.cmake | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 CMake/modules/FindOSMesa.cmake diff --git a/CMake/modules/FindOSMesa.cmake b/CMake/modules/FindOSMesa.cmake deleted file mode 100644 index 3194bd91..00000000 --- a/CMake/modules/FindOSMesa.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Try to find OSMesa on a Unix system -# -# This will define: -# -# OSMESA_LIBRARIES - Link these to use OSMesa -# OSMESA_INCLUDE_DIR - Include directory for OSMesa -# -# Copyright (c) 2014 Brandon Schaefer - -if (NOT WIN32) - - find_package (PkgConfig) - pkg_check_modules (PKG_OSMESA QUIET osmesa) - - set (OSMESA_INCLUDE_DIR ${PKG_OSMESA_INCLUDE_DIRS}) - set (OSMESA_LIBRARIES ${PKG_OSMESA_LIBRARIES}) - -endif () From 21fea01161e0d6b70c0c5c1f52dc8e7a7df14a50 Mon Sep 17 00:00:00 2001 From: LocalSpook Date: Sun, 10 Dec 2023 05:54:11 -0700 Subject: [PATCH 10/10] Wayland: Replace _glfwKeySym2Unicode with xkbcommon libxkbcommon already provides functions to convert keysyms to codepoints and UTF-8. The library has offered these functions since 0.5.0[1], so using them won't cause any compatibility problems. [1] https://xkbcommon.org/doc/0.5.0/group__keysyms.html Closes #2444 --- src/CMakeLists.txt | 4 ++-- src/wl_init.c | 4 ++++ src/wl_platform.h | 7 ++++++- src/wl_window.c | 28 ++++++++++++++-------------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc4e17cf..1a085b2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,8 +53,8 @@ endif() if (GLFW_BUILD_WAYLAND) target_compile_definitions(glfw PRIVATE _GLFW_WAYLAND) - target_sources(glfw PRIVATE wl_platform.h xkb_unicode.h wl_init.c - wl_monitor.c wl_window.c xkb_unicode.c) + target_sources(glfw PRIVATE wl_platform.h wl_init.c + wl_monitor.c wl_window.c) endif() if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND) diff --git a/src/wl_init.c b/src/wl_init.c index 76054bc6..ef9e4503 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -711,6 +711,10 @@ int _glfwInitWayland(void) _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_get_status"); _glfw.wl.xkb.compose_state_get_one_sym = (PFN_xkb_compose_state_get_one_sym) _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_get_one_sym"); + _glfw.wl.xkb.keysym_to_utf32 = (PFN_xkb_keysym_to_utf32) + _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keysym_to_utf32"); + _glfw.wl.xkb.keysym_to_utf8 = (PFN_xkb_keysym_to_utf8) + _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keysym_to_utf8"); if (!_glfw.wl.xkb.context_new || !_glfw.wl.xkb.context_unref || diff --git a/src/wl_platform.h b/src/wl_platform.h index f3e8cba2..afa6f50a 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -42,7 +42,6 @@ typedef struct VkWaylandSurfaceCreateInfoKHR typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWaylandSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*); -#include "xkb_unicode.h" #include "posix_poll.h" typedef int (* PFN_wl_display_flush)(struct wl_display* display); @@ -178,6 +177,8 @@ typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, con typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t); typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t); typedef int (* PFN_xkb_state_mod_index_is_active)(struct xkb_state*,xkb_mod_index_t,enum xkb_state_component); +typedef uint32_t (* PFN_xkb_keysym_to_utf32)(xkb_keysym_t); +typedef int (* PFN_xkb_keysym_to_utf8)(xkb_keysym_t, char*, size_t); #define xkb_context_new _glfw.wl.xkb.context_new #define xkb_context_unref _glfw.wl.xkb.context_unref #define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string @@ -191,6 +192,8 @@ typedef int (* PFN_xkb_state_mod_index_is_active)(struct xkb_state*,xkb_mod_inde #define xkb_state_update_mask _glfw.wl.xkb.state_update_mask #define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout #define xkb_state_mod_index_is_active _glfw.wl.xkb.state_mod_index_is_active +#define xkb_keysym_to_utf32 _glfw.wl.xkb.keysym_to_utf32 +#define xkb_keysym_to_utf8 _glfw.wl.xkb.keysym_to_utf8 typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags); typedef void (* PFN_xkb_compose_table_unref)(struct xkb_compose_table*); @@ -495,6 +498,8 @@ typedef struct _GLFWlibraryWayland PFN_xkb_state_update_mask state_update_mask; PFN_xkb_state_key_get_layout state_key_get_layout; PFN_xkb_state_mod_index_is_active state_mod_index_is_active; + PFN_xkb_keysym_to_utf32 keysym_to_utf32; + PFN_xkb_keysym_to_utf8 keysym_to_utf8; PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale; PFN_xkb_compose_table_unref compose_table_unref; diff --git a/src/wl_window.c b/src/wl_window.c index 2e842aaa..72c1a402 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1192,8 +1192,8 @@ static void inputText(_GLFWwindow* window, uint32_t scancode) if (xkb_state_key_get_syms(_glfw.wl.xkb.state, keycode, &keysyms) == 1) { const xkb_keysym_t keysym = composeSymbol(keysyms[0]); - const uint32_t codepoint = _glfwKeySym2Unicode(keysym); - if (codepoint != GLFW_INVALID_CODEPOINT) + const uint32_t codepoint = xkb_keysym_to_utf32(keysym); + if (codepoint != 0) { const int mods = _glfw.wl.xkb.modifiers; const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT)); @@ -2721,23 +2721,23 @@ const char* _glfwGetScancodeNameWayland(int scancode) return NULL; } - const uint32_t codepoint = _glfwKeySym2Unicode(keysyms[0]); - if (codepoint == GLFW_INVALID_CODEPOINT) + // WORKAROUND: xkb_keysym_to_utf8() requires the third parameter (size of the output buffer) + // to be at least 7 (6 bytes + a null terminator), because it was written when UTF-8 + // sequences could be up to 6 bytes long. The _glfw.wl.keynames buffers are only 5 bytes + // long, because UTF-8 sequences are now limited to 4 bytes and no codepoints were ever assigned + // that needed more than that. To work around this, we first copy to a temporary buffer. + // + // See: https://github.com/xkbcommon/libxkbcommon/issues/418 + char temp_buffer[7]; + const int bytes_written = xkb_keysym_to_utf8(keysyms[0], temp_buffer, sizeof(temp_buffer)); + if (bytes_written <= 0 || bytes_written > 5) { _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Failed to retrieve codepoint for key name"); + "Wayland: Failed to encode keysym as UTF-8"); return NULL; } + memcpy(_glfw.wl.keynames[key], temp_buffer, bytes_written); - const size_t count = _glfwEncodeUTF8(_glfw.wl.keynames[key], codepoint); - if (count == 0) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Failed to encode codepoint for key name"); - return NULL; - } - - _glfw.wl.keynames[key][count] = '\0'; return _glfw.wl.keynames[key]; }