2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "AndroidMouse.h"
11 #include "ServiceBroker.h"
13 #include "application/AppInboundProtocol.h"
14 #include "input/mouse/MouseStat.h"
15 #include "windowing/android/WinSystemAndroid.h"
17 //#define DEBUG_VERBOSE
19 bool CAndroidMouse::onMouseEvent(AInputEvent
* event
)
24 int32_t eventAction
= AMotionEvent_getAction(event
);
25 int8_t mouseAction
= eventAction
& AMOTION_EVENT_ACTION_MASK
;
26 size_t mousePointerIdx
= eventAction
>> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT
;
29 int32_t mousePointerId
= AMotionEvent_getPointerId(event
, mousePointerIdx
);
30 CXBMCApp::android_printf("%s idx:%i, id:%i", __PRETTY_FUNCTION__
, mousePointerIdx
, mousePointerId
);
32 float x
= AMotionEvent_getX(event
, mousePointerIdx
);
33 float y
= AMotionEvent_getY(event
, mousePointerIdx
);
37 case AMOTION_EVENT_ACTION_UP
:
38 case AMOTION_EVENT_ACTION_DOWN
:
39 MouseButton(x
,y
,mouseAction
,AMotionEvent_getButtonState(event
));
41 case AMOTION_EVENT_ACTION_SCROLL
:
42 MouseWheel(x
, y
, AMotionEvent_getAxisValue(event
, AMOTION_EVENT_AXIS_VSCROLL
, mousePointerIdx
));
51 void CAndroidMouse::MouseMove(float x
, float y
)
54 CXBMCApp::android_printf("%s: x:%f, y:%f", __PRETTY_FUNCTION__
, x
, y
);
56 XBMC_Event newEvent
= {};
58 newEvent
.type
= XBMC_MOUSEMOTION
;
59 newEvent
.motion
.x
= x
;
60 newEvent
.motion
.y
= y
;
61 std::shared_ptr
<CAppInboundProtocol
> appPort
= CServiceBroker::GetAppPort();
63 appPort
->OnEvent(newEvent
);
66 void CAndroidMouse::MouseButton(float x
, float y
, int32_t action
, int32_t buttons
)
69 CXBMCApp::android_printf("%s: x:%f, y:%f, action:%i, buttons:%i", __PRETTY_FUNCTION__
, x
, y
, action
, buttons
);
71 XBMC_Event newEvent
= {};
73 int32_t checkButtons
= buttons
;
74 if (action
== AMOTION_EVENT_ACTION_UP
)
75 checkButtons
= m_lastButtonState
;
77 newEvent
.type
= (action
== AMOTION_EVENT_ACTION_DOWN
) ? XBMC_MOUSEBUTTONDOWN
: XBMC_MOUSEBUTTONUP
;
78 newEvent
.button
.x
= x
;
79 newEvent
.button
.y
= y
;
80 if (checkButtons
& AMOTION_EVENT_BUTTON_PRIMARY
)
81 newEvent
.button
.button
= XBMC_BUTTON_LEFT
;
82 else if (checkButtons
& AMOTION_EVENT_BUTTON_SECONDARY
)
83 newEvent
.button
.button
= XBMC_BUTTON_RIGHT
;
84 else if (checkButtons
& AMOTION_EVENT_BUTTON_TERTIARY
)
85 newEvent
.button
.button
= XBMC_BUTTON_MIDDLE
;
87 std::shared_ptr
<CAppInboundProtocol
> appPort
= CServiceBroker::GetAppPort();
89 appPort
->OnEvent(newEvent
);
91 m_lastButtonState
= buttons
;
94 void CAndroidMouse::MouseWheel(float x
, float y
, float value
)
97 CXBMCApp::android_printf("%s: val:%f", __PRETTY_FUNCTION__
, value
);
99 XBMC_Event newEvent
= {};
103 newEvent
.type
= XBMC_MOUSEBUTTONDOWN
;
104 newEvent
.button
.button
= XBMC_BUTTON_WHEELUP
;
106 else if (value
< 0.0f
)
108 newEvent
.type
= XBMC_MOUSEBUTTONDOWN
;
109 newEvent
.button
.button
= XBMC_BUTTON_WHEELDOWN
;
114 newEvent
.button
.x
= x
;
115 newEvent
.button
.y
= y
;
117 std::shared_ptr
<CAppInboundProtocol
> appPort
= CServiceBroker::GetAppPort();
119 appPort
->OnEvent(newEvent
);
121 newEvent
.type
= XBMC_MOUSEBUTTONUP
;
123 dynamic_cast<CWinSystemAndroid
*>(CServiceBroker::GetWinSystem())->MessagePush(&newEvent
);