Some cleanups on the new XInput code.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 17 Sep 2008 08:20:57 +0000
changeset 27636fc50bdd88c0
parent 2762 90de10bc38ec
child 2764 4868c0df2e83
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.
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
     1.1 --- a/configure.in	Mon Sep 15 20:48:51 2008 +0000
     1.2 +++ b/configure.in	Wed Sep 17 08:20:57 2008 +0000
     1.3 @@ -989,6 +989,7 @@
     1.4                      x11ext_lib='/usr/X11R6/lib/libXext.6.dylib'
     1.5                      xrender_lib='/usr/X11R6/lib/libXrender.1.dylib'
     1.6                      xrandr_lib='/usr/X11R6/lib/libXrandr.2.dylib'
     1.7 +                    xinput_lib='/usr/X11R6/lib/libXi.6.dylib'
     1.8                      ;;
     1.9                  *-*-osf*)
    1.10                      x11_lib='libX11.so'
    1.11 @@ -1025,6 +1026,12 @@
    1.12                                  xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
    1.13                              fi
    1.14                          fi
    1.15 +                        if test "x$xinput_lib" = "x"; then
    1.16 +                            xinput_lib=[`ls -- $path/libXi.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
    1.17 +                            if test "x$xinput_lib" = "x"; then
    1.18 +                                xinput_lib=[`ls -- $path/libXi.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
    1.19 +                            fi
    1.20 +                        fi
    1.21                      done
    1.22                      ;;
    1.23              esac
    1.24 @@ -1041,9 +1048,6 @@
    1.25              SOURCES="$SOURCES $srcdir/src/video/Xext/XmuStdCmap/*.c"
    1.26              EXTRA_CFLAGS="$EXTRA_CFLAGS $X_CFLAGS"
    1.27  
    1.28 -echo "FIXME: Need to get dynamic loading of XInput working"
    1.29 -	    enable_x11_shared=no
    1.30 -
    1.31              if test x$enable_x11_shared = xmaybe; then
    1.32                  enable_x11_shared=$x11_symbols_private
    1.33              fi
    1.34 @@ -1066,7 +1070,7 @@
    1.35                  AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib")
    1.36              else
    1.37                  enable_x11_shared=no
    1.38 -                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext -lXi"
    1.39 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext"
    1.40              fi
    1.41              have_video=yes
    1.42  
    1.43 @@ -1128,6 +1132,33 @@
    1.44              if test x$definitely_enable_video_x11_xrandr = xyes; then
    1.45                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
    1.46              fi
    1.47 +            AC_ARG_ENABLE(video-x11-xinput,
    1.48 +AC_HELP_STRING([--enable-video-x11-xinput], [enable X11 XInput extension for manymouse, tablets, etc [[default=yes]]]),
    1.49 +                            , enable_video_x11_xinput=yes)
    1.50 +            if test x$enable_video_x11_xinput = xyes; then
    1.51 +                definitely_enable_video_x11_xinput=no
    1.52 +                AC_CHECK_HEADER(X11/extensions/XInput.h,
    1.53 +                                have_xinput_h_hdr=yes,
    1.54 +                                have_xinput_h_hdr=no,
    1.55 +                                [#include <X11/Xlib.h>
    1.56 +                                ])
    1.57 +                if test x$have_xinput_h_hdr = xyes; then
    1.58 +                    if test x$enable_x11_shared = xyes && test x$xinput_lib != x ; then
    1.59 +                        echo "-- dynamic libXi -> $xinput_lib"
    1.60 +                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT, "$xinput_lib")
    1.61 +                        definitely_enable_video_x11_xinput=yes
    1.62 +                    else
    1.63 +                        AC_CHECK_LIB(Xi, XOpenDevice, have_xinput_lib=yes)
    1.64 +                        if test x$have_xinput_lib = xyes ; then
    1.65 +                            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lXi"
    1.66 +                            definitely_enable_video_x11_xinput=yes
    1.67 +                        fi
    1.68 +                    fi
    1.69 +                fi
    1.70 +            fi
    1.71 +            if test x$definitely_enable_video_x11_xinput = xyes; then
    1.72 +                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT)
    1.73 +            fi
    1.74              AC_ARG_ENABLE(video-x11-dpms,
    1.75  AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
    1.76                              , enable_video_x11_dpms=yes)
     2.1 --- a/include/SDL_config.h.in	Mon Sep 15 20:48:51 2008 +0000
     2.2 +++ b/include/SDL_config.h.in	Wed Sep 17 08:20:57 2008 +0000
     2.3 @@ -282,10 +282,12 @@
     2.4  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
     2.5  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
     2.6  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
     2.7 +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
     2.8  #undef SDL_VIDEO_DRIVER_X11_VIDMODE
     2.9  #undef SDL_VIDEO_DRIVER_X11_XINERAMA
    2.10  #undef SDL_VIDEO_DRIVER_X11_XME
    2.11  #undef SDL_VIDEO_DRIVER_X11_XRANDR
    2.12 +#undef SDL_VIDEO_DRIVER_X11_XINPUT
    2.13  #undef SDL_VIDEO_DRIVER_X11_XV
    2.14  #undef SDL_VIDEO_DRIVER_XBIOS
    2.15  
     3.1 --- a/src/video/x11/SDL_x11dyn.c	Mon Sep 15 20:48:51 2008 +0000
     3.2 +++ b/src/video/x11/SDL_x11dyn.c	Wed Sep 17 08:20:57 2008 +0000
     3.3 @@ -52,12 +52,16 @@
     3.4  #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
     3.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
     3.6  #endif
     3.7 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
     3.8 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL
     3.9 +#endif
    3.10  
    3.11  static x11dynlib x11libs[] = {
    3.12      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
    3.13      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
    3.14      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER},
    3.15      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
    3.16 +    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
    3.17  };
    3.18  
    3.19  static void
     4.1 --- a/src/video/x11/SDL_x11dyn.h	Mon Sep 15 20:48:51 2008 +0000
     4.2 +++ b/src/video/x11/SDL_x11dyn.h	Wed Sep 17 08:20:57 2008 +0000
     4.3 @@ -29,7 +29,6 @@
     4.4  #include <X11/Xatom.h>
     4.5  #include <X11/Xlibint.h>
     4.6  #include <X11/Xproto.h>
     4.7 -//#include <X11/extensions/XInput.h>
     4.8  #include "../Xext/extensions/Xext.h"
     4.9  #include "../Xext/extensions/extutil.h"
    4.10  
    4.11 @@ -43,6 +42,10 @@
    4.12  #include <X11/extensions/Xrandr.h>
    4.13  #endif
    4.14  
    4.15 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    4.16 +#include <X11/extensions/XInput.h>
    4.17 +#endif
    4.18 +
    4.19  /*
    4.20   * When using the "dynamic X11" functionality, we duplicate all the Xlib
    4.21   *  symbols that would be referenced by SDL inside of SDL itself.
     5.1 --- a/src/video/x11/SDL_x11events.c	Mon Sep 15 20:48:51 2008 +0000
     5.2 +++ b/src/video/x11/SDL_x11events.c	Wed Sep 17 08:20:57 2008 +0000
     5.3 @@ -29,12 +29,6 @@
     5.4  #include "SDL_x11video.h"
     5.5  #include "../../events/SDL_events_c.h"
     5.6  
     5.7 -extern int motion;              /* the motion event id defined by an XInput function */
     5.8 -extern int button_pressed;      /* the button_pressed event id defined by an XInput function */
     5.9 -extern int button_released;     /* the button_released event id defined by an XInput function */
    5.10 -extern int proximity_in;        /* the proximity in event defined by an XInput function */
    5.11 -extern int proximity_out;       /* the proximity out event defined by an XInput function */
    5.12 -
    5.13  static void
    5.14  X11_DispatchEvent(_THIS)
    5.15  {
     6.1 --- a/src/video/x11/SDL_x11mouse.c	Mon Sep 15 20:48:51 2008 +0000
     6.2 +++ b/src/video/x11/SDL_x11mouse.c	Wed Sep 17 08:20:57 2008 +0000
     6.3 @@ -20,22 +20,25 @@
     6.4      slouken@libsdl.org
     6.5  */
     6.6  #include "SDL_config.h"
     6.7 -
     6.8  #include "SDL_x11video.h"
     6.9 -
    6.10  #include "../../events/SDL_mouse_c.h"
    6.11  
    6.12  void
    6.13  X11_InitMouse(_THIS)
    6.14  {
    6.15 -    extern XDevice **SDL_XDevices;
    6.16 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    6.17      XDevice **newDevices;
    6.18      int i, j, index = 0, numOfDevices;
    6.19 -    extern int SDL_NumOfXDevices;
    6.20      XDeviceInfo *DevList;
    6.21      XAnyClassPtr deviceClass;
    6.22      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    6.23  
    6.24 +    SDL_XDevices = NULL;
    6.25 +    SDL_NumOfXDevices = 0;
    6.26 +
    6.27 +    if (!SDL_X11_HAVE_XINPUT)
    6.28 +        return;  /* should have dynamically loaded, but wasn't available. */
    6.29 +
    6.30      /* we're getting the list of input devices */
    6.31      DevList = XListInputDevices(data->display, &numOfDevices);
    6.32      SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice));
    6.33 @@ -92,6 +95,7 @@
    6.34      XFreeDeviceList(DevList);
    6.35  
    6.36      SDL_NumOfXDevices = index;
    6.37 +#endif
    6.38  }
    6.39  
    6.40  void
    6.41 @@ -99,6 +103,8 @@
    6.42  {
    6.43      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    6.44  
    6.45 +    /* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */
    6.46 +
    6.47      /* let's delete all of the mice */
    6.48      SDL_MouseQuit();
    6.49  }
     7.1 --- a/src/video/x11/SDL_x11sym.h	Mon Sep 15 20:48:51 2008 +0000
     7.2 +++ b/src/video/x11/SDL_x11sym.h	Wed Sep 17 08:20:57 2008 +0000
     7.3 @@ -144,11 +144,6 @@
     7.4  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
     7.5  SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
     7.6  
     7.7 -/*SDL_X11_SYM(XDeviceInfo* , XListInputDevices, (Display* a, int* b), (a,b),return)
     7.8 -SDL_X11_SYM(void, XFreeDeviceList, (XDeviceInfo* a), (a),)
     7.9 -SDL_X11_SYM(int, XSelectExtensionEvent,(Display* a, Window b, XEventClass* c, int d),(a,b,c,d),return)
    7.10 -SDL_X11_SYM(XDevice* ,XOpenDevice,(Display* a, XID b), (a,b),return)*/
    7.11 -
    7.12  #if NeedWidePrototypes
    7.13  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
    7.14  #else
    7.15 @@ -218,6 +213,15 @@
    7.16  SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
    7.17  #endif
    7.18  
    7.19 +/* XInput support for multiple mice, tablets, etc. */
    7.20 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    7.21 +SDL_X11_MODULE(XINPUT)
    7.22 +SDL_X11_SYM(XDeviceInfo*,XListInputDevices,(Display *a,int *b),(a,b),return)
    7.23 +SDL_X11_SYM(void,XFreeDeviceList,(XDeviceInfo *a),(a),)
    7.24 +SDL_X11_SYM(int,XSelectExtensionEvent,(Display *a,Window b,XEventClass *c,int d),(a,b,c,d),return)
    7.25 +SDL_X11_SYM(XDevice*,XOpenDevice,(Display *a,XID b),(a,b),return)
    7.26 +#endif
    7.27 +
    7.28  /* *INDENT-ON* */
    7.29  
    7.30  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/x11/SDL_x11video.c	Mon Sep 15 20:48:51 2008 +0000
     8.2 +++ b/src/video/x11/SDL_x11video.c	Wed Sep 17 08:20:57 2008 +0000
     8.3 @@ -28,13 +28,14 @@
     8.4  
     8.5  #include "SDL_x11video.h"
     8.6  
     8.7 +#if SDL_VIDEO_DRIVER_X11_XINPUT
     8.8  XDevice **SDL_XDevices;
     8.9  int SDL_NumOfXDevices;
    8.10  XEventClass SDL_XEvents[256];
    8.11  int SDL_NumOfXEvents;
    8.12 -
    8.13  int motion, button_pressed, button_released;    /* the definitions of the mice events */
    8.14  int proximity_in, proximity_out;
    8.15 +#endif
    8.16  
    8.17  /* Initialization/Query functions */
    8.18  static int X11_VideoInit(_THIS);
    8.19 @@ -248,6 +249,12 @@
    8.20      }
    8.21      X11_InitMouse(_this);
    8.22  
    8.23 +    /* Set reasonable defaults, in case !SDL_VIDEO_DRIVER_X11_XINPUT */
    8.24 +    motion = MotionNotify;
    8.25 +    button_pressed = ButtonPress;
    8.26 +    button_released = ButtonRelease;
    8.27 +
    8.28 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    8.29      /* we're generating the table of events that should be recognized */
    8.30      for (i = 0; i < SDL_NumOfXDevices; ++i) {
    8.31          /* button events */
    8.32 @@ -283,6 +290,7 @@
    8.33  
    8.34      }
    8.35      SDL_NumOfXEvents = index;
    8.36 +#endif
    8.37  
    8.38      return 0;
    8.39  }
    8.40 @@ -306,7 +314,10 @@
    8.41      X11_QuitModes(_this);
    8.42      X11_QuitKeyboard(_this);
    8.43      X11_QuitMouse(_this);
    8.44 +
    8.45 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    8.46      free(SDL_XDevices);
    8.47 +#endif
    8.48  }
    8.49  
    8.50  /* vim: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/x11/SDL_x11video.h	Mon Sep 15 20:48:51 2008 +0000
     9.2 +++ b/src/video/x11/SDL_x11video.h	Wed Sep 17 08:20:57 2008 +0000
     9.3 @@ -29,7 +29,6 @@
     9.4  #include <X11/Xlib.h>
     9.5  #include <X11/Xutil.h>
     9.6  #include <X11/Xatom.h>
     9.7 -#include <X11/extensions/XInput.h>
     9.8  
     9.9  #if SDL_VIDEO_DRIVER_X11_XINERAMA
    9.10  #include "../Xext/extensions/Xinerama.h"
    9.11 @@ -46,6 +45,9 @@
    9.12  #if SDL_VIDEO_DRIVER_X11_DPMS
    9.13  #include <X11/extensions/dpms.h>
    9.14  #endif
    9.15 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    9.16 +#include <X11/extensions/XInput.h>
    9.17 +#endif
    9.18  
    9.19  #include "SDL_x11dyn.h"
    9.20  
    9.21 @@ -59,6 +61,22 @@
    9.22  
    9.23  /* Private display data */
    9.24  
    9.25 +#if SDL_VIDEO_DRIVER_X11_XINPUT
    9.26 +/* !!! FIXME: should be in SDL_VideoData, not globals. */
    9.27 +extern XDevice **SDL_XDevices;
    9.28 +extern int SDL_NumOfXDevices;
    9.29 +extern XEventClass SDL_XEvents[256];
    9.30 +extern int SDL_NumOfXEvents;
    9.31 +#endif
    9.32 +
    9.33 +/* !!! FIXME: should be in SDL_VideoData, not globals. */
    9.34 +/* !!! FIXME: change these names, too. */
    9.35 +extern int motion;              /* the motion event id defined by an XInput function */
    9.36 +extern int button_pressed;      /* the button_pressed event id defined by an XInput function */
    9.37 +extern int button_released;     /* the button_released event id defined by an XInput function */
    9.38 +extern int proximity_in;        /* the proximity in event defined by an XInput function */
    9.39 +extern int proximity_out;       /* the proximity out event defined by an XInput function */
    9.40 +
    9.41  typedef struct SDL_VideoData
    9.42  {
    9.43      Display *display;