From 2ab0057315e35fcfe7cd0515951a167ec949dd7a Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 28 Apr 2021 06:13:03 -0700 Subject: [PATCH] Add FreeBSD support to the glfw joystick code. Tested with the multimedia/webcamd port as "driver", and an Xbox One game pad. Assumes "Linux" for game pad definitions, which seems right as webcamd actually is wrapping the Linux drivers. Note that part of this may have to be synced upstream with glfw. No idea how this process works in go-gl/glfw. --- v3.3/glfw/c_glfw_freebsd.go | 3 ++- v3.3/glfw/glfw/src/linux_joystick.c | 2 +- v3.3/glfw/glfw/src/linux_joystick.h | 4 ++++ v3.3/glfw/glfw/src/wl_init.c | 4 ++-- v3.3/glfw/glfw/src/wl_platform.h | 2 +- v3.3/glfw/glfw/src/x11_init.c | 4 ++-- v3.3/glfw/glfw/src/x11_platform.h | 2 +- v3.3/glfw/glfw/src/x11_window.c | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-) diff --git a/v3.3/glfw/c_glfw_freebsd.go b/v3.3/glfw/c_glfw_freebsd.go index 01122739..7202233f 100644 --- a/v3.3/glfw/c_glfw_freebsd.go +++ b/v3.3/glfw/c_glfw_freebsd.go @@ -3,6 +3,7 @@ package glfw /* +#cgo LDFLAGS: -linotify #ifdef _GLFW_WAYLAND #include "glfw/src/wl_init.c" #include "glfw/src/wl_monitor.c" @@ -20,7 +21,7 @@ package glfw #include "glfw/src/x11_window.c" #include "glfw/src/glx_context.c" #endif -#include "glfw/src/null_joystick.c" +#include "glfw/src/linux_joystick.c" #include "glfw/src/posix_time.c" #include "glfw/src/posix_thread.c" #include "glfw/src/xkb_unicode.c" diff --git a/v3.3/glfw/glfw/src/linux_joystick.c b/v3.3/glfw/glfw/src/linux_joystick.c index 5a3b806c..3b44d368 100644 --- a/v3.3/glfw/glfw/src/linux_joystick.c +++ b/v3.3/glfw/glfw/src/linux_joystick.c @@ -283,7 +283,7 @@ GLFWbool _glfwInitJoysticksLinux(void) // Continue without device connection notifications if inotify fails - if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) + if (regcomp(&_glfw.linjs.regex, "^event[0-9][0-9]*$", 0) != 0) { _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); return GLFW_FALSE; diff --git a/v3.3/glfw/glfw/src/linux_joystick.h b/v3.3/glfw/glfw/src/linux_joystick.h index 2eabfa13..dfee7993 100644 --- a/v3.3/glfw/glfw/src/linux_joystick.h +++ b/v3.3/glfw/glfw/src/linux_joystick.h @@ -25,7 +25,11 @@ //======================================================================== #include +#ifdef __linux__ #include +#else +#include +#endif #include #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs diff --git a/v3.3/glfw/glfw/src/wl_init.c b/v3.3/glfw/glfw/src/wl_init.c index 49e7cc52..78a9a353 100644 --- a/v3.3/glfw/glfw/src/wl_init.c +++ b/v3.3/glfw/glfw/src/wl_init.c @@ -1157,7 +1157,7 @@ int _glfwPlatformInit(void) // Sync so we got all initial output events wl_display_roundtrip(_glfw.wl.display); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; #endif @@ -1217,7 +1217,7 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) _glfwTerminateJoysticksLinux(); #endif _glfwTerminateEGL(); diff --git a/v3.3/glfw/glfw/src/wl_platform.h b/v3.3/glfw/glfw/src/wl_platform.h index 41a7fdfa..5f94c706 100644 --- a/v3.3/glfw/glfw/src/wl_platform.h +++ b/v3.3/glfw/glfw/src/wl_platform.h @@ -47,7 +47,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR #include "posix_thread.h" #include "posix_time.h" -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #include "linux_joystick.h" #else #include "null_joystick.h" diff --git a/v3.3/glfw/glfw/src/x11_init.c b/v3.3/glfw/glfw/src/x11_init.c index 87b3eb78..fc96fdd5 100644 --- a/v3.3/glfw/glfw/src/x11_init.c +++ b/v3.3/glfw/glfw/src/x11_init.c @@ -1094,7 +1094,7 @@ int _glfwPlatformInit(void) } } -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; #endif @@ -1187,7 +1187,7 @@ void _glfwPlatformTerminate(void) _glfwTerminateEGL(); _glfwTerminateGLX(); -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) _glfwTerminateJoysticksLinux(); #endif } diff --git a/v3.3/glfw/glfw/src/x11_platform.h b/v3.3/glfw/glfw/src/x11_platform.h index 4873bd74..2ff3b9fb 100644 --- a/v3.3/glfw/glfw/src/x11_platform.h +++ b/v3.3/glfw/glfw/src/x11_platform.h @@ -155,7 +155,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(Vk #include "glx_context.h" #include "egl_context.h" #include "osmesa_context.h" -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include "linux_joystick.h" #else #include "null_joystick.h" diff --git a/v3.3/glfw/glfw/src/x11_window.c b/v3.3/glfw/glfw/src/x11_window.c index 90c4d9be..78b2d607 100644 --- a/v3.3/glfw/glfw/src/x11_window.c +++ b/v3.3/glfw/glfw/src/x11_window.c @@ -2771,7 +2771,7 @@ void _glfwPlatformPollEvents(void) { _GLFWwindow* window; -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) _glfwDetectJoystickConnectionLinux(); #endif XPending(_glfw.x11.display);