Mercurial > sdl-ios-xcode
changeset 2763:6fc50bdd88c0
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.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 17 Sep 2008 08:20:57 +0000 |
parents | 90de10bc38ec |
children | 4868c0df2e83 |
files | configure.in include/SDL_config.h.in src/video/x11/SDL_x11dyn.c src/video/x11/SDL_x11dyn.h src/video/x11/SDL_x11events.c src/video/x11/SDL_x11mouse.c src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.c src/video/x11/SDL_x11video.h |
diffstat | 9 files changed, 95 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in Mon Sep 15 20:48:51 2008 +0000 +++ b/configure.in Wed Sep 17 08:20:57 2008 +0000 @@ -989,6 +989,7 @@ x11ext_lib='/usr/X11R6/lib/libXext.6.dylib' xrender_lib='/usr/X11R6/lib/libXrender.1.dylib' xrandr_lib='/usr/X11R6/lib/libXrandr.2.dylib' + xinput_lib='/usr/X11R6/lib/libXi.6.dylib' ;; *-*-osf*) x11_lib='libX11.so' @@ -1025,6 +1026,12 @@ xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`] 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 ;; esac @@ -1041,9 +1048,6 @@ SOURCES="$SOURCES $srcdir/src/video/Xext/XmuStdCmap/*.c" 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 enable_x11_shared=$x11_symbols_private fi @@ -1066,7 +1070,7 @@ AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib") else enable_x11_shared=no - EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext -lXi" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext" fi have_video=yes @@ -1128,6 +1132,33 @@ if test x$definitely_enable_video_x11_xrandr = xyes; then AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR) 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_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]), , enable_video_x11_dpms=yes)
--- a/include/SDL_config.h.in Mon Sep 15 20:48:51 2008 +0000 +++ b/include/SDL_config.h.in Wed Sep 17 08:20:57 2008 +0000 @@ -282,10 +282,12 @@ #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR #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_XINERAMA #undef SDL_VIDEO_DRIVER_X11_XME #undef SDL_VIDEO_DRIVER_X11_XRANDR +#undef SDL_VIDEO_DRIVER_X11_XINPUT #undef SDL_VIDEO_DRIVER_X11_XV #undef SDL_VIDEO_DRIVER_XBIOS
--- a/src/video/x11/SDL_x11dyn.c Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11dyn.c Wed Sep 17 08:20:57 2008 +0000 @@ -52,12 +52,16 @@ #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL #endif +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL +#endif static x11dynlib x11libs[] = { {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR}, + {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT}, }; static void
--- a/src/video/x11/SDL_x11dyn.h Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11dyn.h Wed Sep 17 08:20:57 2008 +0000 @@ -29,7 +29,6 @@ #include <X11/Xatom.h> #include <X11/Xlibint.h> #include <X11/Xproto.h> -//#include <X11/extensions/XInput.h> #include "../Xext/extensions/Xext.h" #include "../Xext/extensions/extutil.h" @@ -43,6 +42,10 @@ #include <X11/extensions/Xrandr.h> #endif +#if SDL_VIDEO_DRIVER_X11_XINPUT +#include <X11/extensions/XInput.h> +#endif + /* * When using the "dynamic X11" functionality, we duplicate all the Xlib * symbols that would be referenced by SDL inside of SDL itself.
--- a/src/video/x11/SDL_x11events.c Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11events.c Wed Sep 17 08:20:57 2008 +0000 @@ -29,12 +29,6 @@ #include "SDL_x11video.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 X11_DispatchEvent(_THIS) {
--- a/src/video/x11/SDL_x11mouse.c Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11mouse.c Wed Sep 17 08:20:57 2008 +0000 @@ -20,22 +20,25 @@ slouken@libsdl.org */ #include "SDL_config.h" - #include "SDL_x11video.h" - #include "../../events/SDL_mouse_c.h" void X11_InitMouse(_THIS) { - extern XDevice **SDL_XDevices; +#if SDL_VIDEO_DRIVER_X11_XINPUT XDevice **newDevices; int i, j, index = 0, numOfDevices; - extern int SDL_NumOfXDevices; XDeviceInfo *DevList; XAnyClassPtr deviceClass; 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 */ DevList = XListInputDevices(data->display, &numOfDevices); SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice)); @@ -92,6 +95,7 @@ XFreeDeviceList(DevList); SDL_NumOfXDevices = index; +#endif } void @@ -99,6 +103,8 @@ { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + /* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */ + /* let's delete all of the mice */ SDL_MouseQuit(); }
--- a/src/video/x11/SDL_x11sym.h Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11sym.h Wed Sep 17 08:20:57 2008 +0000 @@ -144,11 +144,6 @@ 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(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 SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return) #else @@ -218,6 +213,15 @@ SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return) #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* */ /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/x11/SDL_x11video.c Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11video.c Wed Sep 17 08:20:57 2008 +0000 @@ -28,13 +28,14 @@ #include "SDL_x11video.h" +#if SDL_VIDEO_DRIVER_X11_XINPUT XDevice **SDL_XDevices; int SDL_NumOfXDevices; XEventClass SDL_XEvents[256]; int SDL_NumOfXEvents; - int motion, button_pressed, button_released; /* the definitions of the mice events */ int proximity_in, proximity_out; +#endif /* Initialization/Query functions */ static int X11_VideoInit(_THIS); @@ -248,6 +249,12 @@ } 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 */ for (i = 0; i < SDL_NumOfXDevices; ++i) { /* button events */ @@ -283,6 +290,7 @@ } SDL_NumOfXEvents = index; +#endif return 0; } @@ -306,7 +314,10 @@ X11_QuitModes(_this); X11_QuitKeyboard(_this); X11_QuitMouse(_this); + +#if SDL_VIDEO_DRIVER_X11_XINPUT free(SDL_XDevices); +#endif } /* vim: set ts=4 sw=4 expandtab: */
--- a/src/video/x11/SDL_x11video.h Mon Sep 15 20:48:51 2008 +0000 +++ b/src/video/x11/SDL_x11video.h Wed Sep 17 08:20:57 2008 +0000 @@ -29,7 +29,6 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> -#include <X11/extensions/XInput.h> #if SDL_VIDEO_DRIVER_X11_XINERAMA #include "../Xext/extensions/Xinerama.h" @@ -46,6 +45,9 @@ #if SDL_VIDEO_DRIVER_X11_DPMS #include <X11/extensions/dpms.h> #endif +#if SDL_VIDEO_DRIVER_X11_XINPUT +#include <X11/extensions/XInput.h> +#endif #include "SDL_x11dyn.h" @@ -59,6 +61,22 @@ /* 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 { Display *display;