diff --git a/CMakeLists.txt b/CMakeLists.txt index 448c7f79..2f230d90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,10 @@ if (NOT CMAKE_VERSION VERSION_LESS "3.0") cmake_policy(SET CMP0042 OLD) endif() +if (NOT CMAKE_VERSION VERSION_LESS "3.1") + cmake_policy(SET CMP0054 NEW) +endif() + set(GLFW_VERSION_MAJOR "3") set(GLFW_VERSION_MINOR "3") set(GLFW_VERSION_PATCH "0") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 43e88953..a84ac5c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,12 +18,19 @@ elseif (_GLFW_WIN32) win32_monitor.c win32_time.c win32_tls.c win32_window.c wgl_context.c egl_context.c) elseif (_GLFW_X11) - set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h - linux_joystick.h posix_time.h posix_tls.h glx_context.h - egl_context.h) + set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h posix_time.h + posix_tls.h glx_context.h egl_context.h) set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c - xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c - glx_context.c egl_context.c) + xkb_unicode.c posix_time.c posix_tls.c glx_context.c + egl_context.c) + + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(glfw_HEADERS ${glfw_HEADERS} linux_joystick.h) + set(glfw_SOURCES ${glfw_SOURCES} linux_joystick.c) + else() + set(glfw_HEADERS ${glfw_HEADERS} null_joystick.h) + set(glfw_SOURCES ${glfw_SOURCES} null_joystick.c) + endif() elseif (_GLFW_WAYLAND) set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h posix_time.h posix_tls.h xkb_unicode.h egl_context.h) @@ -46,10 +53,10 @@ elseif (_GLFW_MIR) linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c egl_context.c) elseif (_GLFW_OSMESA) - set(glfw_HEADERS ${common_HEADERS} osmesa_platform.h + set(glfw_HEADERS ${common_HEADERS} osmesa_platform.h null_joystick.h posix_time.h posix_tls.h osmesa_context.h) set(glfw_SOURCES ${common_SOURCES} osmesa_init.c osmesa_monitor.c - osmesa_window.c posix_time.c posix_tls.c + osmesa_window.c null_joystick.c posix_time.c posix_tls.c osmesa_context.c) endif() diff --git a/src/linux_joystick.c b/src/linux_joystick.c index cfc15a49..04cca5f5 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -27,7 +27,6 @@ #include "internal.h" -#if defined(__linux__) #include #include @@ -40,12 +39,10 @@ #include #include #include -#endif // __linux__ // Attempt to open the specified joystick device // -#if defined(__linux__) static GLFWbool openJoystickDevice(const char* path) { char axisCount, buttonCount; @@ -93,11 +90,9 @@ static GLFWbool openJoystickDevice(const char* path) _glfwInputJoystick(_GLFW_JOYSTICK_ID(js), GLFW_CONNECTED); return GLFW_TRUE; } -#endif // __linux__ // Frees all resources associated with the specified joystick // -#if defined(__linux__) static void closeJoystick(_GLFWjoystick* js) { close(js->linjs.fd); @@ -105,18 +100,15 @@ static void closeJoystick(_GLFWjoystick* js) _glfwFreeJoystick(js); _glfwInputJoystick(_GLFW_JOYSTICK_ID(js), GLFW_DISCONNECTED); } -#endif // __linux__ // Lexically compare joysticks by name; used by qsort // -#if defined(__linux__) static int compareJoysticks(const void* fp, const void* sp) { const _GLFWjoystick* fj = fp; const _GLFWjoystick* sj = sp; return strcmp(fj->linjs.path, sj->linjs.path); } -#endif // __linux__ ////////////////////////////////////////////////////////////////////////// @@ -127,7 +119,6 @@ static int compareJoysticks(const void* fp, const void* sp) // GLFWbool _glfwInitJoysticksLinux(void) { -#if defined(__linux__) DIR* dir; int count = 0; const char* dirname = "/dev/input"; @@ -192,8 +183,6 @@ GLFWbool _glfwInitJoysticksLinux(void) } qsort(_glfw.joysticks, count, sizeof(_GLFWjoystick), compareJoysticks); -#endif // __linux__ - return GLFW_TRUE; } @@ -201,7 +190,6 @@ GLFWbool _glfwInitJoysticksLinux(void) // void _glfwTerminateJoysticksLinux(void) { -#if defined(__linux__) int jid; for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) @@ -220,12 +208,10 @@ void _glfwTerminateJoysticksLinux(void) close(_glfw.linjs.inotify); } -#endif // __linux__ } void _glfwDetectJoystickConnectionLinux(void) { -#if defined(__linux__) ssize_t offset = 0; char buffer[16384]; @@ -260,7 +246,6 @@ void _glfwDetectJoystickConnectionLinux(void) offset += sizeof(struct inotify_event) + e->len; } -#endif } @@ -270,7 +255,6 @@ void _glfwDetectJoystickConnectionLinux(void) int _glfwPlatformPollJoystick(int jid, int mode) { -#if defined(__linux__) _GLFWjoystick* js = _glfw.joysticks + jid; // Read all queued events (non-blocking) @@ -296,7 +280,7 @@ int _glfwPlatformPollJoystick(int jid, int mode) else if (e.type == JS_EVENT_BUTTON) _glfwInputJoystickButton(jid, e.number, e.value ? 1 : 0); } -#endif // __linux__ + return js->present; } diff --git a/src/linux_joystick.h b/src/linux_joystick.h index e61a3c6a..3698b7e0 100644 --- a/src/linux_joystick.h +++ b/src/linux_joystick.h @@ -45,11 +45,9 @@ typedef struct _GLFWjoystickLinux // typedef struct _GLFWlibraryLinux { -#if defined(__linux__) int inotify; int watch; regex_t regex; -#endif /*__linux__*/ } _GLFWlibraryLinux; diff --git a/src/mir_init.c b/src/mir_init.c index a7b5846f..5df5d981 100644 --- a/src/mir_init.c +++ b/src/mir_init.c @@ -239,9 +239,7 @@ const char* _glfwPlatformGetVersionString(void) #else " gettimeofday" #endif -#if defined(__linux__) " /dev/js" -#endif #if defined(_GLFW_BUILD_DLL) " shared" #endif diff --git a/src/null_joystick.c b/src/null_joystick.c new file mode 100644 index 00000000..7d08af00 --- /dev/null +++ b/src/null_joystick.c @@ -0,0 +1,38 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2006-2016 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +int _glfwPlatformPollJoystick(int jid, int mode) +{ + return GLFW_FALSE; +} + diff --git a/src/null_joystick.h b/src/null_joystick.h new file mode 100644 index 00000000..dc7759bc --- /dev/null +++ b/src/null_joystick.h @@ -0,0 +1,34 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2006-2016 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#ifndef _glfw3_null_joystick_h_ +#define _glfw3_null_joystick_h_ + +#define _GLFW_PLATFORM_JOYSTICK_STATE int nulljs +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int nulljs + + +#endif // _glfw3_null_joystick_h_ diff --git a/src/osmesa_platform.h b/src/osmesa_platform.h index e6581bfe..9571bab8 100644 --- a/src/osmesa_platform.h +++ b/src/osmesa_platform.h @@ -35,13 +35,13 @@ #define _GLFW_PLATFORM_MONITOR_STATE #define _GLFW_PLATFORM_CURSOR_STATE #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE #define _GLFW_EGL_CONTEXT_STATE #define _GLFW_EGL_LIBRARY_CONTEXT_STATE #include "osmesa_context.h" #include "posix_time.h" #include "posix_tls.h" +#include "null_joystick.h" #if defined(_GLFW_WIN32) #define _glfw_dlopen(name) LoadLibraryA(name) diff --git a/src/osmesa_window.c b/src/osmesa_window.c index 20838f55..d0593826 100644 --- a/src/osmesa_window.c +++ b/src/osmesa_window.c @@ -269,11 +269,6 @@ int _glfwPlatformGetKeyScancode(int key) return -1; } -int _glfwPlatformPollJoystick(int jid, int mode) -{ - return GLFW_FALSE; -} - void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { } diff --git a/src/wl_init.c b/src/wl_init.c index 58a265a0..ecc94f2a 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -739,9 +739,7 @@ const char* _glfwPlatformGetVersionString(void) #else " gettimeofday" #endif -#if defined(__linux__) " /dev/js" -#endif #if defined(_GLFW_BUILD_DLL) " shared" #endif diff --git a/src/x11_init.c b/src/x11_init.c index 02918f87..2e81c92d 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -798,8 +798,10 @@ int _glfwPlatformInit(void) if (!_glfwInitThreadLocalStoragePOSIX()) return GLFW_FALSE; +#if defined(__linux__) if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; +#endif _glfwInitTimerPOSIX(); @@ -853,7 +855,9 @@ void _glfwPlatformTerminate(void) // cleanup callbacks that get called by it _glfwTerminateGLX(); +#if defined(__linux__) _glfwTerminateJoysticksLinux(); +#endif _glfwTerminateThreadLocalStoragePOSIX(); } diff --git a/src/x11_platform.h b/src/x11_platform.h index 1db433d5..4319c528 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -89,10 +89,14 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(Vk #include "posix_tls.h" #include "posix_time.h" -#include "linux_joystick.h" #include "xkb_unicode.h" #include "glx_context.h" #include "egl_context.h" +#if defined(__linux__) +#include "linux_joystick.h" +#else +#include "null_joystick.h" +#endif #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) #define _glfw_dlclose(handle) dlclose(handle) diff --git a/src/x11_window.c b/src/x11_window.c index ab2c0dc2..86a17b5a 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2153,8 +2153,9 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformPollEvents(void) { +#if defined(__linux__) _glfwDetectJoystickConnectionLinux(); - +#endif int count = XPending(_glfw.x11.display); while (count--) {