X11: Fixed high mouse buttons mappings and horizontal wheels (thanks, Daniel!).
authorRyan C. Gordon
Sun, 31 May 2015 00:58:43 -0400
changeset 9686d84e21b0b0ba
parent 9685 525f13ccf27f
child 9687 ad9917a91c06
X11: Fixed high mouse buttons mappings and horizontal wheels (thanks, Daniel!).

Fixes Bugzilla #2472.
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Sun May 31 00:50:30 2015 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Sun May 31 00:58:43 2015 -0400
     1.3 @@ -173,14 +173,15 @@
     1.4      XEvent *event = (XEvent *) arg;
     1.5      /* we only handle buttons 4 and 5 - false positive avoidance */
     1.6      if (chkev->type == ButtonRelease &&
     1.7 -        (event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
     1.8 +        (event->xbutton.button == Button4 || event->xbutton.button == Button5 ||
     1.9 +         event->xbutton.button == 6 || event->xbutton.button == 7) &&
    1.10          chkev->xbutton.button == event->xbutton.button &&
    1.11          chkev->xbutton.time == event->xbutton.time)
    1.12          return True;
    1.13      return False;
    1.14  }
    1.15  
    1.16 -static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
    1.17 +static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * xticks,int * yticks)
    1.18  {
    1.19      XEvent relevent;
    1.20      if (X11_XPending(display)) {
    1.21 @@ -198,12 +199,19 @@
    1.22              (XPointer) event)) {
    1.23  
    1.24              /* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse,
    1.25 -               Button4 maps to wheel up, Button5 maps to wheel down. */
    1.26 +               Button4 maps to (vertical) wheel up, Button5 maps to wheel down.
    1.27 +               Horizontal scrolling usually maps to 6 and 7 which have no name */
    1.28              if (event->xbutton.button == Button4) {
    1.29 -                *ticks = 1;
    1.30 +                *yticks = 1;
    1.31              }
    1.32              else if (event->xbutton.button == Button5) {
    1.33 -                *ticks = -1;
    1.34 +                *yticks = -1;
    1.35 +            }
    1.36 +            else if (event->xbutton.button == 6) {
    1.37 +                *xticks = 1;
    1.38 +            }
    1.39 +            else if (event->xbutton.button == 7) {
    1.40 +                *xticks = -1;
    1.41              }
    1.42              return SDL_TRUE;
    1.43          }
    1.44 @@ -1023,22 +1031,33 @@
    1.45          break;
    1.46  
    1.47      case ButtonPress:{
    1.48 -            int ticks = 0;
    1.49 -            if (X11_IsWheelEvent(display,&xevent,&ticks)) {
    1.50 -                SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
    1.51 +            int xticks = 0, yticks = 0;
    1.52 +            if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) {
    1.53 +                SDL_SendMouseWheel(data->window, 0, xticks, yticks, SDL_MOUSEWHEEL_NORMAL);
    1.54              } else {
    1.55 -                if(xevent.xbutton.button == Button1) {
    1.56 +                int button = xevent.xbutton.button;
    1.57 +                if(button == Button1) {
    1.58                      if (ProcessHitTest(_this, data, &xevent)) {
    1.59                          break;  /* don't pass this event on to app. */
    1.60                      }
    1.61                  }
    1.62 -                SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
    1.63 +                else if(button > 7) {
    1.64 +                    /* X button values 4-7 are used for scrolling, so X1 is 8, X2 is 9, ...
    1.65 +                       => subtract (8-SDL_BUTTON_X1) to get value SDL expects */
    1.66 +                    button -= (8-SDL_BUTTON_X1);
    1.67 +                }
    1.68 +                SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
    1.69              }
    1.70          }
    1.71          break;
    1.72  
    1.73      case ButtonRelease:{
    1.74 -            SDL_SendMouseButton(data->window, 0, SDL_RELEASED, xevent.xbutton.button);
    1.75 +            int button = xevent.xbutton.button;
    1.76 +            if (button > 7) {
    1.77 +                /* see explanation at case ButtonPress */
    1.78 +                button -= (8-SDL_BUTTON_X1);
    1.79 +            }
    1.80 +            SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
    1.81          }
    1.82          break;
    1.83