http://wilku.ravenlord.ws/doku.php?id=documentation for information how things work. Currently implemented: detecting many pointing devices and pressure detection. Still a bug. Each program has to be comipled with a flag -lXi gsoc2008_manymouse
authorSzymon Wilczek <kazeuser@gmail.com>
Fri, 06 Jun 2008 15:23:29 +0000
branchgsoc2008_manymouse
changeset 376064f346a83ed3
parent 3759 064c178558b7
child 3761 e0c95ad1ba87
http://wilku.ravenlord.ws/doku.php?id=documentation for information how things work. Currently implemented: detecting many pointing devices and pressure detection. Still a bug. Each program has to be comipled with a flag -lXi
configure.in
include/SDL_events.h
include/SDL_keysym.h
include/SDL_mouse.h
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
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
src/video/x11/SDL_x11window.c
     1.1 --- a/configure.in	Fri Jun 06 14:50:56 2008 +0000
     1.2 +++ b/configure.in	Fri Jun 06 15:23:29 2008 +0000
     1.3 @@ -1055,7 +1055,7 @@
     1.4                  AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT, "$x11ext_lib")
     1.5              else
     1.6                  enable_x11_shared=no
     1.7 -                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext"
     1.8 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $X_LIBS -lX11 -lXext -lXi"
     1.9              fi
    1.10              have_video=yes
    1.11  
     2.1 --- a/include/SDL_events.h	Fri Jun 06 14:50:56 2008 +0000
     2.2 +++ b/include/SDL_events.h	Fri Jun 06 15:23:29 2008 +0000
     2.3 @@ -170,6 +170,7 @@
     2.4      Uint8 state;            /**< The current button state */
     2.5      int x;                  /**< X coordinate, relative to window */
     2.6      int y;                  /**< Y coordinate, relative to window */
     2.7 +    int z;
     2.8      int xrel;               /**< The relative motion in the X direction */
     2.9      int yrel;               /**< The relative motion in the Y direction */
    2.10      SDL_WindowID windowID;  /**< The window with mouse focus, if any */
     3.1 --- a/include/SDL_keysym.h	Fri Jun 06 14:50:56 2008 +0000
     3.2 +++ b/include/SDL_keysym.h	Fri Jun 06 15:23:29 2008 +0000
     3.3 @@ -242,7 +242,7 @@
     3.4      SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
     3.5      SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
     3.6      SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
     3.7 -    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
     3.8 +    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
     3.9  };
    3.10  
    3.11  /**
     4.1 --- a/include/SDL_mouse.h	Fri Jun 06 14:50:56 2008 +0000
     4.2 +++ b/include/SDL_mouse.h	Fri Jun 06 15:23:29 2008 +0000
     4.3 @@ -203,6 +203,11 @@
     4.4     Button 2:	Middle mouse button
     4.5     Button 3:	Right mouse button
     4.6   */
     4.7 +
     4.8 +extern DECLSPEC int SDLCALL SDL_GetNumOfMice(void);
     4.9 +
    4.10 +extern DECLSPEC char* SDLCALL SDL_GetMouseName(int index);
    4.11 +
    4.12  #define SDL_BUTTON(X)		(1 << ((X)-1))
    4.13  #define SDL_BUTTON_LEFT		1
    4.14  #define SDL_BUTTON_MIDDLE	2
     5.1 --- a/src/events/SDL_mouse.c	Fri Jun 06 14:50:56 2008 +0000
     5.2 +++ b/src/events/SDL_mouse.c	Fri Jun 06 15:23:29 2008 +0000
     5.3 @@ -31,6 +31,8 @@
     5.4  static int SDL_num_mice;
     5.5  static int SDL_current_mouse;
     5.6  static SDL_Mouse **SDL_mice;
     5.7 +int *SDL_IdIndex;
     5.8 +int SDL_highestId;
     5.9  
    5.10  
    5.11  /* Public functions */
    5.12 @@ -50,11 +52,11 @@
    5.13  }
    5.14  
    5.15  int
    5.16 -SDL_AddMouse(const SDL_Mouse * mouse, int index)
    5.17 +SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name)
    5.18  {
    5.19      SDL_Mouse **mice;
    5.20      int selected_mouse;
    5.21 -
    5.22 +    char* temp_name;
    5.23      /* Add the mouse to the list of mice */
    5.24      if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    5.25          mice =
    5.26 @@ -74,8 +76,8 @@
    5.27          return -1;
    5.28      }
    5.29      *SDL_mice[index] = *mouse;
    5.30 -
    5.31 -    /* Create the default cursor for the mouse */
    5.32 +    SDL_mice[index]->name=SDL_malloc(strlen(name)*sizeof(char));
    5.33 +    strcpy(SDL_mice[index]->name,name);
    5.34      SDL_mice[index]->cursor_shown = SDL_TRUE;
    5.35      selected_mouse = SDL_SelectMouse(index);
    5.36      SDL_mice[index]->cur_cursor = NULL;
    5.37 @@ -98,6 +100,7 @@
    5.38      }
    5.39  
    5.40      mouse->def_cursor = NULL;
    5.41 +    SDL_free(mouse->name);
    5.42      while (mouse->cursors) {
    5.43          SDL_FreeCursor(mouse->cursors);
    5.44      }
    5.45 @@ -266,8 +269,9 @@
    5.46  }
    5.47  
    5.48  void
    5.49 -SDL_SetMouseFocus(int index, SDL_WindowID windowID)
    5.50 +SDL_SetMouseFocus(int id, SDL_WindowID windowID)
    5.51  {
    5.52 +    int index = SDL_GetIndexById(id);
    5.53      SDL_Mouse *mouse = SDL_GetMouse(index);
    5.54      int i;
    5.55      SDL_bool focus;
    5.56 @@ -315,8 +319,9 @@
    5.57  }
    5.58  
    5.59  int
    5.60 -SDL_SendMouseMotion(int index, int relative, int x, int y)
    5.61 +SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
    5.62  {
    5.63 +    int index=SDL_GetIndexById(id);
    5.64      SDL_Mouse *mouse = SDL_GetMouse(index);
    5.65      int posted;
    5.66      int xrel;
    5.67 @@ -352,6 +357,7 @@
    5.68      }
    5.69      mouse->xdelta += xrel;
    5.70      mouse->ydelta += yrel;
    5.71 +    mouse->z=z;
    5.72  
    5.73      /* Move the mouse cursor, if needed */
    5.74      if (mouse->cursor_shown && !mouse->relative_mode &&
    5.75 @@ -368,6 +374,7 @@
    5.76          event.motion.state = mouse->buttonstate;
    5.77          event.motion.x = mouse->x;
    5.78          event.motion.y = mouse->y;
    5.79 +        event.motion.z = mouse->z;
    5.80          event.motion.xrel = xrel;
    5.81          event.motion.yrel = yrel;
    5.82          event.motion.windowID = mouse->focus;
    5.83 @@ -377,8 +384,9 @@
    5.84  }
    5.85  
    5.86  int
    5.87 -SDL_SendMouseButton(int index, Uint8 state, Uint8 button)
    5.88 +SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
    5.89  {
    5.90 +    int index=SDL_GetIndexById(id);
    5.91      SDL_Mouse *mouse = SDL_GetMouse(index);
    5.92      int posted;
    5.93      Uint8 type;
    5.94 @@ -398,10 +406,10 @@
    5.95          mouse->buttonstate |= SDL_BUTTON(button);
    5.96          break;
    5.97      case SDL_RELEASED:
    5.98 -        if (!(mouse->buttonstate & SDL_BUTTON(button))) {
    5.99 -            /* Ignore this event, no state change */
   5.100 -            return 0;
   5.101 -        }
   5.102 +        //if (!(mouse->buttonstate & SDL_BUTTON(button))) {
   5.103 +        //    /* Ignore this event, no state change */
   5.104 +        //    return 0;
   5.105 +        //}*/
   5.106          type = SDL_MOUSEBUTTONUP;
   5.107          mouse->buttonstate &= ~SDL_BUTTON(button);
   5.108          break;
   5.109 @@ -463,7 +471,7 @@
   5.110          mouse->WarpMouse(mouse, windowID, x, y);
   5.111      } else {
   5.112          SDL_SetMouseFocus(SDL_current_mouse, windowID);
   5.113 -        SDL_SendMouseMotion(SDL_current_mouse, 0, x, y);
   5.114 +        SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
   5.115      }
   5.116  }
   5.117  
   5.118 @@ -649,4 +657,54 @@
   5.119      return shown;
   5.120  }
   5.121  
   5.122 +void SDL_SetIndexId(int id, int index)
   5.123 +{
   5.124 +    if(id>SDL_highestId)
   5.125 +    {
   5.126 +        int *indexes;
   5.127 +        indexes =
   5.128 +            (int*) SDL_realloc(SDL_IdIndex,
   5.129 +                                       (id + 1) * sizeof(int));
   5.130 +        if (!indexes) {
   5.131 +            SDL_OutOfMemory();
   5.132 +            return -1;
   5.133 +        }
   5.134 +        SDL_IdIndex=indexes;
   5.135 +        SDL_IdIndex[id]=index;
   5.136 +        SDL_highestId=id;
   5.137 +    }
   5.138 +    else
   5.139 +    {
   5.140 +        SDL_IdIndex[id]=index;
   5.141 +    }
   5.142 +}
   5.143 +
   5.144 +int SDL_GetIndexById(int id)
   5.145 +{
   5.146 +    if(id>SDL_highestId)
   5.147 +    {
   5.148 +        return -1;
   5.149 +    }
   5.150 +    else
   5.151 +    {
   5.152 +        return SDL_IdIndex[id];
   5.153 +    }
   5.154 +}
   5.155 +
   5.156 +int SDL_GetNumOfMice(void)
   5.157 +{
   5.158 +    return SDL_num_mice;
   5.159 +}
   5.160 +
   5.161 +char* SDL_GetMouseName(int index)
   5.162 +{
   5.163 +    SDL_Mouse* mouse = SDL_GetMouse(index);
   5.164 +    if(!mouse)
   5.165 +    {
   5.166 +        return NULL;
   5.167 +    }
   5.168 +    return mouse->name;
   5.169 +}
   5.170 +
   5.171 +
   5.172  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/events/SDL_mouse_c.h	Fri Jun 06 14:50:56 2008 +0000
     6.2 +++ b/src/events/SDL_mouse_c.h	Fri Jun 06 15:23:29 2008 +0000
     6.3 @@ -58,10 +58,13 @@
     6.4  
     6.5      /* Data common to all mice */
     6.6      SDL_WindowID focus;
     6.7 +    int which;
     6.8      int x;
     6.9      int y;
    6.10 +    int z;
    6.11      int xdelta;
    6.12      int ydelta;
    6.13 +    char* name;
    6.14      Uint8 buttonstate;
    6.15      SDL_bool relative_mode;
    6.16      SDL_bool flush_motion;
    6.17 @@ -84,7 +87,7 @@
    6.18  /* Add a mouse, possibly reattaching at a particular index (or -1),
    6.19     returning the index of the mouse, or -1 if there was an error.
    6.20   */
    6.21 -extern int SDL_AddMouse(const SDL_Mouse * mouse, int index);
    6.22 +extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name);
    6.23  
    6.24  /* Remove a mouse at an index, clearing the slot for later */
    6.25  extern void SDL_DelMouse(int index);
    6.26 @@ -96,7 +99,7 @@
    6.27  extern void SDL_SetMouseFocus(int index, SDL_WindowID windowID);
    6.28  
    6.29  /* Send a mouse motion event for a mouse at an index */
    6.30 -extern int SDL_SendMouseMotion(int index, int relative, int x, int y);
    6.31 +extern int SDL_SendMouseMotion(int index, int relative, int x, int y, int z);
    6.32  
    6.33  /* Send a mouse button event for a mouse at an index */
    6.34  extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
    6.35 @@ -107,6 +110,16 @@
    6.36  /* Shutdown the mouse subsystem */
    6.37  extern void SDL_MouseQuit(void);
    6.38  
    6.39 +extern int SDL_GetIndexById(int id);
    6.40 +
    6.41 +extern void SDL_SetIndexId(int id, int index);
    6.42 +
    6.43 +extern int SDL_GetNumOfMice(void);
    6.44 +
    6.45 +extern char* SDL_GetMouseName(int index);
    6.46 +
    6.47 +
    6.48 +
    6.49  #endif /* _SDL_mouse_c_h */
    6.50  
    6.51  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/x11/SDL_x11dyn.h	Fri Jun 06 14:50:56 2008 +0000
     7.2 +++ b/src/video/x11/SDL_x11dyn.h	Fri Jun 06 15:23:29 2008 +0000
     7.3 @@ -29,7 +29,7 @@
     7.4  #include <X11/Xatom.h>
     7.5  #include <X11/Xlibint.h>
     7.6  #include <X11/Xproto.h>
     7.7 -
     7.8 +//#include <X11/extensions/XInput.h>
     7.9  #include "../Xext/extensions/Xext.h"
    7.10  #include "../Xext/extensions/extutil.h"
    7.11  
     8.1 --- a/src/video/x11/SDL_x11events.c	Fri Jun 06 14:50:56 2008 +0000
     8.2 +++ b/src/video/x11/SDL_x11events.c	Fri Jun 06 15:23:29 2008 +0000
     8.3 @@ -29,13 +29,16 @@
     8.4  #include "SDL_x11video.h"
     8.5  #include "../../events/SDL_events_c.h"
     8.6  
     8.7 +//XEventClass *SDL_XEvents;
     8.8 +//int SDL_numOfEvents;
     8.9 +
    8.10  static void
    8.11  X11_DispatchEvent(_THIS)
    8.12  {
    8.13      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    8.14      SDL_WindowData *data;
    8.15      XEvent xevent;
    8.16 -    int i;
    8.17 +    int i,z;
    8.18  
    8.19      SDL_zero(xevent);           /* valgrind fix. --ryan. */
    8.20      XNextEvent(videodata->display, &xevent);
    8.21 @@ -91,9 +94,10 @@
    8.22  #endif
    8.23              if ((xevent.xcrossing.mode != NotifyGrab) &&
    8.24                  (xevent.xcrossing.mode != NotifyUngrab)) {
    8.25 -                SDL_SetMouseFocus(videodata->mouse, data->windowID);
    8.26 -                SDL_SendMouseMotion(videodata->mouse, 0, xevent.xcrossing.x,
    8.27 -                                    xevent.xcrossing.y);
    8.28 +			    XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
    8.29 +                SDL_SetMouseFocus(move->deviceid, data->windowID);
    8.30 +                SDL_SendMouseMotion(move->deviceid, 0, move->x,
    8.31 +                                    move->y,move->axis_data[2]);
    8.32              }
    8.33          }
    8.34          break;
    8.35 @@ -111,9 +115,10 @@
    8.36              if ((xevent.xcrossing.mode != NotifyGrab) &&
    8.37                  (xevent.xcrossing.mode != NotifyUngrab) &&
    8.38                  (xevent.xcrossing.detail != NotifyInferior)) {
    8.39 -                SDL_SendMouseMotion(videodata->mouse, 0,
    8.40 -                                    xevent.xcrossing.x, xevent.xcrossing.y);
    8.41 -                SDL_SetMouseFocus(videodata->mouse, 0);
    8.42 +			    XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
    8.43 +                SDL_SendMouseMotion(move->deviceid, 0,
    8.44 +                                    move->x, move->y,move->axis_data[2]);
    8.45 +                SDL_SetMouseFocus(move->deviceid, 0);
    8.46              }
    8.47          }
    8.48          break;
    8.49 @@ -167,26 +172,30 @@
    8.50          break;
    8.51  
    8.52          /* Mouse motion? */
    8.53 -    case MotionNotify:{
    8.54 +    case 103:{ //MotionNotify
    8.55  #ifdef DEBUG_MOTION
    8.56              printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    8.57  #endif
    8.58 -            SDL_SendMouseMotion(videodata->mouse, 0, xevent.xmotion.x,
    8.59 -                                xevent.xmotion.y);
    8.60 +			XDeviceMotionEvent* move=(XDeviceMotionEvent*)&xevent;
    8.61 +            SDL_SendMouseMotion(move->deviceid, 0, move->x,
    8.62 +                                move->y,move->axis_data[2]);
    8.63          }
    8.64          break;
    8.65 +    /*case MotionNotify:{
    8.66  
    8.67          /* Mouse button press? */
    8.68 -    case ButtonPress:{
    8.69 -            SDL_SendMouseButton(videodata->mouse, SDL_PRESSED,
    8.70 -                                xevent.xbutton.button);
    8.71 +    case 101:{//ButtonPress
    8.72 +			XDeviceButtonPressedEvent* pressed=(XDeviceButtonPressedEvent*)&xevent;
    8.73 +            SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
    8.74 +                                pressed->button);
    8.75          }
    8.76          break;
    8.77  
    8.78          /* Mouse button release? */
    8.79 -    case ButtonRelease:{
    8.80 -            SDL_SendMouseButton(videodata->mouse, SDL_RELEASED,
    8.81 -                                xevent.xbutton.button);
    8.82 +    case 102:{//ButtonRelease
    8.83 +			XDeviceButtonReleasedEvent* released=(XDeviceButtonReleasedEvent*)&xevent;
    8.84 +            SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
    8.85 +                                released->button);
    8.86          }
    8.87          break;
    8.88  
     9.1 --- a/src/video/x11/SDL_x11mouse.c	Fri Jun 06 14:50:56 2008 +0000
     9.2 +++ b/src/video/x11/SDL_x11mouse.c	Fri Jun 06 15:23:29 2008 +0000
     9.3 @@ -28,11 +28,45 @@
     9.4  void
     9.5  X11_InitMouse(_THIS)
     9.6  {
     9.7 +    extern XDevice **SDL_XDevices;
     9.8 +    XDevice **newDevices;
     9.9 +    int i,j,index=0, numOfDevices;
    9.10 +    extern int SDL_NumOfXDevices;
    9.11 +    XDeviceInfo *DevList;
    9.12 +    XAnyClassPtr deviceClass;
    9.13      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    9.14 -    SDL_Mouse mouse;
    9.15 +   
    9.16 +    DevList=XListInputDevices(data->display, &numOfDevices);
    9.17  
    9.18 -    SDL_zero(mouse);
    9.19 -    data->mouse = SDL_AddMouse(&mouse, -1);
    9.20 +    for(i=0;i<numOfDevices;++i)
    9.21 +    {
    9.22 +        if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard))
    9.23 +        {
    9.24 +            deviceClass=DevList[i].inputclassinfo;
    9.25 +            for(j=0;j<DevList[i].num_classes;++j)
    9.26 +            {
    9.27 +                if(deviceClass->class==ValuatorClass)
    9.28 +                {
    9.29 +                    newDevices= (XDevice**) SDL_realloc(SDL_XDevices, (index+1)*sizeof(*newDevices));
    9.30 +                    if(!newDevices)
    9.31 +                    {
    9.32 +                        SDL_OutOfMemory();
    9.33 +                        return -1;
    9.34 +                    }
    9.35 +                    SDL_XDevices=newDevices;
    9.36 +                    SDL_XDevices[index]=XOpenDevice(data->display,DevList[i].id);
    9.37 +                    SDL_Mouse mouse;
    9.38 +                    SDL_zero(mouse);
    9.39 +                    SDL_SetIndexId(DevList[i].id,index);
    9.40 +                    data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name);
    9.41 +                    break;
    9.42 +                }
    9.43 +                deviceClass=(XAnyClassPtr)((char*)deviceClass + deviceClass->length);
    9.44 +            }
    9.45 +        }
    9.46 +    }
    9.47 +    XFreeDeviceList(DevList);
    9.48 +    SDL_NumOfXDevices=index;
    9.49  }
    9.50  
    9.51  void
    9.52 @@ -40,7 +74,7 @@
    9.53  {
    9.54      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    9.55  
    9.56 -    SDL_DelMouse(data->mouse);
    9.57 +    SDL_MouseQuit();
    9.58  }
    9.59  
    9.60  /* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/x11/SDL_x11sym.h	Fri Jun 06 14:50:56 2008 +0000
    10.2 +++ b/src/video/x11/SDL_x11sym.h	Fri Jun 06 15:23:29 2008 +0000
    10.3 @@ -144,6 +144,11 @@
    10.4  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
    10.5  SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
    10.6  
    10.7 +/*SDL_X11_SYM(XDeviceInfo* , XListInputDevices, (Display* a, int* b), (a,b),return)
    10.8 +SDL_X11_SYM(void, XFreeDeviceList, (XDeviceInfo* a), (a),)
    10.9 +SDL_X11_SYM(int, XSelectExtensionEvent,(Display* a, Window b, XEventClass* c, int d),(a,b,c,d),return)
   10.10 +SDL_X11_SYM(XDevice* ,XOpenDevice,(Display* a, XID b), (a,b),return)*/
   10.11 +
   10.12  #if NeedWidePrototypes
   10.13  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
   10.14  #else
    11.1 --- a/src/video/x11/SDL_x11video.c	Fri Jun 06 14:50:56 2008 +0000
    11.2 +++ b/src/video/x11/SDL_x11video.c	Fri Jun 06 15:23:29 2008 +0000
    11.3 @@ -30,6 +30,11 @@
    11.4  //#include "SDL_d3drender.h"
    11.5  //#include "SDL_gdirender.h"
    11.6  
    11.7 +XDevice **SDL_XDevices;
    11.8 +int SDL_NumOfXDevices;
    11.9 +XEventClass SDL_XEvents[256];
   11.10 +int SDL_NumOfXEvents;
   11.11 +
   11.12  /* Initialization/Query functions */
   11.13  static int X11_VideoInit(_THIS);
   11.14  static void X11_VideoQuit(_THIS);
   11.15 @@ -96,8 +101,8 @@
   11.16  static void
   11.17  X11_DeleteDevice(SDL_VideoDevice * device)
   11.18  {
   11.19 +    int i;
   11.20      SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
   11.21 -
   11.22      if (data->display) {
   11.23          XCloseDisplay(data->display);
   11.24      }
   11.25 @@ -212,6 +217,8 @@
   11.26  int
   11.27  X11_VideoInit(_THIS)
   11.28  {
   11.29 +    int i,index=0,c_not_needed;
   11.30 +    XEventClass xEvent;
   11.31      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   11.32  
   11.33      /* Get the window class name, usually the name of the application */
   11.34 @@ -240,6 +247,72 @@
   11.35          return -1;
   11.36      }
   11.37      X11_InitMouse(_this);
   11.38 +    for(i=0;i<SDL_NumOfXDevices;++i)
   11.39 +    {   
   11.40 +        DeviceKeyPress(SDL_XDevices[i],c_not_needed,xEvent);
   11.41 +	    if (xEvent) SDL_XEvents[index++] = xEvent;
   11.42 +	    DeviceKeyRelease(SDL_XDevices[i],c_not_needed,xEvent);
   11.43 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.44 +
   11.45 +	/* focus events */
   11.46 +	DeviceFocusIn(SDL_XDevices[i],c_not_needed,xEvent);
   11.47 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.48 +	DeviceFocusOut(SDL_XDevices[i],c_not_needed,xEvent);
   11.49 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.50 +
   11.51 +	/* button events */
   11.52 +	DeviceButtonPress(SDL_XDevices[i],c_not_needed,xEvent);
   11.53 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.54 +	DeviceButtonRelease(SDL_XDevices[i],c_not_needed,xEvent);
   11.55 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.56 +
   11.57 +	/* proximity events */
   11.58 +	ProximityIn(SDL_XDevices[i],c_not_needed,xEvent);
   11.59 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.60 +	ProximityOut(SDL_XDevices[i],c_not_needed,xEvent);
   11.61 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.62 +
   11.63 +	/* motion events */
   11.64 +	DeviceMotionNotify(SDL_XDevices[i],c_not_needed,xEvent);
   11.65 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.66 +
   11.67 +	/* device state */
   11.68 +	DeviceStateNotify(SDL_XDevices[i],c_not_needed,xEvent);
   11.69 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.70 +	DeviceMappingNotify(SDL_XDevices[i],
   11.71 +			c_not_needed,xEvent);
   11.72 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.73 +	ChangeDeviceNotify(SDL_XDevices[i],c_not_needed,xEvent);
   11.74 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.75 +
   11.76 +#if 0
   11.77 +	/* this cuts the motion data down - not sure if this is useful */
   11.78 +	DevicePointerMotionHint(SDL_XDevices[i],
   11.79 +			c_not_neededINPUTEVENT_DEVICE_POINTER_MOTION_HINT],xEvent);
   11.80 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.81 +#endif
   11.82 +
   11.83 +	/* button motion */
   11.84 +	DeviceButtonMotion(SDL_XDevices[i],
   11.85 +			c_not_needed,xEvent);
   11.86 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.87 +	DeviceButton1Motion(SDL_XDevices[i],
   11.88 +			c_not_needed,xEvent);
   11.89 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.90 +	DeviceButton2Motion(SDL_XDevices[i],
   11.91 +			c_not_needed,xEvent);
   11.92 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.93 +	DeviceButton3Motion(SDL_XDevices[i],
   11.94 +			c_not_needed,xEvent);
   11.95 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.96 +	DeviceButton4Motion(SDL_XDevices[i],
   11.97 +			c_not_needed,xEvent);
   11.98 +	if (xEvent) SDL_XEvents[index++] = xEvent;
   11.99 +	DeviceButton5Motion(SDL_XDevices[i],
  11.100 +			c_not_needed,xEvent);
  11.101 +	if (xEvent) SDL_XEvents[index++] = xEvent;
  11.102 +    }
  11.103 +    SDL_NumOfXEvents=index;
  11.104  
  11.105      return 0;
  11.106  }
  11.107 @@ -247,6 +320,8 @@
  11.108  void
  11.109  X11_VideoQuit(_THIS)
  11.110  {
  11.111 +    int i;
  11.112 +
  11.113      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
  11.114  
  11.115      if (data->classname) {
  11.116 @@ -263,6 +338,7 @@
  11.117      X11_QuitModes(_this);
  11.118      X11_QuitKeyboard(_this);
  11.119      X11_QuitMouse(_this);
  11.120 +    free(SDL_XDevices);
  11.121  }
  11.122  
  11.123  /* vim: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/video/x11/SDL_x11video.h	Fri Jun 06 14:50:56 2008 +0000
    12.2 +++ b/src/video/x11/SDL_x11video.h	Fri Jun 06 15:23:29 2008 +0000
    12.3 @@ -29,6 +29,7 @@
    12.4  #include <X11/Xlib.h>
    12.5  #include <X11/Xutil.h>
    12.6  #include <X11/Xatom.h>
    12.7 +#include <X11/extensions/XInput.h>
    12.8  
    12.9  #if SDL_VIDEO_DRIVER_X11_XINERAMA
   12.10  #include "../Xext/extensions/Xinerama.h"
   12.11 @@ -68,7 +69,7 @@
   12.12      int numwindows;
   12.13      SDL_WindowData **windowlist;
   12.14      int windowlistlength;
   12.15 -    int mouse;
   12.16 +    int *mouse;
   12.17      int keyboard;
   12.18      Atom WM_DELETE_WINDOW;
   12.19      SDL_scancode key_layout[256];
    13.1 --- a/src/video/x11/SDL_x11window.c	Fri Jun 06 14:50:56 2008 +0000
    13.2 +++ b/src/video/x11/SDL_x11window.c	Fri Jun 06 15:23:29 2008 +0000
    13.3 @@ -153,6 +153,8 @@
    13.4      XSizeHints *sizehints;
    13.5      XWMHints *wmhints;
    13.6      XClassHint *classhints;
    13.7 +    extern XEventClass SDL_XEvents[];
    13.8 +    extern int SDL_NumOfXEvents;
    13.9  
   13.10  #if SDL_VIDEO_DRIVER_X11_XINERAMA
   13.11  /* FIXME
   13.12 @@ -481,20 +483,24 @@
   13.13          Uint32 fevent = 0;
   13.14          pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
   13.15                        XNFilterEvents, &fevent, NULL);
   13.16 +        XMapWindow(data->display,w);
   13.17          XSelectInput(data->display, w,
   13.18                       (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   13.19                        ExposureMask | ButtonPressMask | ButtonReleaseMask |
   13.20                        PointerMotionMask | KeyPressMask | KeyReleaseMask |
   13.21                        PropertyChangeMask | StructureNotifyMask |
   13.22                        KeymapStateMask | fevent));
   13.23 +    XSelectExtensionEvent(data->display, w, SDL_XEvents, SDL_NumOfXEvents);
   13.24      }
   13.25  #else
   13.26 +    XMapWindow(data->display,w);
   13.27      XSelectInput(data->display, w,
   13.28                   (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   13.29                    ExposureMask | ButtonPressMask | ButtonReleaseMask |
   13.30                    PointerMotionMask | KeyPressMask | KeyReleaseMask |
   13.31                    PropertyChangeMask | StructureNotifyMask |
   13.32                    KeymapStateMask));
   13.33 +    XSelectExtensionEvent(data->display, w, SDL_XEvents, SDL_NumOfXEvents);
   13.34  #endif
   13.35  
   13.36      return 0;