haiku: Add support for relative mouse mode.
authorGerasim Troeglazov <3dEyes@gmail.com>
Mon, 11 Nov 2019 22:21:17 -0500
changeset 132357e53f9a1d5e4
parent 13234 c6c5c0c9ad2b
child 13236 00da92ddae19
haiku: Add support for relative mouse mode.

Partially fixes Bugzilla #4442.
src/main/haiku/SDL_BApp.h
src/video/haiku/SDL_BWin.h
     1.1 --- a/src/main/haiku/SDL_BApp.h	Mon Nov 11 22:18:21 2019 -0500
     1.2 +++ b/src/main/haiku/SDL_BApp.h	Mon Nov 11 22:21:17 2019 -0500
     1.3 @@ -228,7 +228,6 @@
     1.4              return;
     1.5          }
     1.6          win = GetSDLWindow(winID);
     1.7 -        SDL_SendMouseMotion(win, 0, 0, x, y);
     1.8  
     1.9  		// Simple relative mode support for mouse.
    1.10  		if ((SDL_GetMouse()->relative_mode ||
    1.11 @@ -237,10 +236,14 @@
    1.12  			int winWidth, winHeight, winPosX, winPosY;
    1.13  			SDL_GetWindowSize(win, &winWidth, &winHeight);
    1.14  			SDL_GetWindowPosition(win, &winPosX, &winPosY);
    1.15 +			int dx = x - (winWidth / 2);
    1.16 +			int dy = y - (winHeight / 2);
    1.17 +			SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
    1.18  			set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
    1.19  			if (!be_app->IsCursorHidden())
    1.20  				be_app->HideCursor();
    1.21  		} else {
    1.22 +			SDL_SendMouseMotion(win, 0, 0, x, y);
    1.23  			if (be_app->IsCursorHidden())
    1.24  				be_app->ShowCursor();
    1.25  		}
     2.1 --- a/src/video/haiku/SDL_BWin.h	Mon Nov 11 22:18:21 2019 -0500
     2.2 +++ b/src/video/haiku/SDL_BWin.h	Mon Nov 11 22:21:17 2019 -0500
     2.3 @@ -319,22 +319,17 @@
     2.4                  && msg->FindInt32("be:transit", &transit) == B_OK) {
     2.5                  _MouseMotionEvent(where, transit);
     2.6              }
     2.7 +            break;
     2.8  
     2.9 -            /* FIXME: Apparently a button press/release event might be dropped
    2.10 -               if made before before a different button is released.  Does
    2.11 -               B_MOUSE_MOVED have the data needed to check if a mouse button
    2.12 -               state has changed? */
    2.13 +        case B_MOUSE_DOWN:
    2.14              if (msg->FindInt32("buttons", &buttons) == B_OK) {
    2.15 -                _MouseButtonEvent(buttons);
    2.16 +                _MouseButtonEvent(buttons, SDL_PRESSED);
    2.17              }
    2.18              break;
    2.19  
    2.20 -        case B_MOUSE_DOWN:
    2.21          case B_MOUSE_UP:
    2.22 -            /* _MouseButtonEvent() detects any and all buttons that may have
    2.23 -               changed state, as well as that button's new state */
    2.24              if (msg->FindInt32("buttons", &buttons) == B_OK) {
    2.25 -                _MouseButtonEvent(buttons);
    2.26 +                _MouseButtonEvent(buttons, SDL_RELEASED);
    2.27              }
    2.28              break;
    2.29  
    2.30 @@ -497,26 +492,17 @@
    2.31   if true:  SDL_SetCursor(NULL); */
    2.32      }
    2.33  
    2.34 -    void _MouseButtonEvent(int32 buttons) {
    2.35 +    void _MouseButtonEvent(int32 buttons, Uint8 state) {
    2.36          int32 buttonStateChange = buttons ^ _last_buttons;
    2.37  
    2.38 -        /* Make sure at least one button has changed state */
    2.39 -        if( !(buttonStateChange) ) {
    2.40 -            return;
    2.41 -        }
    2.42 -
    2.43 -        /* Add any mouse button events */
    2.44          if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
    2.45 -            _SendMouseButton(SDL_BUTTON_LEFT, buttons &
    2.46 -                B_PRIMARY_MOUSE_BUTTON);
    2.47 +            _SendMouseButton(SDL_BUTTON_LEFT, state);
    2.48          }
    2.49          if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
    2.50 -            _SendMouseButton(SDL_BUTTON_RIGHT, buttons &
    2.51 -                B_PRIMARY_MOUSE_BUTTON);
    2.52 +            _SendMouseButton(SDL_BUTTON_RIGHT, state);
    2.53          }
    2.54          if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
    2.55 -            _SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
    2.56 -                B_PRIMARY_MOUSE_BUTTON);
    2.57 +            _SendMouseButton(SDL_BUTTON_MIDDLE, state);
    2.58          }
    2.59  
    2.60          _last_buttons = buttons;