From d7cd3a3c3c1796b1f3153ac947cdaacd76f3515a Mon Sep 17 00:00:00 2001 From: pchampio Date: Mon, 25 Nov 2019 16:38:01 +0100 Subject: [PATCH] udpate GLFW source code --- v3.3/glfw/GLFW_C_REVISION.txt | 2 +- v3.3/glfw/glfw/src/CMakeLists.txt | 12 ++++++++ v3.3/glfw/glfw/src/cocoa_joystick.h | 2 +- v3.3/glfw/glfw/src/cocoa_monitor.m | 2 +- v3.3/glfw/glfw/src/cocoa_platform.h | 3 ++ v3.3/glfw/glfw/src/cocoa_window.m | 10 ++++--- v3.3/glfw/glfw/src/mappings.h | 2 -- v3.3/glfw/glfw/src/nsgl_context.h | 3 ++ v3.3/glfw/glfw/src/nsgl_context.m | 4 +-- v3.3/glfw/glfw/src/null_joystick.h | 4 +-- v3.3/glfw/glfw/src/null_platform.h | 14 +++++----- v3.3/glfw/glfw/src/win32_joystick.h | 2 +- v3.3/glfw/glfw/src/win32_window.c | 2 +- v3.3/glfw/glfw/src/wl_platform.h | 6 ++-- v3.3/glfw/glfw/src/x11_init.c | 11 +++----- v3.3/glfw/glfw/src/x11_monitor.c | 10 +++++++ v3.3/glfw/glfw/src/x11_window.c | 43 +++++++++++++---------------- 17 files changed, 76 insertions(+), 56 deletions(-) diff --git a/v3.3/glfw/GLFW_C_REVISION.txt b/v3.3/glfw/GLFW_C_REVISION.txt index 1ebaf03e..79d2fc38 100644 --- a/v3.3/glfw/GLFW_C_REVISION.txt +++ b/v3.3/glfw/GLFW_C_REVISION.txt @@ -1 +1 @@ -e4e9581557826bd522158ab9159859e20e10700e +2bac7ee8da526257d808bd026b027246c98e4f2f diff --git a/v3.3/glfw/glfw/src/CMakeLists.txt b/v3.3/glfw/glfw/src/CMakeLists.txt index 06867308..6cbeed6d 100644 --- a/v3.3/glfw/glfw/src/CMakeLists.txt +++ b/v3.3/glfw/glfw/src/CMakeLists.txt @@ -100,6 +100,18 @@ 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") + + set_target_properties(glfw PROPERTIES C_STANDARD 99) +else() + # Remove this fallback when removing support for CMake version less than 3.1 + target_compile_options(glfw PRIVATE + "$<$:-std=c99>" + "$<$:-std=c99>" + "$<$:-std=c99>") +endif() + target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H) target_include_directories(glfw PUBLIC "$" diff --git a/v3.3/glfw/glfw/src/cocoa_joystick.h b/v3.3/glfw/glfw/src/cocoa_joystick.h index 0ab81377..b4448778 100644 --- a/v3.3/glfw/glfw/src/cocoa_joystick.h +++ b/v3.3/glfw/glfw/src/cocoa_joystick.h @@ -30,7 +30,7 @@ #include #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; } #define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" diff --git a/v3.3/glfw/glfw/src/cocoa_monitor.m b/v3.3/glfw/glfw/src/cocoa_monitor.m index 28abe0d4..bb526732 100644 --- a/v3.3/glfw/glfw/src/cocoa_monitor.m +++ b/v3.3/glfw/glfw/src/cocoa_monitor.m @@ -252,7 +252,7 @@ void _glfwPollMonitorsNS(void) CGDirectDisplayID* displays = calloc(displayCount, sizeof(CGDirectDisplayID)); CGGetOnlineDisplayList(displayCount, displays, &displayCount); - for (uint32_t i = 0; i < _glfw.monitorCount; i++) + for (int i = 0; i < _glfw.monitorCount; i++) _glfw.monitors[i]->ns.screen = nil; _GLFWmonitor** disconnected = NULL; diff --git a/v3.3/glfw/glfw/src/cocoa_platform.h b/v3.3/glfw/glfw/src/cocoa_platform.h index 43639a34..b29b64c8 100644 --- a/v3.3/glfw/glfw/src/cocoa_platform.h +++ b/v3.3/glfw/glfw/src/cocoa_platform.h @@ -41,6 +41,9 @@ typedef void* id; #endif +// NOTE: Many Cocoa enum values have been renamed and we need to build across +// SDK versions where one is unavailable or the other deprecated +// We use the newer names in code and these macros to handle compatibility #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat #define NSEventMaskAny NSAnyEventMask diff --git a/v3.3/glfw/glfw/src/cocoa_window.m b/v3.3/glfw/glfw/src/cocoa_window.m index c8af3321..61321805 100644 --- a/v3.3/glfw/glfw/src/cocoa_window.m +++ b/v3.3/glfw/glfw/src/cocoa_window.m @@ -35,15 +35,14 @@ // static NSUInteger getStyleMask(_GLFWwindow* window) { - NSUInteger styleMask = 0; + NSUInteger styleMask = NSWindowStyleMaskMiniaturizable; if (window->monitor || !window->decorated) styleMask |= NSWindowStyleMaskBorderless; else { styleMask |= NSWindowStyleMaskTitled | - NSWindowStyleMaskClosable | - NSWindowStyleMaskMiniaturizable; + NSWindowStyleMaskClosable; if (window->resizable) styleMask |= NSWindowStyleMaskResizable; @@ -816,7 +815,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, [window->ns.object setLevel:NSMainMenuWindowLevel + 1]; else { - [window->ns.object center]; + [(NSWindow*) window->ns.object center]; _glfw.ns.cascadePoint = NSPointToCGPoint([window->ns.object cascadeTopLeftFromPoint: NSPointFromCGPoint(_glfw.ns.cascadePoint)]); @@ -962,6 +961,9 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) [window->ns.object close]; window->ns.object = nil; + // HACK: Allow Cocoa to catch up before returning + _glfwPlatformPollEvents(); + } // autoreleasepool } diff --git a/v3.3/glfw/glfw/src/mappings.h b/v3.3/glfw/glfw/src/mappings.h index 94a279af..606824a6 100644 --- a/v3.3/glfw/glfw/src/mappings.h +++ b/v3.3/glfw/glfw/src/mappings.h @@ -84,7 +84,6 @@ const char* _glfwDefaultMappings[] = "030000000d0f00008700000000000000,Fighting Stick mini 4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows,", "030000000d0f00002700000000000000,FIGHTING STICK V3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows,", "78696e70757403000000000000000000,Fightstick TES,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,start:b7,x:b2,y:b3,platform:Windows,", -"03000000790000000600000000000000,G-Shark GS-GP702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b3,y:b0,platform:Windows,", "03000000260900002625000000000000,Gamecube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,lefttrigger:a4,leftx:a0,lefty:a1,righttrigger:a5,rightx:a2,righty:a3,start:b7,x:b2,y:b3,platform:Windows,", "030000008f0e00000d31000000000000,GAMEPAD 3 TURBO,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,", "03000000280400000140000000000000,GamePad Pro USB,a:b1,b:b2,back:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,platform:Windows,", @@ -207,7 +206,6 @@ const char* _glfwDefaultMappings[] = "030000008305000031b0000000000000,Cideko AK08b,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X,", "03000000260900008888000088020000,Cyber Gadget GameCube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:a5,rightx:a2,righty:a3~,start:b7,x:b2,y:b3,platform:Mac OS X,", "03000000a306000022f6000001030000,Cyborg V.3 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:-a3,rightx:a2,righty:a4,start:b9,x:b0,y:b3,platform:Mac OS X,", -"03000000790000000600000000000000,G-Shark GP-702,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b3,y:b0,platform:Mac OS X,", "03000000ad1b000001f9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X,", "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,", "030000000d0f00005f00000000010000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X,", diff --git a/v3.3/glfw/glfw/src/nsgl_context.h b/v3.3/glfw/glfw/src/nsgl_context.h index 2485b180..432d200e 100644 --- a/v3.3/glfw/glfw/src/nsgl_context.h +++ b/v3.3/glfw/glfw/src/nsgl_context.h @@ -24,6 +24,9 @@ // //======================================================================== +// NOTE: Many Cocoa enum values have been renamed and we need to build across +// SDK versions where one is unavailable or the other deprecated +// We use the newer names in code and these macros to handle compatibility #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity diff --git a/v3.3/glfw/glfw/src/nsgl_context.m b/v3.3/glfw/glfw/src/nsgl_context.m index 1b450b18..9cfa4276 100644 --- a/v3.3/glfw/glfw/src/nsgl_context.m +++ b/v3.3/glfw/glfw/src/nsgl_context.m @@ -339,7 +339,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, return GLFW_FALSE; } - NSOpenGLContext* share = NULL; + NSOpenGLContext* share = nil; if (ctxconfig->share) share = ctxconfig->share->context.nsgl.object; @@ -412,7 +412,7 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) if (window->context.client == GLFW_NO_API) { _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); - return NULL; + return nil; } return window->context.nsgl.object; diff --git a/v3.3/glfw/glfw/src/null_joystick.h b/v3.3/glfw/glfw/src/null_joystick.h index 5a5c5584..9307ae88 100644 --- a/v3.3/glfw/glfw/src/null_joystick.h +++ b/v3.3/glfw/glfw/src/null_joystick.h @@ -24,8 +24,8 @@ // //======================================================================== -#define _GLFW_PLATFORM_JOYSTICK_STATE int nulljs -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int nulljs +#define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; } +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } #define _GLFW_PLATFORM_MAPPING_NAME "" diff --git a/v3.3/glfw/glfw/src/null_platform.h b/v3.3/glfw/glfw/src/null_platform.h index 7871683e..708975d1 100644 --- a/v3.3/glfw/glfw/src/null_platform.h +++ b/v3.3/glfw/glfw/src/null_platform.h @@ -29,13 +29,13 @@ #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNull null -#define _GLFW_PLATFORM_CONTEXT_STATE -#define _GLFW_PLATFORM_MONITOR_STATE -#define _GLFW_PLATFORM_CURSOR_STATE -#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE -#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE -#define _GLFW_EGL_CONTEXT_STATE -#define _GLFW_EGL_LIBRARY_CONTEXT_STATE +#define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } +#define _GLFW_PLATFORM_MONITOR_STATE struct { int dummyMonitor; } +#define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; } +#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } +#define _GLFW_EGL_CONTEXT_STATE struct { int dummyEGLContext; } +#define _GLFW_EGL_LIBRARY_CONTEXT_STATE struct { int dummyEGLLibraryContext; } #include "osmesa_context.h" #include "posix_time.h" diff --git a/v3.3/glfw/glfw/src/win32_joystick.h b/v3.3/glfw/glfw/src/win32_joystick.h index 22bcded3..9ba46d90 100644 --- a/v3.3/glfw/glfw/src/win32_joystick.h +++ b/v3.3/glfw/glfw/src/win32_joystick.h @@ -25,7 +25,7 @@ //======================================================================== #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int dummy +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } #define _GLFW_PLATFORM_MAPPING_NAME "Windows" diff --git a/v3.3/glfw/glfw/src/win32_window.c b/v3.3/glfw/glfw/src/win32_window.c index 29ade445..cdb1fe87 100644 --- a/v3.3/glfw/glfw/src/win32_window.c +++ b/v3.3/glfw/glfw/src/win32_window.c @@ -411,7 +411,7 @@ static void updateFramebufferTransparency(const _GLFWwindow* window) // issue. When set to black, something is making the hit test // not resize with the window frame. SetLayeredWindowAttributes(window->win32.handle, - RGB(0, 193, 48), 255, LWA_COLORKEY); + RGB(255, 0, 255), 255, LWA_COLORKEY); } DeleteObject(region); diff --git a/v3.3/glfw/glfw/src/wl_platform.h b/v3.3/glfw/glfw/src/wl_platform.h index 9fef848d..940e57ee 100644 --- a/v3.3/glfw/glfw/src/wl_platform.h +++ b/v3.3/glfw/glfw/src/wl_platform.h @@ -75,8 +75,8 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWayland wl #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWayland wl -#define _GLFW_PLATFORM_CONTEXT_STATE -#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE +#define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } +#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } struct wl_cursor_image { uint32_t width; @@ -332,7 +332,7 @@ typedef struct _GLFWlibraryWayland typedef struct _GLFWmonitorWayland { struct wl_output* output; - int name; + uint32_t name; int currentMode; int x; diff --git a/v3.3/glfw/glfw/src/x11_init.c b/v3.3/glfw/glfw/src/x11_init.c index f00080d6..2f220ec5 100644 --- a/v3.3/glfw/glfw/src/x11_init.c +++ b/v3.3/glfw/glfw/src/x11_init.c @@ -793,13 +793,10 @@ static GLFWbool initExtensions(void) // static void getSystemContentScale(float* xscale, float* yscale) { - // NOTE: Fall back to the display-wide DPI instead of RandR monitor DPI if - // Xft.dpi retrieval below fails as we don't currently have an exact - // policy for which monitor a window is considered to "be on" - float xdpi = DisplayWidth(_glfw.x11.display, _glfw.x11.screen) * - 25.4f / DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen); - float ydpi = DisplayHeight(_glfw.x11.display, _glfw.x11.screen) * - 25.4f / DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen); + // Start by assuming the default X11 DPI + // NOTE: Some desktop environments (KDE) may remove the Xft.dpi field when it + // would be set to 96, so assume that is the case if we cannot find it + float xdpi = 96.f, ydpi = 96.f; // NOTE: Basing the scale on Xft.dpi where available should provide the most // consistent user experience (matches Qt, Gtk, etc), although not diff --git a/v3.3/glfw/glfw/src/x11_monitor.c b/v3.3/glfw/glfw/src/x11_monitor.c index cce05f98..412f9f40 100644 --- a/v3.3/glfw/glfw/src/x11_monitor.c +++ b/v3.3/glfw/glfw/src/x11_monitor.c @@ -161,6 +161,16 @@ void _glfwPollMonitorsX11(void) heightMM = oi->mm_height; } + if (widthMM <= 0 || heightMM <= 0) + { + // HACK: If RandR does not provide a physical size, assume the + // X11 default 96 DPI and calcuate from the CRTC viewport + // NOTE: These members are affected by rotation, unlike the mode + // info and output info members + widthMM = (int) (ci->width * 25.4f / 96.f); + heightMM = (int) (ci->height * 25.4f / 96.f); + } + _GLFWmonitor* monitor = _glfwAllocMonitor(oi->name, widthMM, heightMM); monitor->x11.output = sr->outputs[i]; monitor->x11.crtc = oi->crtc; diff --git a/v3.3/glfw/glfw/src/x11_window.c b/v3.3/glfw/glfw/src/x11_window.c index 0ddbc0d4..85d548a6 100644 --- a/v3.3/glfw/glfw/src/x11_window.c +++ b/v3.3/glfw/glfw/src/x11_window.c @@ -50,6 +50,10 @@ #define Button6 6 #define Button7 7 +// Motif WM hints flags +#define MWM_HINTS_DECORATIONS 2 +#define MWM_DECOR_ALL 1 + #define _GLFW_XDND_VERSION 5 @@ -2536,33 +2540,24 @@ void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) { - if (enabled) - { - XDeleteProperty(_glfw.x11.display, - window->x11.handle, - _glfw.x11.MOTIF_WM_HINTS); - } - else + struct { - struct - { - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long input_mode; - unsigned long status; - } hints; + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long input_mode; + unsigned long status; + } hints = {0}; - hints.flags = 2; // Set decorations - hints.decorations = 0; // No decorations + hints.flags = MWM_HINTS_DECORATIONS; + hints.decorations = enabled ? MWM_DECOR_ALL : 0; - XChangeProperty(_glfw.x11.display, window->x11.handle, - _glfw.x11.MOTIF_WM_HINTS, - _glfw.x11.MOTIF_WM_HINTS, 32, - PropModeReplace, - (unsigned char*) &hints, - sizeof(hints) / sizeof(long)); - } + XChangeProperty(_glfw.x11.display, window->x11.handle, + _glfw.x11.MOTIF_WM_HINTS, + _glfw.x11.MOTIF_WM_HINTS, 32, + PropModeReplace, + (unsigned char*) &hints, + sizeof(hints) / sizeof(long)); } void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)