Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Some cleanups on the new XInput code.
Browse files Browse the repository at this point in the history
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 4feb460
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 22 deletions.
39 changes: 35 additions & 4 deletions configure.in
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config.h.in
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/video/x11/SDL_x11dyn.c
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/video/x11/SDL_x11dyn.h
Expand Up @@ -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"

Expand All @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -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)
{
Expand Down
14 changes: 10 additions & 4 deletions src/video/x11/SDL_x11mouse.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}
Expand Down
14 changes: 9 additions & 5 deletions src/video/x11/SDL_x11sym.h
Expand Up @@ -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
Expand Down Expand Up @@ -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: */
13 changes: 12 additions & 1 deletion src/video/x11/SDL_x11video.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -283,6 +290,7 @@ X11_VideoInit(_THIS)

}
SDL_NumOfXEvents = index;
#endif

return 0;
}
Expand All @@ -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: */
20 changes: 19 additions & 1 deletion src/video/x11/SDL_x11video.h
Expand Up @@ -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"
Expand All @@ -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"

Expand All @@ -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;
Expand Down

0 comments on commit 4feb460

Please sign in to comment.