Commit c0f52b12 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Some cleanups on the new XInput code.

One or two things got moved around, but largely this is hooked up correctly
 in the Unix configure system now: it can be dynamically loaded and fallback
 gracefully if not available, or libXi can be directly linked to libSDL.

XInput support can be --disable'd from the configure script, too (defaults to
 enabled).

Please note that while the framework is in place to gracefully fallback, the
 current state of the source requires XInput. We'll need to adjust a few
 things still to correct this.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403220
parent 0d38b678
...@@ -989,6 +989,7 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma ...@@ -989,6 +989,7 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
x11ext_lib='/usr/X11R6/lib/libXext.6.dylib' x11ext_lib='/usr/X11R6/lib/libXext.6.dylib'
xrender_lib='/usr/X11R6/lib/libXrender.1.dylib' xrender_lib='/usr/X11R6/lib/libXrender.1.dylib'
xrandr_lib='/usr/X11R6/lib/libXrandr.2.dylib' xrandr_lib='/usr/X11R6/lib/libXrandr.2.dylib'
xinput_lib='/usr/X11R6/lib/libXi.6.dylib'
;; ;;
*-*-osf*) *-*-osf*)
x11_lib='libX11.so' x11_lib='libX11.so'
...@@ -1025,6 +1026,12 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma ...@@ -1025,6 +1026,12 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`] xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
fi fi
fi fi
if test "x$xinput_lib" = "x"; then
xinput_lib=[`ls -- $path/libXi.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
if test "x$xinput_lib" = "x"; then
xinput_lib=[`ls -- $path/libXi.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
fi
fi
done done
;; ;;
esac esac
...@@ -1041,9 +1048,6 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma ...@@ -1041,9 +1048,6 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
SOURCES="$SOURCES $srcdir/src/video/Xext/XmuStdCmap/*.c" SOURCES="$SOURCES $srcdir/src/video/Xext/XmuStdCmap/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $X_CFLAGS" EXTRA_CFLAGS="$EXTRA_CFLAGS $X_CFLAGS"
echo "FIXME: Need to get dynamic loading of XInput working"
enable_x11_shared=no
if test x$enable_x11_shared = xmaybe; then if test x$enable_x11_shared = xmaybe; then
enable_x11_shared=$x11_symbols_private enable_x11_shared=$x11_symbols_private
fi fi
...@@ -1066,7 +1070,7 @@ echo "FIXME: Need to get dynamic loading of XInput working" ...@@ -1066,7 +1070,7 @@ echo "FIXME: Need to get dynamic loading of XInput working"
AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib") AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib")
else else
enable_x11_shared=no enable_x11_shared=no
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext -lXi" EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext"
fi fi
have_video=yes have_video=yes
...@@ -1128,6 +1132,33 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful ...@@ -1128,6 +1132,33 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful
if test x$definitely_enable_video_x11_xrandr = xyes; then if test x$definitely_enable_video_x11_xrandr = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR) AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
fi fi
AC_ARG_ENABLE(video-x11-xinput,
AC_HELP_STRING([--enable-video-x11-xinput], [enable X11 XInput extension for manymouse, tablets, etc [[default=yes]]]),
, enable_video_x11_xinput=yes)
if test x$enable_video_x11_xinput = xyes; then
definitely_enable_video_x11_xinput=no
AC_CHECK_HEADER(X11/extensions/XInput.h,
have_xinput_h_hdr=yes,
have_xinput_h_hdr=no,
[#include <X11/Xlib.h>
])
if test x$have_xinput_h_hdr = xyes; then
if test x$enable_x11_shared = xyes && test x$xinput_lib != x ; then
echo "-- dynamic libXi -> $xinput_lib"
AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT, "$xinput_lib")
definitely_enable_video_x11_xinput=yes
else
AC_CHECK_LIB(Xi, XOpenDevice, have_xinput_lib=yes)
if test x$have_xinput_lib = xyes ; then
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXi"
definitely_enable_video_x11_xinput=yes
fi
fi
fi
fi
if test x$definitely_enable_video_x11_xinput = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT)
fi
AC_ARG_ENABLE(video-x11-dpms, AC_ARG_ENABLE(video-x11-dpms,
AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]), AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
, enable_video_x11_dpms=yes) , enable_video_x11_dpms=yes)
......
...@@ -282,10 +282,12 @@ ...@@ -282,10 +282,12 @@
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
#undef SDL_VIDEO_DRIVER_X11_VIDMODE #undef SDL_VIDEO_DRIVER_X11_VIDMODE
#undef SDL_VIDEO_DRIVER_X11_XINERAMA #undef SDL_VIDEO_DRIVER_X11_XINERAMA
#undef SDL_VIDEO_DRIVER_X11_XME #undef SDL_VIDEO_DRIVER_X11_XME
#undef SDL_VIDEO_DRIVER_X11_XRANDR #undef SDL_VIDEO_DRIVER_X11_XRANDR
#undef SDL_VIDEO_DRIVER_X11_XINPUT
#undef SDL_VIDEO_DRIVER_X11_XV #undef SDL_VIDEO_DRIVER_X11_XV
#undef SDL_VIDEO_DRIVER_XBIOS #undef SDL_VIDEO_DRIVER_XBIOS
......
...@@ -52,12 +52,16 @@ typedef struct ...@@ -52,12 +52,16 @@ typedef struct
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
#endif #endif
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL
#endif
static x11dynlib x11libs[] = { static x11dynlib x11libs[] = {
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
{NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
}; };
static void static void
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xlibint.h> #include <X11/Xlibint.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
//#include <X11/extensions/XInput.h>
#include "../Xext/extensions/Xext.h" #include "../Xext/extensions/Xext.h"
#include "../Xext/extensions/extutil.h" #include "../Xext/extensions/extutil.h"
...@@ -43,6 +42,10 @@ ...@@ -43,6 +42,10 @@
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#endif #endif
#if SDL_VIDEO_DRIVER_X11_XINPUT
#include <X11/extensions/XInput.h>
#endif
/* /*
* When using the "dynamic X11" functionality, we duplicate all the Xlib * When using the "dynamic X11" functionality, we duplicate all the Xlib
* symbols that would be referenced by SDL inside of SDL itself. * symbols that would be referenced by SDL inside of SDL itself.
......
...@@ -29,12 +29,6 @@ ...@@ -29,12 +29,6 @@
#include "SDL_x11video.h" #include "SDL_x11video.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
extern int motion; /* the motion event id defined by an XInput function */
extern int button_pressed; /* the button_pressed event id defined by an XInput function */
extern int button_released; /* the button_released event id defined by an XInput function */
extern int proximity_in; /* the proximity in event defined by an XInput function */
extern int proximity_out; /* the proximity out event defined by an XInput function */
static void static void
X11_DispatchEvent(_THIS) X11_DispatchEvent(_THIS)
{ {
......
...@@ -20,22 +20,25 @@ ...@@ -20,22 +20,25 @@
slouken@libsdl.org slouken@libsdl.org
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#include "SDL_x11video.h" #include "SDL_x11video.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
void void
X11_InitMouse(_THIS) X11_InitMouse(_THIS)
{ {
extern XDevice **SDL_XDevices; #if SDL_VIDEO_DRIVER_X11_XINPUT
XDevice **newDevices; XDevice **newDevices;
int i, j, index = 0, numOfDevices; int i, j, index = 0, numOfDevices;
extern int SDL_NumOfXDevices;
XDeviceInfo *DevList; XDeviceInfo *DevList;
XAnyClassPtr deviceClass; XAnyClassPtr deviceClass;
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_XDevices = NULL;
SDL_NumOfXDevices = 0;
if (!SDL_X11_HAVE_XINPUT)
return; /* should have dynamically loaded, but wasn't available. */
/* we're getting the list of input devices */ /* we're getting the list of input devices */
DevList = XListInputDevices(data->display, &numOfDevices); DevList = XListInputDevices(data->display, &numOfDevices);
SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice)); SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice));
...@@ -92,6 +95,7 @@ X11_InitMouse(_THIS) ...@@ -92,6 +95,7 @@ X11_InitMouse(_THIS)
XFreeDeviceList(DevList); XFreeDeviceList(DevList);
SDL_NumOfXDevices = index; SDL_NumOfXDevices = index;
#endif
} }
void void
...@@ -99,6 +103,8 @@ X11_QuitMouse(_THIS) ...@@ -99,6 +103,8 @@ X11_QuitMouse(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
/* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */
/* let's delete all of the mice */ /* let's delete all of the mice */
SDL_MouseQuit(); SDL_MouseQuit();
} }
......
...@@ -144,11 +144,6 @@ SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,S ...@@ -144,11 +144,6 @@ SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,S
SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return) SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return) SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
/*SDL_X11_SYM(XDeviceInfo* , XListInputDevices, (Display* a, int* b), (a,b),return)
SDL_X11_SYM(void, XFreeDeviceList, (XDeviceInfo* a), (a),)
SDL_X11_SYM(int, XSelectExtensionEvent,(Display* a, Window b, XEventClass* c, int d),(a,b,c,d),return)
SDL_X11_SYM(XDevice* ,XOpenDevice,(Display* a, XID b), (a,b),return)*/
#if NeedWidePrototypes #if NeedWidePrototypes
SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return) SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
#else #else
...@@ -218,6 +213,15 @@ SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return) ...@@ -218,6 +213,15 @@ SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return) SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
#endif #endif
/* XInput support for multiple mice, tablets, etc. */
#if SDL_VIDEO_DRIVER_X11_XINPUT
SDL_X11_MODULE(XINPUT)
SDL_X11_SYM(XDeviceInfo*,XListInputDevices,(Display *a,int *b),(a,b),return)
SDL_X11_SYM(void,XFreeDeviceList,(XDeviceInfo *a),(a),)
SDL_X11_SYM(int,XSelectExtensionEvent,(Display *a,Window b,XEventClass *c,int d),(a,b,c,d),return)
SDL_X11_SYM(XDevice*,XOpenDevice,(Display *a,XID b),(a,b),return)
#endif
/* *INDENT-ON* */ /* *INDENT-ON* */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
#include "SDL_x11video.h" #include "SDL_x11video.h"
#if SDL_VIDEO_DRIVER_X11_XINPUT
XDevice **SDL_XDevices; XDevice **SDL_XDevices;
int SDL_NumOfXDevices; int SDL_NumOfXDevices;
XEventClass SDL_XEvents[256]; XEventClass SDL_XEvents[256];
int SDL_NumOfXEvents; int SDL_NumOfXEvents;
int motion, button_pressed, button_released; /* the definitions of the mice events */ int motion, button_pressed, button_released; /* the definitions of the mice events */
int proximity_in, proximity_out; int proximity_in, proximity_out;
#endif
/* Initialization/Query functions */ /* Initialization/Query functions */
static int X11_VideoInit(_THIS); static int X11_VideoInit(_THIS);
...@@ -248,6 +249,12 @@ X11_VideoInit(_THIS) ...@@ -248,6 +249,12 @@ X11_VideoInit(_THIS)
} }
X11_InitMouse(_this); X11_InitMouse(_this);
/* Set reasonable defaults, in case !SDL_VIDEO_DRIVER_X11_XINPUT */
motion = MotionNotify;
button_pressed = ButtonPress;
button_released = ButtonRelease;
#if SDL_VIDEO_DRIVER_X11_XINPUT
/* we're generating the table of events that should be recognized */ /* we're generating the table of events that should be recognized */
for (i = 0; i < SDL_NumOfXDevices; ++i) { for (i = 0; i < SDL_NumOfXDevices; ++i) {
/* button events */ /* button events */
...@@ -283,6 +290,7 @@ X11_VideoInit(_THIS) ...@@ -283,6 +290,7 @@ X11_VideoInit(_THIS)
} }
SDL_NumOfXEvents = index; SDL_NumOfXEvents = index;
#endif
return 0; return 0;
} }
...@@ -306,7 +314,10 @@ X11_VideoQuit(_THIS) ...@@ -306,7 +314,10 @@ X11_VideoQuit(_THIS)
X11_QuitModes(_this); X11_QuitModes(_this);
X11_QuitKeyboard(_this); X11_QuitKeyboard(_this);
X11_QuitMouse(_this); X11_QuitMouse(_this);
#if SDL_VIDEO_DRIVER_X11_XINPUT
free(SDL_XDevices); free(SDL_XDevices);
#endif
} }
/* vim: set ts=4 sw=4 expandtab: */ /* vim: set ts=4 sw=4 expandtab: */
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/XInput.h>
#if SDL_VIDEO_DRIVER_X11_XINERAMA #if SDL_VIDEO_DRIVER_X11_XINERAMA
#include "../Xext/extensions/Xinerama.h" #include "../Xext/extensions/Xinerama.h"
...@@ -46,6 +45,9 @@ ...@@ -46,6 +45,9 @@
#if SDL_VIDEO_DRIVER_X11_DPMS #if SDL_VIDEO_DRIVER_X11_DPMS
#include <X11/extensions/dpms.h> #include <X11/extensions/dpms.h>
#endif #endif
#if SDL_VIDEO_DRIVER_X11_XINPUT
#include <X11/extensions/XInput.h>
#endif
#include "SDL_x11dyn.h" #include "SDL_x11dyn.h"
...@@ -59,6 +61,22 @@ ...@@ -59,6 +61,22 @@
/* Private display data */ /* Private display data */
#if SDL_VIDEO_DRIVER_X11_XINPUT
/* !!! FIXME: should be in SDL_VideoData, not globals. */
extern XDevice **SDL_XDevices;
extern int SDL_NumOfXDevices;
extern XEventClass SDL_XEvents[256];
extern int SDL_NumOfXEvents;
#endif
/* !!! FIXME: should be in SDL_VideoData, not globals. */
/* !!! FIXME: change these names, too. */
extern int motion; /* the motion event id defined by an XInput function */
extern int button_pressed; /* the button_pressed event id defined by an XInput function */
extern int button_released; /* the button_released event id defined by an XInput function */
extern int proximity_in; /* the proximity in event defined by an XInput function */
extern int proximity_out; /* the proximity out event defined by an XInput function */
typedef struct SDL_VideoData typedef struct SDL_VideoData
{ {
Display *display; Display *display;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment