src/video/x11/SDL_x11events.c
changeset 2710 44e49d3fa6cf
parent 2328 91e601d9df8b
child 2738 79c1bd651f04
     1.1 --- a/src/video/x11/SDL_x11events.c	Mon Aug 25 05:30:28 2008 +0000
     1.2 +++ b/src/video/x11/SDL_x11events.c	Mon Aug 25 06:33:00 2008 +0000
     1.3 @@ -29,6 +29,12 @@
     1.4  #include "SDL_x11video.h"
     1.5  #include "../../events/SDL_events_c.h"
     1.6  
     1.7 +extern int motion;              /* the motion event id defined by an XInput function */
     1.8 +extern int button_pressed;      /* the button_pressed event id defined by an XInput function */
     1.9 +extern int button_released;     /* the button_released event id defined by an XInput function */
    1.10 +extern int proximity_in;        /* the proximity in event defined by an XInput function */
    1.11 +extern int proximity_out;       /* the proximity out event defined by an XInput function */
    1.12 +
    1.13  static void
    1.14  X11_DispatchEvent(_THIS)
    1.15  {
    1.16 @@ -91,9 +97,10 @@
    1.17  #endif
    1.18              if ((xevent.xcrossing.mode != NotifyGrab) &&
    1.19                  (xevent.xcrossing.mode != NotifyUngrab)) {
    1.20 -                SDL_SetMouseFocus(videodata->mouse, data->windowID);
    1.21 -                SDL_SendMouseMotion(videodata->mouse, 0, xevent.xcrossing.x,
    1.22 -                                    xevent.xcrossing.y);
    1.23 +                XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
    1.24 +                SDL_SetMouseFocus(move->deviceid, data->windowID);
    1.25 +                SDL_SendMouseMotion(move->deviceid, 0, move->x,
    1.26 +                                    move->y, move->axis_data[2]);
    1.27              }
    1.28          }
    1.29          break;
    1.30 @@ -111,9 +118,8 @@
    1.31              if ((xevent.xcrossing.mode != NotifyGrab) &&
    1.32                  (xevent.xcrossing.mode != NotifyUngrab) &&
    1.33                  (xevent.xcrossing.detail != NotifyInferior)) {
    1.34 -                SDL_SendMouseMotion(videodata->mouse, 0,
    1.35 -                                    xevent.xcrossing.x, xevent.xcrossing.y);
    1.36 -                SDL_SetMouseFocus(videodata->mouse, 0);
    1.37 +                XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
    1.38 +                SDL_SetMouseFocus(move->deviceid, 0);
    1.39              }
    1.40          }
    1.41          break;
    1.42 @@ -166,30 +172,6 @@
    1.43          }
    1.44          break;
    1.45  
    1.46 -        /* Mouse motion? */
    1.47 -    case MotionNotify:{
    1.48 -#ifdef DEBUG_MOTION
    1.49 -            printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    1.50 -#endif
    1.51 -            SDL_SendMouseMotion(videodata->mouse, 0, xevent.xmotion.x,
    1.52 -                                xevent.xmotion.y);
    1.53 -        }
    1.54 -        break;
    1.55 -
    1.56 -        /* Mouse button press? */
    1.57 -    case ButtonPress:{
    1.58 -            SDL_SendMouseButton(videodata->mouse, SDL_PRESSED,
    1.59 -                                xevent.xbutton.button);
    1.60 -        }
    1.61 -        break;
    1.62 -
    1.63 -        /* Mouse button release? */
    1.64 -    case ButtonRelease:{
    1.65 -            SDL_SendMouseButton(videodata->mouse, SDL_RELEASED,
    1.66 -                                xevent.xbutton.button);
    1.67 -        }
    1.68 -        break;
    1.69 -
    1.70          /* Key press? */
    1.71      case KeyPress:{
    1.72              KeyCode keycode = xevent.xkey.keycode;
    1.73 @@ -301,8 +283,44 @@
    1.74          break;
    1.75  
    1.76      default:{
    1.77 +            if (xevent.type == motion) {        /* MotionNotify */
    1.78 +#ifdef DEBUG_MOTION
    1.79 +                printf("X11 motion: %d,%d\n", xevent.xmotion.x,
    1.80 +                       xevent.xmotion.y);
    1.81 +#endif
    1.82 +                XWindowAttributes attrib;
    1.83 +                XGetWindowAttributes(videodata->display,
    1.84 +                                     ((XAnyEvent *) & xevent)->window,
    1.85 +                                     &attrib);
    1.86 +                SDL_UpdateCoordinates(attrib.width, attrib.height);
    1.87 +                XDeviceMotionEvent *move = (XDeviceMotionEvent *) & xevent;
    1.88 +                SDL_SendMouseMotion(move->deviceid, 0, move->x,
    1.89 +                                    move->y, move->axis_data[2]);
    1.90 +            } else if (xevent.type == button_pressed) { /* ButtonPress */
    1.91 +                XDeviceButtonPressedEvent *pressed =
    1.92 +                    (XDeviceButtonPressedEvent *) & xevent;
    1.93 +                SDL_SendMouseButton(pressed->deviceid, SDL_PRESSED,
    1.94 +                                    pressed->button);
    1.95 +            } else if (xevent.type == button_released) {        /* ButtonRelease */
    1.96 +                XDeviceButtonReleasedEvent *released =
    1.97 +                    (XDeviceButtonReleasedEvent *) & xevent;
    1.98 +                SDL_SendMouseButton(released->deviceid, SDL_RELEASED,
    1.99 +                                    released->button);
   1.100 +            } else if (xevent.type == proximity_in) {
   1.101 +                XProximityNotifyEvent *proximity =
   1.102 +                    (XProximityNotifyEvent *) & xevent;
   1.103 +                SDL_SendProximity(proximity->deviceid, proximity->x,
   1.104 +                                  proximity->y, SDL_PROXIMITYIN);
   1.105 +            } else if (xevent.type == proximity_out) {
   1.106 +                XProximityNotifyEvent *proximity =
   1.107 +                    (XProximityNotifyEvent *) & xevent;
   1.108 +                SDL_SendProximity(proximity->deviceid, proximity->x,
   1.109 +                                  proximity->y, SDL_PROXIMITYOUT);
   1.110 +            }
   1.111  #ifdef DEBUG_XEVENTS
   1.112 -            printf("Unhandled event %d\n", xevent.type);
   1.113 +            else {
   1.114 +                printf("Unhandled event %d\n", xevent.type);
   1.115 +            }
   1.116  #endif
   1.117          }
   1.118          break;