diff options
-rw-r--r-- | xbmc/android/activity/AndroidExtra.h | 11 | ||||
-rw-r--r-- | xbmc/android/activity/AndroidMouse.cpp | 31 | ||||
-rw-r--r-- | xbmc/android/activity/AndroidMouse.h | 5 | ||||
-rw-r--r-- | xbmc/android/activity/EventLoop.cpp | 5 |
4 files changed, 41 insertions, 11 deletions
diff --git a/xbmc/android/activity/AndroidExtra.h b/xbmc/android/activity/AndroidExtra.h index ea1b1f0522..7b1c9ffa72 100644 --- a/xbmc/android/activity/AndroidExtra.h +++ b/xbmc/android/activity/AndroidExtra.h @@ -26,6 +26,11 @@ extern float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t extern typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue; #define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue) +// missing in NDK +extern int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event); +extern typeof(AMotionEvent_getButtonState) *p_AMotionEvent_getButtonState; +#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState) + //Additional defines from android.view.KeyEvent (http://developer.android.com/reference/android/view/KeyEvent.html) #define AKEYCODE_ESCAPE 111 #define AKEYCODE_FORWARD_DEL 112 @@ -41,6 +46,12 @@ extern typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue; //Additional defines from android.view.MotionEvent (http://developer.android.com/reference/android/view/MotionEvent.html) #define AMOTION_EVENT_ACTION_SCROLL 0x08 +#define AMOTION_EVENT_BUTTON_PRIMARY 0x00000001 +#define AMOTION_EVENT_BUTTON_SECONDARY 0x00000002 +#define AMOTION_EVENT_BUTTON_TERTIARY 0x00000004 +#define AMOTION_EVENT_BUTTON_BACK 0x00000008 +#define AMOTION_EVENT_BUTTON_FORWARD 0x00000010 + #define AINPUT_SOURCE_CLASS_JOYSTICK 0x00000010 #define AINPUT_SOURCE_GAMEPAD (0x00000400 | AINPUT_SOURCE_CLASS_BUTTON) diff --git a/xbmc/android/activity/AndroidMouse.cpp b/xbmc/android/activity/AndroidMouse.cpp index a25c255948..0665bbb05a 100644 --- a/xbmc/android/activity/AndroidMouse.cpp +++ b/xbmc/android/activity/AndroidMouse.cpp @@ -29,6 +29,7 @@ //#define DEBUG_VERBOSE CAndroidMouse::CAndroidMouse() + : m_lastButtonState(0) { } @@ -43,22 +44,23 @@ bool CAndroidMouse::onMouseEvent(AInputEvent* event) int32_t eventAction = AMotionEvent_getAction(event); int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK; - size_t mousePointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + size_t mousePointerIdx = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + int32_t mousePointerId = AMotionEvent_getPointerId(event, mousePointerIdx); #ifdef DEBUG_VERBOSE - CXBMCApp::android_printf("%s pointer:%i", __PRETTY_FUNCTION__, mousePointer); + CXBMCApp::android_printf("%s idx:%i, id:%i", __PRETTY_FUNCTION__, mousePointerIdx, mousePointerId); #endif - float x = AMotionEvent_getX(event, mousePointer); - float y = AMotionEvent_getY(event, mousePointer); + float x = AMotionEvent_getX(event, mousePointerIdx); + float y = AMotionEvent_getY(event, mousePointerIdx); switch (mouseAction) { case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_DOWN: - MouseButton(x,y,mouseAction); + MouseButton(x,y,mouseAction,AMotionEvent_getButtonState(event)); return true; case AMOTION_EVENT_ACTION_SCROLL: - MouseWheel(x, y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointer)); + MouseWheel(x, y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointerIdx)); return true; default: MouseMove(x,y); @@ -87,22 +89,33 @@ void CAndroidMouse::MouseMove(float x, float y) CWinEvents::MessagePush(&newEvent); } -void CAndroidMouse::MouseButton(float x, float y, int32_t action) +void CAndroidMouse::MouseButton(float x, float y, int32_t action, int32_t buttons) { #ifdef DEBUG_VERBOSE - CXBMCApp::android_printf("%s: x:%f, y:%f, action:%i", __PRETTY_FUNCTION__, x, y, action); + CXBMCApp::android_printf("%s: x:%f, y:%f, action:%i, buttons:%i", __PRETTY_FUNCTION__, x, y, action, buttons); #endif XBMC_Event newEvent; memset(&newEvent, 0, sizeof(newEvent)); + int32_t checkButtons = buttons; + if (action == AMOTION_EVENT_ACTION_UP) + checkButtons = m_lastButtonState; + newEvent.type = (action == AMOTION_EVENT_ACTION_DOWN) ? XBMC_MOUSEBUTTONDOWN : XBMC_MOUSEBUTTONUP; newEvent.button.state = (action == AMOTION_EVENT_ACTION_DOWN) ? XBMC_PRESSED : XBMC_RELEASED; newEvent.button.type = newEvent.type; newEvent.button.x = x; newEvent.button.y = y; - newEvent.button.button = XBMC_BUTTON_LEFT; + if (checkButtons & AMOTION_EVENT_BUTTON_PRIMARY) + newEvent.button.button = XBMC_BUTTON_LEFT; + else if (checkButtons & AMOTION_EVENT_BUTTON_SECONDARY) + newEvent.button.button = XBMC_BUTTON_RIGHT; + else if (checkButtons & AMOTION_EVENT_BUTTON_TERTIARY) + newEvent.button.button = XBMC_BUTTON_MIDDLE; CWinEvents::MessagePush(&newEvent); + + m_lastButtonState = buttons; } void CAndroidMouse::MouseWheel(float x, float y, float value) diff --git a/xbmc/android/activity/AndroidMouse.h b/xbmc/android/activity/AndroidMouse.h index f1746a6d80..10199a25f4 100644 --- a/xbmc/android/activity/AndroidMouse.h +++ b/xbmc/android/activity/AndroidMouse.h @@ -33,6 +33,9 @@ protected: private: void MouseMove(float x, float y); - void MouseButton(float x, float y, int32_t type); + void MouseButton(float x, float y, int32_t type, int32_t buttons); void MouseWheel(float x, float y, float value); + +private: + int32_t m_lastButtonState; }; diff --git a/xbmc/android/activity/EventLoop.cpp b/xbmc/android/activity/EventLoop.cpp index 851ff5173c..fdf3358415 100644 --- a/xbmc/android/activity/EventLoop.cpp +++ b/xbmc/android/activity/EventLoop.cpp @@ -25,6 +25,7 @@ #include <dlfcn.h> typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue; +typeof(AMotionEvent_getButtonState) *p_AMotionEvent_getButtonState; CEventLoop::CEventLoop(android_app* application) : m_enabled(false), @@ -50,7 +51,9 @@ void CEventLoop::run(IActivityHandler &activityHandler, IInputHandler &inputHand // missing in early NDKs, is present in r9b+ p_AMotionEvent_getAxisValue = (typeof(AMotionEvent_getAxisValue)*) dlsym(RTLD_DEFAULT, "AMotionEvent_getAxisValue"); - CXBMCApp::android_printf("CEventLoop: AMotionEvent_getAxisValue: %p", p_AMotionEvent_getAxisValue); + // missing in NDK + p_AMotionEvent_getButtonState = (typeof(AMotionEvent_getButtonState)*) dlsym(RTLD_DEFAULT, "AMotionEvent_getButtonState"); + CXBMCApp::android_printf("CEventLoop: AMotionEvent_getAxisValue: %p, AMotionEvent_getButtonState: %p", p_AMotionEvent_getAxisValue, p_AMotionEvent_getButtonState); CXBMCApp::android_printf("CEventLoop: starting event loop"); while (1) |