The core pointer is comprised of merging the inputs of all mice.
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2009 18:29:20 +0000
changeset 2992dbff5769d742
parent 2991 f4d14219c2aa
child 2993 2fad80c77c17
The core pointer is comprised of merging the inputs of all mice.
If there are other mice, they should show up in the device list, and
we want to report events from those devices instead of the core events.
However, if XInput isn't supported or we can't find other mice in the
device list, we'll add the core pointer and interpret normal mouse events.
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11mouse.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Sun Jan 04 17:30:00 2009 +0000
     1.2 +++ b/src/video/x11/SDL_x11events.c	Sun Jan 04 18:29:20 2009 +0000
     1.3 @@ -280,21 +280,6 @@
     1.4          }
     1.5          break;
     1.6  
     1.7 -    case MotionNotify:
     1.8 -#ifdef DEBUG_MOTION
     1.9 -        printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    1.10 -#endif
    1.11 -        SDL_SendMouseMotion(0, 0, xevent.xmotion.x, xevent.xmotion.y, 0);
    1.12 -        break;
    1.13 -
    1.14 -    case ButtonPress:
    1.15 -        SDL_SendMouseButton(0, SDL_PRESSED, xevent.xbutton.button);
    1.16 -        break;
    1.17 -
    1.18 -    case ButtonRelease:
    1.19 -        SDL_SendMouseButton(0, SDL_RELEASED, xevent.xbutton.button);
    1.20 -        break;
    1.21 -
    1.22      default:{
    1.23  #if SDL_VIDEO_DRIVER_X11_XINPUT
    1.24              for (i = 0; i < SDL_GetNumMice(); ++i) {
    1.25 @@ -304,6 +289,22 @@
    1.26                  mouse = SDL_GetMouse(i);
    1.27                  data = (X11_MouseData *) mouse->driverdata;
    1.28                  if (!data) {
    1.29 +                    switch (xevent.type) {
    1.30 +                    case MotionNotify:
    1.31 +#ifdef DEBUG_MOTION
    1.32 +                        printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    1.33 +#endif
    1.34 +                        SDL_SendMouseMotion(0, 0, xevent.xmotion.x, xevent.xmotion.y, 0);
    1.35 +                        break;
    1.36 +
    1.37 +                    case ButtonPress:
    1.38 +                        SDL_SendMouseButton(0, SDL_PRESSED, xevent.xbutton.button);
    1.39 +                        break;
    1.40 +
    1.41 +                    case ButtonRelease:
    1.42 +                        SDL_SendMouseButton(0, SDL_RELEASED, xevent.xbutton.button);
    1.43 +                        break;
    1.44 +                    }
    1.45                      continue;
    1.46                  }
    1.47  
     2.1 --- a/src/video/x11/SDL_x11mouse.c	Sun Jan 04 17:30:00 2009 +0000
     2.2 +++ b/src/video/x11/SDL_x11mouse.c	Sun Jan 04 18:29:20 2009 +0000
     2.3 @@ -50,19 +50,14 @@
     2.4      int event_code;
     2.5      XEventClass xEvent;
     2.6  #endif
     2.7 -
     2.8 -    SDL_zero(mouse);
     2.9 -    SDL_AddMouse(&mouse, "CorePointer", 0, 0, 1);
    2.10 +    int num_mice = 0;
    2.11  
    2.12  #if SDL_VIDEO_DRIVER_X11_XINPUT
    2.13 -    if (!SDL_X11_HAVE_XINPUT) {
    2.14 -        /* should have dynamically loaded, but wasn't available. */
    2.15 -        return;
    2.16 -    }
    2.17 -
    2.18      /* we're getting the list of input devices */
    2.19      n = 0;
    2.20 -    DevList = XListInputDevices(display, &n);
    2.21 +    if (SDL_X11_HAVE_XINPUT) {
    2.22 +        DevList = XListInputDevices(display, &n);
    2.23 +    }
    2.24  
    2.25      /* we're aquiring valuators: mice, tablets, etc. */
    2.26      for (i = 0; i < n; ++i) {
    2.27 @@ -127,6 +122,9 @@
    2.28                      } else {
    2.29                          SDL_AddMouse(&mouse, DevList[i].name, 0, 0, 1);
    2.30                      }
    2.31 +                    if (DevList[i].use == IsXExtensionPointer) {
    2.32 +                        ++num_mice;
    2.33 +                    }
    2.34                      break;
    2.35                  }
    2.36                  /* if it's not class we're interested in, lets go further */
    2.37 @@ -138,6 +136,11 @@
    2.38      }
    2.39      XFreeDeviceList(DevList);
    2.40  #endif
    2.41 +
    2.42 +    if (num_mice == 0) {
    2.43 +        SDL_zero(mouse);
    2.44 +        SDL_AddMouse(&mouse, "CorePointer", 0, 0, 1);
    2.45 +    }
    2.46  }
    2.47  
    2.48  void