Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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.
  • Loading branch information
icculus committed Sep 17, 2008
1 parent ae92ffa commit 4feb460ba42e6afc57ee706713ddabef80e6f823
@@ -989,6 +989,7 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
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 @@ 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'`]
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 @@ AC_HELP_STRING([--enable-x11-shared], [dynamically load X11 support [[default=ma
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 @@ echo "FIXME: Need to get dynamic loading of XInput working"
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 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful
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)
@@ -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

@@ -52,12 +52,16 @@ typedef struct
#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
@@ -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.
@@ -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)
{
@@ -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,13 +95,16 @@ X11_InitMouse(_THIS)
XFreeDeviceList(DevList);

SDL_NumOfXDevices = index;
#endif
}

void
X11_QuitMouse(_THIS)
{
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();
}
@@ -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(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,DPMSEnable,(Display *dpy),(dpy),return)
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: */
@@ -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_VideoInit(_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 */
for (i = 0; i < SDL_NumOfXDevices; ++i) {
/* button events */
@@ -283,6 +290,7 @@ X11_VideoInit(_THIS)

}
SDL_NumOfXEvents = index;
#endif

return 0;
}
@@ -306,7 +314,10 @@ X11_VideoQuit(_THIS)
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: */
@@ -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;

0 comments on commit 4feb460

Please sign in to comment.