From f4c127f75a943f4ac187871ff28635ccf079d93e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Jan 2015 23:48:29 +0100 Subject: [PATCH] Made XInput2 optional at compile-time. This is required for RHEL 5, CentOS 5 and Cygwin-X. Fixes #314. --- CMakeLists.txt | 20 ++++++++++---------- README.md | 1 + docs/compile.dox | 5 +++++ src/glfw_config.h.in | 2 ++ src/x11_init.c | 2 ++ src/x11_platform.h | 28 ++++++++++++++++------------ src/x11_window.c | 4 ++++ 7 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c8574ff..1ff15f0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,19 +273,19 @@ if (_GLFW_X11) list(APPEND glfw_PKG_DEPS "xinerama") # Check for XInput (high-resolution cursor motion) - if (NOT X11_Xinput_FOUND) - message(FATAL_ERROR "The XInput library and headers were not found") - endif() + if (X11_Xinput_FOUND) + list(APPEND glfw_INCLUDE_DIRS "${X11_Xinput_INCLUDE_PATH}") + list(APPEND glfw_PKG_DEPS "xi") - list(APPEND glfw_INCLUDE_DIRS "${X11_Xinput_INCLUDE_PATH}") + if (X11_Xinput_LIB) + list(APPEND glfw_LIBRARIES "${X11_Xinput_LIB}") + else() + # Backwards compatibility (bug in CMake 2.8.7) + list(APPEND glfw_LIBRARIES Xi) + endif() - if (X11_Xinput_LIB) - list(APPEND glfw_LIBRARIES "${X11_Xinput_LIB}") - else() - # Backwards compatibility (bug in CMake 2.8.7) - list(APPEND glfw_LIBRARIES Xi) + set(_GLFW_HAS_XINPUT TRUE) endif() - list(APPEND glfw_PKG_DEPS "xi") # Check for Xf86VidMode (fallback gamma control) if (NOT X11_xf86vmode_FOUND) diff --git a/README.md b/README.md index d15c882c..9d26bdf6 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ GLFW bundles a number of dependencies in the `deps/` directory. - [Cocoa] Bugfix: `glfwSetWindowSize` did not change the video mode for full screen windows + - [X11] Made XInput2 optional at compile-time ## Contact diff --git a/docs/compile.dox b/docs/compile.dox index c7b01e34..081fb11c 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -302,6 +302,11 @@ point retrieval mechanism. - `_GLFW_HAS_GLXGETPROCADDRESSEXT` to use `glXGetProcAddressEXT` (legacy) - `_GLFW_HAS_DLOPEN` to do manual retrieval with `dlopen` (fallback) +In addition, support for the following X11 extensions can be enabled: + + - `_GLFW_HAS_XINPUT` to use XInput2 for high-resolution cursor motion + (recommended) + If you are using the Cocoa window creation API, the following options are available: diff --git a/src/glfw_config.h.in b/src/glfw_config.h.in index 485cac58..842fa432 100644 --- a/src/glfw_config.h.in +++ b/src/glfw_config.h.in @@ -62,6 +62,8 @@ // Define this to 1 to force use of high-performance GPU on Optimus systems #cmakedefine _GLFW_USE_OPTIMUS_HPG +// Define this to 1 if the XInput X11 extension is available +#cmakedefine _GLFW_HAS_XINPUT // Define this to 1 if glXGetProcAddress is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS // Define this to 1 if glXGetProcAddressARB is available diff --git a/src/x11_init.c b/src/x11_init.c index 388105ef..aa9c1c2c 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -535,6 +535,7 @@ static GLboolean initExtensions(void) _glfw.x11.xinerama.available = GL_TRUE; } +#if defined(_GLFW_HAS_XINPUT) if (XQueryExtension(_glfw.x11.display, "XInputExtension", &_glfw.x11.xi.majorOpcode, @@ -551,6 +552,7 @@ static GLboolean initExtensions(void) _glfw.x11.xi.available = GL_TRUE; } } +#endif /*_GLFW_HAS_XINPUT*/ // Check if Xkb is supported on this display _glfw.x11.xkb.versionMajor = 1; diff --git a/src/x11_platform.h b/src/x11_platform.h index 81d1bef1..d1572ba8 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -43,15 +43,17 @@ // The XRandR extension provides mode setting and gamma control #include -// The XInput2 extension provides improved input events -#include - // The Xkb extension provides improved keyboard support #include // The Xinerama extension provides legacy monitor indices #include +#if defined(_GLFW_HAS_XINPUT) + // The XInput2 extension provides improved input events + #include +#endif + #include "posix_tls.h" #if defined(_GLFW_GLX) @@ -188,15 +190,6 @@ typedef struct _GLFWlibraryX11 int versionMinor; } xkb; - struct { - GLboolean available; - int majorOpcode; - int eventBase; - int errorBase; - int versionMajor; - int versionMinor; - } xi; - struct { int count; int timeout; @@ -215,6 +208,17 @@ typedef struct _GLFWlibraryX11 int versionMinor; } xinerama; +#if defined(_GLFW_HAS_XINPUT) + struct { + GLboolean available; + int majorOpcode; + int eventBase; + int errorBase; + int versionMajor; + int versionMinor; + } xi; +#endif /*_GLFW_HAS_XINPUT*/ + } _GLFWlibraryX11; diff --git a/src/x11_window.c b/src/x11_window.c index 3f584cdf..77a34597 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -412,6 +412,7 @@ static GLboolean createWindow(_GLFWwindow* window, XFree(hint); } +#if defined(_GLFW_HAS_XINPUT) if (_glfw.x11.xi.available) { // Select for XInput2 events @@ -426,6 +427,7 @@ static GLboolean createWindow(_GLFWwindow* window, XISelectEvents(_glfw.x11.display, window->x11.handle, &eventmask, 1); } +#endif /*_GLFW_HAS_XINPUT*/ if (_glfw.x11.XdndAware) { @@ -1310,6 +1312,7 @@ static void processEvent(XEvent *event) case DestroyNotify: return; +#if defined(_GLFW_HAS_XINPUT) case GenericEvent: { if (event->xcookie.extension == _glfw.x11.xi.majorOpcode && @@ -1355,6 +1358,7 @@ static void processEvent(XEvent *event) XFreeEventData(_glfw.x11.display, &event->xcookie); break; } +#endif /*_GLFW_HAS_XINPUT*/ default: {