From e0b3361683045475b46cc20cbebececba0a81e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 7 Oct 2020 22:50:54 +0200 Subject: [PATCH 01/21] Win32: Enable /W3 on VS for library sources /W3 is the default for new VS projects and the library builds cleanly with it on VS 2010-2019 so let's try to keep it that way. (cherry picked from commit 6b78419c9ae8d504e3b44adab51645d89c23108c) --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c1a1d7f..9519597d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -120,12 +120,14 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") COMPILE_FLAGS -Wdeclaration-after-statement) endif() +# Enable a reasonable set of warnings if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") - # Enable a reasonable set of warnings (no, -Wextra is not reasonable) target_compile_options(glfw PRIVATE "-Wall") +elseif (MSVC) + target_compile_options(glfw PRIVATE "/W3") endif() if (WIN32) From 7dee4e05f92052ccb289a7bf565a7e889a33f42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 7 Oct 2020 22:51:58 +0200 Subject: [PATCH 02/21] Win32: Fix clang-cl interpreting -Wall as /Wall Unlike -Wall, VS /Wall really means all warnings. Closes #1780. (cherry picked from commit ac627706ef93362caf08bd3bf249656efd9151e8) --- README.md | 1 + src/CMakeLists.txt | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3af3efe..1a1f0316 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,7 @@ skills. - Eloi Marín Gratacós - Stefan Gustavson - Jonathan Hale + - hdf89shfdfs - Sylvain Hellegouarch - Matthew Henry - heromyth diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9519597d..402f8f6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,7 +125,12 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") - target_compile_options(glfw PRIVATE "-Wall") + if ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + # Tell Clang-CL that this is a Clang flag + target_compile_options(glfw PRIVATE "/clang:-Wall") + else() + target_compile_options(glfw PRIVATE "-Wall") + endif() elseif (MSVC) target_compile_options(glfw PRIVATE "/W3") endif() From 395ab660d5daceb5191531c39e3b9ce32ce9efa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 7 Oct 2020 23:35:17 +0200 Subject: [PATCH 03/21] Win32: Filter out duplicate size events This mirrors the filtering done on X11 and Cocoa. Possibly this should be done by shared code instead. Fixes #1610. (cherry picked from commit 0bccc3852b903e690e77e66d2486fb33166e112d) --- README.md | 2 ++ src/win32_platform.h | 3 +++ src/win32_window.c | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a1f0316..ce29513e 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ information on what to include when reporting a bug. - [Win32] Bugfix: Monitor functions could return invalid values after configuration change (#1761) - [Win32] Bugfix: Initialization would segfault on Windows 8 (not 8.1) (#1775) + - [Win32] Bugfix: Duplicate size events were not filtered (#1610) - [Cocoa] Changed `EGLNativeWindowType` from `NSView` to `CALayer` (#1169) - [Cocoa] Bugfix: Non-BMP Unicode codepoint input was reported as UTF-16 (#1635) @@ -254,6 +255,7 @@ skills. - Shane Liesegang - Anders Lindqvist - Leon Linhart + - Marco Lizza - Eyal Lotem - Aaron Loucks - Luflosi diff --git a/src/win32_platform.h b/src/win32_platform.h index 7305fd28..003b8a14 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -321,6 +321,9 @@ typedef struct _GLFWwindowWin32 GLFWbool transparent; GLFWbool scaleToMonitor; + // Cached size used to filter out duplicate events + int width, height; + // The last received cursor position, regardless of source int lastCursorPosX, lastCursorPosY; // The last recevied high surrogate when decoding pairs of UTF-16 messages diff --git a/src/win32_window.c b/src/win32_window.c index f76f560f..15fe2aa9 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -954,6 +954,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_SIZE: { + const int width = LOWORD(lParam); + const int height = HIWORD(lParam); const GLFWbool iconified = wParam == SIZE_MINIMIZED; const GLFWbool maximized = wParam == SIZE_MAXIMIZED || (window->win32.maximized && @@ -968,8 +970,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (window->win32.maximized != maximized) _glfwInputWindowMaximize(window, maximized); - _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam)); - _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); + if (width != window->win32.width || height != window->win32.height) + { + window->win32.width = width; + window->win32.height = height; + + _glfwInputFramebufferSize(window, width, height); + _glfwInputWindowSize(window, width, height); + } if (window->monitor && window->win32.iconified != iconified) { @@ -1307,6 +1315,8 @@ static int createNativeWindow(_GLFWwindow* window, window->win32.transparent = GLFW_TRUE; } + _glfwPlatformGetWindowSize(window, &window->win32.width, &window->win32.height); + return GLFW_TRUE; } From baf26a6ea792f032c27a6853fb375d281e35ffc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 18 Oct 2020 19:34:23 +0200 Subject: [PATCH 04/21] Cocoa: Fix ObjC being built as C with CMake 3.19 CMake 3.19 adds -xc when the LANGUAGE file property is C, breaking our workaround for CMake 3.15 and earlier not understanding the .m suffix. Fixes #1787. (cherry picked from commit 3327050ca66ad34426a82c217c2d60ced61526b7) --- README.md | 2 ++ src/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce29513e..deb2c609 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ information on what to include when reporting a bug. (#1635) - [Cocoa] Bugfix: Failing to retrieve the refresh rate of built-in displays could leak memory + - [Cocoa] Bugfix: Objective-C files were compiled as C with CMake 3.19 (#1787) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors @@ -250,6 +251,7 @@ skills. - Konstantin Käfer - Eric Larson - Francis Lecavalier + - Jong Won Lee - Robin Leffmann - Glenn Lewis - Shane Liesegang diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 402f8f6f..e18b14aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,8 +72,8 @@ if (_GLFW_X11 OR _GLFW_WAYLAND) endif() endif() -if (APPLE) - # For some reason CMake didn't know about .m until version 3.16 +# 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) From b31d7ddc8c64870a0e9945cc0ac16c361154a803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20K=C3=B6nig?= Date: Wed, 28 Oct 2020 19:23:28 +0100 Subject: [PATCH 05/21] Wayland: Fix destroying CSDs in the correct order On Wayland we implement Client-Side Decorations if the compositors do not implement SSDs. In that case, the destructors of the surfaces were called in the wrong order, leading to a dereference of an already freed object. We need to first destroy the subsurface before destroying the parent surface. Related PR on kitty: https://github.com/kovidgoyal/kitty/pull/3066 Related issue on kitty: https://github.com/kovidgoyal/kitty/issues/3051 Closes #1798. (cherry picked from commit 0dc1005c853e9bdd00448ca1a3405858790a9fef) --- README.md | 2 ++ src/wl_window.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index deb2c609..e0359e48 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: Retrieving partial framebuffer size would segfault - [Wayland] Bugfix: Scrolling offsets were inverted compared to other platforms (#1463) + - [Wayland] Bugfix: Client-Side Decorations were destroyed in the wrong worder ## Contact @@ -370,6 +371,7 @@ skills. - Santi Zupancic - Jonas Ådahl - Lasse Öörni + - Leonard König - All the unmentioned and anonymous contributors in the GLFW community, for bug reports, patches, feedback, testing and encouragement diff --git a/src/wl_window.c b/src/wl_window.c index f811fffc..d10861cd 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -312,10 +312,10 @@ static void createDecorations(_GLFWwindow* window) static void destroyDecoration(_GLFWdecorationWayland* decoration) { - if (decoration->surface) - wl_surface_destroy(decoration->surface); if (decoration->subsurface) wl_subsurface_destroy(decoration->subsurface); + if (decoration->surface) + wl_surface_destroy(decoration->surface); if (decoration->viewport) wp_viewport_destroy(decoration->viewport); decoration->surface = NULL; From edb6f674cdb19337e494c9b9f791cceae557ccbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 19 Nov 2020 02:49:14 +0100 Subject: [PATCH 06/21] Add missing changelog issue number (cherry picked from commit 7e8da57094281c73a0be5669a4b79686b4917f6c) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e0359e48..9c1d950c 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: Scrolling offsets were inverted compared to other platforms (#1463) - [Wayland] Bugfix: Client-Side Decorations were destroyed in the wrong worder + (#1798) ## Contact From 0d7acffd470c6dcd703904943ac46b469b2777d8 Mon Sep 17 00:00:00 2001 From: Bhee Date: Mon, 14 Dec 2020 02:37:20 -0500 Subject: [PATCH 07/21] Fix minor typo: If if -> If. (cherry picked from commit 0b9e48fa3df9c184ff1abfb2452fd1a4b696ecd8) --- docs/vulkan.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/vulkan.dox b/docs/vulkan.dox index 2585c2bb..68e3d5fe 100644 --- a/docs/vulkan.dox +++ b/docs/vulkan.dox @@ -93,7 +93,7 @@ if (glfwVulkanSupported()) This function returns `GLFW_TRUE` if the Vulkan loader and any minimally functional ICD was found. -If if one or both were not found, calling any other Vulkan related GLFW function +If one or both were not found, calling any other Vulkan related GLFW function will generate a @ref GLFW_API_UNAVAILABLE error. From cdd5ee8d36b20f1b161887da3e25352beea5f42b Mon Sep 17 00:00:00 2001 From: ashishgamedev <66940640+ashishgamedev@users.noreply.github.com> Date: Thu, 10 Dec 2020 19:48:55 +0530 Subject: [PATCH 08/21] Fix indentation in internal.h Closes #1818. (cherry picked from commit 761f97d6b600794062bc2c6055d7d09ae6a567fc) --- src/internal.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/internal.h b/src/internal.h index 92b9497a..91631c06 100644 --- a/src/internal.h +++ b/src/internal.h @@ -342,9 +342,9 @@ struct _GLFWcontext int robustness; int release; - PFNGLGETSTRINGIPROC GetStringi; + PFNGLGETSTRINGIPROC GetStringi; PFNGLGETINTEGERVPROC GetIntegerv; - PFNGLGETSTRINGPROC GetString; + PFNGLGETSTRINGPROC GetString; _GLFWmakecontextcurrentfun makeCurrent; _GLFWswapbuffersfun swapBuffers; @@ -396,23 +396,23 @@ struct _GLFWwindow _GLFWcontext context; struct { - GLFWwindowposfun pos; - GLFWwindowsizefun size; - GLFWwindowclosefun close; - GLFWwindowrefreshfun refresh; - GLFWwindowfocusfun focus; - GLFWwindowiconifyfun iconify; - GLFWwindowmaximizefun maximize; - GLFWframebuffersizefun fbsize; + GLFWwindowposfun pos; + GLFWwindowsizefun size; + GLFWwindowclosefun close; + GLFWwindowrefreshfun refresh; + GLFWwindowfocusfun focus; + GLFWwindowiconifyfun iconify; + GLFWwindowmaximizefun maximize; + GLFWframebuffersizefun fbsize; GLFWwindowcontentscalefun scale; - GLFWmousebuttonfun mouseButton; - GLFWcursorposfun cursorPos; - GLFWcursorenterfun cursorEnter; - GLFWscrollfun scroll; - GLFWkeyfun key; - GLFWcharfun character; - GLFWcharmodsfun charmods; - GLFWdropfun drop; + GLFWmousebuttonfun mouseButton; + GLFWcursorposfun cursorPos; + GLFWcursorenterfun cursorEnter; + GLFWscrollfun scroll; + GLFWkeyfun key; + GLFWcharfun character; + GLFWcharmodsfun charmods; + GLFWdropfun drop; } callbacks; // This is defined in the window API's platform.h From 294b08dcc8f93e79429b052acf80a550ec2f06eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 15 Dec 2020 02:13:24 +0100 Subject: [PATCH 09/21] Add credit Related to #1818. (cherry picked from commit 6ce6b50787e058177aad547aac33015ab298f1f1) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9c1d950c..8c2d393b 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ skills. - Bobyshev Alexander - Matt Arsenault + - ashishgamedev - David Avedissian - Keith Bauer - John Bartholomew From be56132c02bd182ef76ece4de190ec29d54e698d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 3 Jan 2021 21:13:02 +0100 Subject: [PATCH 10/21] Update repo URL for Nuklear Fixes #1826. (cherry picked from commit 5d1d1a01e3a05c068289487831940896d9a5902e) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c2d393b..116e7fa5 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ located in the `deps/` directory. functions - [linmath.h](https://github.com/datenwolf/linmath.h) for linear algebra in examples - - [Nuklear](https://github.com/vurtun/nuklear) for test and example UI + - [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) for test and example UI - [stb\_image\_write](https://github.com/nothings/stb) for writing images to disk The documentation is generated with [Doxygen](http://doxygen.org/) if CMake can From 078e8fcf55870da4451b92df87848300effe1438 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 5 Jan 2021 20:42:46 -0800 Subject: [PATCH 11/21] Cocoa: Fix duplicate video mode detection Closes #1830. (cherry picked from commit f5af421a6b9910ae8d02c4f468ec6d130052c351) --- src/cocoa_monitor.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index cc45f85e..4fa5dbd8 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -527,7 +527,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) } // Skip duplicate modes - if (i < *count) + if (j < *count) continue; (*count)++; From 01c362ba37ee11fcd2ea743fc598e6fa3ef2ad71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 16:24:27 +0100 Subject: [PATCH 12/21] Update changelog (cherry picked from commit 552209fe465b3c3d8bc4e2b02e0b259364d2a3a1) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 116e7fa5..f8e347b8 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Failing to retrieve the refresh rate of built-in displays could leak memory - [Cocoa] Bugfix: Objective-C files were compiled as C with CMake 3.19 (#1787) + - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors From eda12dd94938504ccaba0734b41485de91aac0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 8 Dec 2020 23:23:20 +0100 Subject: [PATCH 13/21] Cocoa: Fix menubar for unbundled apps on 10.15 NSApp setActivationPolicy: was being called too soon when the app was not bundled and launched from the command line. This fix is based on #1802 by @richardwilkes. Fixes #1648. Closes #1802. Adapted to 3.3-stable from 8b118674643b199fc28d11dc22039ffe528970b3. --- README.md | 3 +++ src/cocoa_init.m | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f8e347b8..96b153db 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,8 @@ information on what to include when reporting a bug. could leak memory - [Cocoa] Bugfix: Objective-C files were compiled as C with CMake 3.19 (#1787) - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) + - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and + regained focus (#1648,#1802) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors @@ -366,6 +368,7 @@ skills. - Waris - Jay Weisskopf - Frank Wille + - Richard A. Wilkes - Tatsuya Yatagawa - Ryogo Yoshimura - Lukas Zanner diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 579b6e6c..0eb86f57 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -428,9 +428,6 @@ static GLFWbool initializeTIS(void) { if (_glfw.hints.init.ns.menubar) { - // In case we are unbundled, make us a proper UI application - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - // Menu bar setup must go between sharedApplication and finishLaunching // in order to properly emulate the behavior of NSApplicationMain @@ -449,6 +446,8 @@ static GLFWbool initializeTIS(void) { _glfw.ns.finishedLaunching = GLFW_TRUE; _glfwPlatformPostEmptyEvent(); + // In case we are unbundled, make us a proper UI application + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp stop:nil]; } From 14921d1e249bf451a21a590b90a3c0ac9ffd5ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 01:26:00 +0100 Subject: [PATCH 14/21] Cocoa: Fix duplicate monitor connection events (cherry picked from commit 5aff72aa0016105477b9ce16f2da590939cec981) --- src/cocoa_monitor.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 4fa5dbd8..1007d062 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -338,7 +338,8 @@ void _glfwPollMonitorsNS(void) // display replacement on machines with automatic graphics // switching const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); - for (uint32_t j = 0; j < disconnectedCount; j++) + uint32_t j; + for (j = 0; j < disconnectedCount; j++) { if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) { @@ -347,6 +348,9 @@ void _glfwPollMonitorsNS(void) } } + if (j < disconnectedCount) + continue; + const CGSize size = CGDisplayScreenSize(displays[i]); char* name = getDisplayName(displays[i]); if (!name) From 8746f68d613b8732c14aac22b81e14eb4a719250 Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Mon, 11 Jan 2021 17:27:27 +0100 Subject: [PATCH 15/21] Cocoa: Use modern API to get display name On Apple Silicon, IOKit is deprecated and there will be no matching io_service that we can query for name. Luckilly, NSScreen got an API to fetch the display name in 10.15. This is a blocker to get glfw running on Apple Silicon. Fixes #1809. Closes #1833. (cherry picked from commit 2bc52ca82e46f6f238007b8e80b7253328bd080d) --- src/cocoa_monitor.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 1007d062..5a701826 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -41,6 +41,22 @@ // static char* getDisplayName(CGDirectDisplayID displayID) { + // IOKit doesn't work on Apple Silicon anymore. Luckilly, 10.15 introduced -[NSScreen localizedName]. + // Use it if available, and fall back to IOKit otherwise. + if ([NSScreen instancesRespondToSelector:@selector(localizedName)]) + { + for(NSScreen *screen in [NSScreen screens]) + { + if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue] == displayID) + { + NSString *name = [screen valueForKey:@"localizedName"]; + if (name) + { + return _glfw_strdup([name UTF8String]); + } + } + } + } io_iterator_t it; io_service_t service; CFDictionaryRef info; From 903c0ebfd1ce66d9831120aeda0ad9a066883c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 01:34:55 +0100 Subject: [PATCH 16/21] Update changelog and add credit Related to #1833. (cherry picked from commit 8ab40399d3bdbf8fb9501e42e53f36b5e5528da1) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 96b153db..c5eb612a 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and regained focus (#1648,#1802) + - [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors @@ -185,6 +186,7 @@ skills. - Coşku Baş - Niklas Behrens - Andrew Belt + - Nevyn Bengtsson - Niklas Bergström - Denis Bernard - Doug Binks From 15b0c43e2de1adfbcacd9e15a8ed970727918213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 17 Jan 2021 19:49:51 +0100 Subject: [PATCH 17/21] Cocoa: Unify CG display to NS screen mapping This moves the matching of CG displays to NS screens to monitor enumeration time. (cherry picked from commit 3959ee894952f7dcba4e46bdd5d34e4528701cd7) --- src/cocoa_monitor.m | 79 +++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 5a701826..55638cf0 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -39,24 +39,21 @@ // Get the name of the specified display, or NULL // -static char* getDisplayName(CGDirectDisplayID displayID) +static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen) { - // IOKit doesn't work on Apple Silicon anymore. Luckilly, 10.15 introduced -[NSScreen localizedName]. + // IOKit doesn't work on Apple Silicon anymore + // Luckily, 10.15 introduced -[NSScreen localizedName]. // Use it if available, and fall back to IOKit otherwise. - if ([NSScreen instancesRespondToSelector:@selector(localizedName)]) + if (screen) { - for(NSScreen *screen in [NSScreen screens]) + if ([screen respondsToSelector:@selector(localizedName)]) { - if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue] == displayID) - { - NSString *name = [screen valueForKey:@"localizedName"]; - if (name) - { - return _glfw_strdup([name UTF8String]); - } - } + NSString* name = [screen valueForKey:@"localizedName"]; + if (name) + return _glfw_strdup([name UTF8String]); } } + io_iterator_t it; io_service_t service; CFDictionaryRef info; @@ -225,31 +222,6 @@ static void endFadeReservation(CGDisplayFadeReservationToken token) } } -// Finds and caches the NSScreen corresponding to the specified monitor -// -static GLFWbool refreshMonitorScreen(_GLFWmonitor* monitor) -{ - if (monitor->ns.screen) - return GLFW_TRUE; - - for (NSScreen* screen in [NSScreen screens]) - { - NSNumber* displayID = [screen deviceDescription][@"NSScreenNumber"]; - - // HACK: Compare unit numbers instead of display IDs to work around - // display replacement on machines with automatic graphics - // switching - if (monitor->ns.unitNumber == CGDisplayUnitNumber([displayID unsignedIntValue])) - { - monitor->ns.screen = screen; - return GLFW_TRUE; - } - } - - _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find a screen for monitor"); - return GLFW_FALSE; -} - // Returns the display refresh rate queried from the I/O registry // static double getFallbackRefreshRate(CGDirectDisplayID displayID) @@ -350,15 +322,29 @@ void _glfwPollMonitorsNS(void) if (CGDisplayIsAsleep(displays[i])) continue; + const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); + NSScreen* screen = nil; + + for (screen in [NSScreen screens]) + { + NSNumber* screenNumber = [screen deviceDescription][@"NSScreenNumber"]; + + // HACK: Compare unit numbers instead of display IDs to work around + // display replacement on machines with automatic graphics + // switching + if (CGDisplayUnitNumber([screenNumber unsignedIntValue]) == unitNumber) + break; + } + // HACK: Compare unit numbers instead of display IDs to work around // display replacement on machines with automatic graphics // switching - const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); uint32_t j; for (j = 0; j < disconnectedCount; j++) { if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) { + disconnected[j]->ns.screen = screen; disconnected[j] = NULL; break; } @@ -368,13 +354,14 @@ void _glfwPollMonitorsNS(void) continue; const CGSize size = CGDisplayScreenSize(displays[i]); - char* name = getDisplayName(displays[i]); + char* name = getMonitorName(displays[i], screen); if (!name) name = _glfw_strdup("Unknown"); _GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height); monitor->ns.displayID = displays[i]; monitor->ns.unitNumber = unitNumber; + monitor->ns.screen = screen; free(name); @@ -483,8 +470,11 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, { @autoreleasepool { - if (!refreshMonitorScreen(monitor)) - return; + if (!monitor->ns.screen) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Cannot query content scale without screen"); + } const NSRect points = [monitor->ns.screen frame]; const NSRect pixels = [monitor->ns.screen convertRectToBacking:points]; @@ -503,8 +493,11 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, { @autoreleasepool { - if (!refreshMonitorScreen(monitor)) - return; + if (!monitor->ns.screen) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Cannot query workarea without screen"); + } const NSRect frameRect = [monitor->ns.screen visibleFrame]; From 8270081334e110f92d08599355bfe2219145832f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 16:04:51 +0100 Subject: [PATCH 18/21] Simplify references in CMake if-statements Adapted to 3.3-stable from f8d6801a507ff5a5b41f30347dd03f1e38a0f9e9. --- src/CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e18b14aa..624483e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,7 @@ elseif (_GLFW_OSMESA) endif() if (_GLFW_X11 OR _GLFW_WAYLAND) - if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") set(glfw_HEADERS ${glfw_HEADERS} linux_joystick.h) set(glfw_SOURCES ${glfw_SOURCES} linux_joystick.c) else() @@ -73,7 +73,7 @@ if (_GLFW_X11 OR _GLFW_WAYLAND) endif() # Workaround for CMake not knowing about .m files before version 3.16 -if ("${CMAKE_VERSION}" VERSION_LESS "3.16" AND APPLE) +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) @@ -87,8 +87,8 @@ set_target_properties(glfw PROPERTIES POSITION_INDEPENDENT_CODE ON FOLDER "GLFW3") -if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR - ${CMAKE_VERSION} VERSION_GREATER "3.1.0") +if (CMAKE_VERSION VERSION_EQUAL "3.1.0" OR + CMAKE_VERSION VERSION_GREATER "3.1.0") set_target_properties(glfw PROPERTIES C_STANDARD 99) else() @@ -111,7 +111,7 @@ target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) # Make GCC warn about declarations that VS 2010 and 2012 won't accept for all # source files that VS will build (Clang ignores this because we set -std=c99) -if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") set_source_files_properties(context.c init.c input.c monitor.c vulkan.c window.c win32_init.c win32_joystick.c win32_monitor.c win32_time.c win32_thread.c @@ -121,11 +121,11 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") endif() # Enable a reasonable set of warnings -if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR - "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - if ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + if (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") # Tell Clang-CL that this is a Clang flag target_compile_options(glfw PRIVATE "/clang:-Wall") else() From 5a15d8a7842fbc4b5260eac2335a6691bca9be4b Mon Sep 17 00:00:00 2001 From: Laurent Aphecetche Date: Fri, 14 Jun 2019 16:42:50 +0200 Subject: [PATCH 19/21] Cocoa: Fix install name for installed dylib The install name was incorrectly set to a relative path. This change leaves the install name of the installed dylib as @rpath/soname. Those who wish to override this can set the CMAKE_INSTALL_NAME_DIR variable. Closes #1504. (cherry picked from commit 384ff74a4645347bbc5726fc572138b38f87ae8b) --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 624483e9..a409459b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -168,9 +168,6 @@ if (BUILD_SHARED_LIBS) elseif (APPLE) # Add -fno-common to work around a bug in Apple's GCC target_compile_options(glfw PRIVATE "-fno-common") - - set_target_properties(glfw PROPERTIES - INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}") endif() if (UNIX) From 860d9deceb16549019e501c174e3ec85401bb002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 18:55:17 +0100 Subject: [PATCH 20/21] Update changelog and add credit (cherry picked from commit 94773111300fee0453844a4c9407af7e880b4df8) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c5eb612a..3f22bb6f 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and regained focus (#1648,#1802) - [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833) + - [Cocoa] Bugfix: The install name of the installed dylib was relative (#1504) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors @@ -178,6 +179,7 @@ GLFW exists because people around the world donated their time and lent their skills. - Bobyshev Alexander + - Laurent Aphecetche - Matt Arsenault - ashishgamedev - David Avedissian From c6fa2c8cfb9d69afa5d9c0117c3119ae5a33e061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 10 Feb 2021 17:23:43 +0100 Subject: [PATCH 21/21] Cocoa: Fix console apps getting a dock icon Regression introduced by @elmindreda in 8b118674643b199fc28d11dc22039ffe528970b3. Adapted to 3.3-stable from 6de084000bbebec345f4e5845a92fb2f4f931c00. --- src/cocoa_init.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 0eb86f57..209639e2 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -446,8 +446,11 @@ static GLFWbool initializeTIS(void) { _glfw.ns.finishedLaunching = GLFW_TRUE; _glfwPlatformPostEmptyEvent(); + // In case we are unbundled, make us a proper UI application - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + if (_glfw.hints.init.ns.menubar) + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + [NSApp stop:nil]; }