mirror of
https://github.com/glfw/glfw.git
synced 2025-06-15 12:12:16 +00:00
Enable joystick support on FreeBSD using the Linux driver.
This is arguably incomplete; it supports joysticks via webcamd (which uses Linux drivers running in userspace), but not via uhidd (which is FreeBSD's own thing). Nevertheless a strict improvement. Tested using a gamepad I have that is supported by the "xpad" Linux driver. Note: adds build dependency on devel/evdev-proto and devel/libinotify. To actually use it, need to install multimedia/webcamd at runtime (if not installed or not running, no joysticks will be detected). Fixes #1892.
This commit is contained in:
parent
85348c67cd
commit
496c700042
@ -88,6 +88,10 @@ in the documentation for more information.
|
|||||||
GLFW itself needs only CMake 3.1 or later and the headers and libraries for your
|
GLFW itself needs only CMake 3.1 or later and the headers and libraries for your
|
||||||
OS and window system.
|
OS and window system.
|
||||||
|
|
||||||
|
As an exception, on FreeBSD, the `devel/evdev-proto` and `devel/libinotify`
|
||||||
|
ports need to be installed; furthermore, to actually use gamepads/joysticks,
|
||||||
|
`multimedia/webcamd` needs to be installed and configured.
|
||||||
|
|
||||||
The examples and test programs depend on a number of tiny libraries. These are
|
The examples and test programs depend on a number of tiny libraries. These are
|
||||||
located in the `deps/` directory.
|
located in the `deps/` directory.
|
||||||
|
|
||||||
|
@ -49,6 +49,12 @@ endif()
|
|||||||
if (_GLFW_X11 OR _GLFW_WAYLAND)
|
if (_GLFW_X11 OR _GLFW_WAYLAND)
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c)
|
target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c)
|
||||||
|
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||||
|
target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c)
|
||||||
|
pkg_check_modules(LIBINOTIFY REQUIRED libinotify)
|
||||||
|
target_link_libraries(glfw PRIVATE ${LIBINOTIFY_LINK_LIBRARIES})
|
||||||
|
target_include_directories(glfw PRIVATE ${LIBINOTIFY_INCLUDE_DIRS})
|
||||||
|
target_compile_options(glfw PRIVATE ${LIBINOTIFY_CFLAGS_OTHER})
|
||||||
else()
|
else()
|
||||||
target_sources(glfw PRIVATE null_joystick.h null_joystick.c)
|
target_sources(glfw PRIVATE null_joystick.h null_joystick.c)
|
||||||
endif()
|
endif()
|
||||||
|
@ -324,7 +324,7 @@ GLFWbool _glfwPlatformInitJoysticks(void)
|
|||||||
|
|
||||||
// Continue without device connection notifications if inotify fails
|
// 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");
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex");
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
|
@ -25,7 +25,11 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
#ifdef __linux__
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
|
#else
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
|
||||||
#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs
|
#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs
|
||||||
|
@ -47,7 +47,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
|
|||||||
|
|
||||||
#include "posix_thread.h"
|
#include "posix_thread.h"
|
||||||
#include "posix_time.h"
|
#include "posix_time.h"
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
#include "linux_joystick.h"
|
#include "linux_joystick.h"
|
||||||
#else
|
#else
|
||||||
#include "null_joystick.h"
|
#include "null_joystick.h"
|
||||||
|
@ -1487,7 +1487,7 @@ const char* _glfwPlatformGetVersionString(void)
|
|||||||
#if defined(_POSIX_MONOTONIC_CLOCK)
|
#if defined(_POSIX_MONOTONIC_CLOCK)
|
||||||
" monotonic"
|
" monotonic"
|
||||||
#endif
|
#endif
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
" evdev"
|
" evdev"
|
||||||
#endif
|
#endif
|
||||||
#if defined(_GLFW_BUILD_DLL)
|
#if defined(_GLFW_BUILD_DLL)
|
||||||
|
@ -378,7 +378,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(Vk
|
|||||||
#include "posix_time.h"
|
#include "posix_time.h"
|
||||||
#include "xkb_unicode.h"
|
#include "xkb_unicode.h"
|
||||||
#include "glx_context.h"
|
#include "glx_context.h"
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
#include "linux_joystick.h"
|
#include "linux_joystick.h"
|
||||||
#else
|
#else
|
||||||
#include "null_joystick.h"
|
#include "null_joystick.h"
|
||||||
|
@ -67,7 +67,7 @@ static GLFWbool waitForEvent(double* timeout)
|
|||||||
const int fd = ConnectionNumber(_glfw.x11.display);
|
const int fd = ConnectionNumber(_glfw.x11.display);
|
||||||
int count = fd + 1;
|
int count = fd + 1;
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
if (_glfw.linjs.inotify > fd)
|
if (_glfw.linjs.inotify > fd)
|
||||||
count = _glfw.linjs.inotify + 1;
|
count = _glfw.linjs.inotify + 1;
|
||||||
#endif
|
#endif
|
||||||
@ -75,7 +75,7 @@ static GLFWbool waitForEvent(double* timeout)
|
|||||||
{
|
{
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
if (_glfw.linjs.inotify > 0)
|
if (_glfw.linjs.inotify > 0)
|
||||||
FD_SET(_glfw.linjs.inotify, &fds);
|
FD_SET(_glfw.linjs.inotify, &fds);
|
||||||
#endif
|
#endif
|
||||||
@ -2779,7 +2779,7 @@ void _glfwPlatformPollEvents(void)
|
|||||||
{
|
{
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
if (_glfw.joysticksInitialized)
|
if (_glfw.joysticksInitialized)
|
||||||
_glfwDetectJoystickConnectionLinux();
|
_glfwDetectJoystickConnectionLinux();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user