revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-android / hidd / androidgfx / android_mouseclass.c
blob5031a9cb44eb96fab24cef9164b7e150ceabbc38
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Android mouse input hidd class.
6 Lang: English.
7 */
9 #include <aros/debug.h>
10 #include <proto/utility.h>
11 #include <proto/oop.h>
12 #include <oop/oop.h>
13 #include <hidd/mouse.h>
15 #include <android/input.h>
17 #include "androidgfx_hidd.h"
18 #include "android_mouse.h"
19 #include "android_server.h"
21 OOP_Object *AMouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
23 D(EnterFunc("[AMouse] hidd.mouse.gdi::New()\n"));
26 * We can't be instantiated twice. Just in case.
27 * We don't want to cope with semaphore protection here because actually nobody
28 * will try to instantiate us.
30 if (XSD(cl)->mousehidd)
31 return NULL;
33 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, &msg->mID);
34 D(bug("[AMouse] Object created by superclass: 0x%p\n", o));
36 if (o)
38 struct mouse_data *data = OOP_INST_DATA(cl, o);
39 struct TagItem *tstate = msg->attrList;
40 struct TagItem *tag;
42 while ((tag = NextTagItem(&tstate)))
44 ULONG idx;
46 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
48 switch (idx)
50 case aoHidd_Mouse_IrqHandler:
51 D(bug("[AMouse] Callback address 0x%p\n", tag->ti_Data));
52 data->mouse_callback = (VOID (*)())tag->ti_Data;
53 break;
55 case aoHidd_Mouse_IrqHandlerData:
56 D(bug("[AMouse] Callback data 0x%p\n", tag->ti_Data));
57 data->callbackdata = (APTR)tag->ti_Data;
58 break;
61 } /* while (tags to process) */
64 * Install the mouse hidd.
65 * Our class is final, it's not meant to be subclassed. Additionally, we
66 * report mouse events from within an interrupt, and omitting oop.library calls
67 * speeds things up.
69 XSD(cl)->mousehidd = data;
72 return o;
75 /****************************************************************************************/
77 VOID AMouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
79 XSD(cl)->mousehidd = NULL;
81 OOP_DoSuperMethod(cl, o, msg);
84 /****************************************************************************************/
86 VOID AMouse__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
88 struct mouse_data *data = OOP_INST_DATA(cl, o);
89 ULONG idx;
91 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx))
93 switch (idx)
95 case aoHidd_Mouse_IrqHandler:
96 *msg->storage = (IPTR)data->mouse_callback;
97 return;
99 case aoHidd_Mouse_IrqHandlerData:
100 *msg->storage = (IPTR)data->callbackdata;
101 return;
103 /* case aoHidd_Mouse_State:
105 TODO: Implement this
107 return;*/
109 /* We can report both absolute and relative coordinates */
110 case aoHidd_Mouse_Extended:
111 *msg->storage = TRUE;
112 return;
116 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
119 /****************************************************************************************/
121 void AMouse_ReportEvent(struct mouse_data *data, struct PointerEvent *pkt)
123 struct pHidd_Mouse_ExtEvent e;
125 DB2(bug("[AMouse] Mouse event 0x%08X at (%d, %d)\n", e.action, e.x, e.y));
127 switch (pkt->action)
129 case AMOTION_EVENT_ACTION_DOWN:
130 e.button = vHidd_Mouse_Button1;
131 e.type = vHidd_Mouse_Press;
132 break;
134 case AMOTION_EVENT_ACTION_UP:
135 e.button = vHidd_Mouse_Button1;
136 e.type = vHidd_Mouse_Release;
137 break;
139 case AMOTION_EVENT_ACTION_MOVE:
140 e.button = vHidd_Mouse_NoButton;
141 e.type = vHidd_Mouse_Motion;
142 break;
144 default:
145 /* Ignore something we don't know about */
146 return;
149 e.x = pkt->x;
150 e.y = pkt->y;
151 e.flags = vHidd_Mouse_Relative;
153 data->mouse_callback(data->callbackdata, &e);
156 /****************************************************************************************/
158 void AMouse_ReportTouch(struct mouse_data *data, struct PointerEvent *pkt)
160 struct pHidd_Mouse_ExtEvent e;
162 DB2(bug("[AMouse] Touch event 0x%08X at (%d, %d)\n", e.action, e.x, e.y));
165 * Intuition input handler doesn't recognize mouse button events
166 * together with movement. Instead it catches actions but misses
167 * the actual movement.
168 * In order to work around this, we send two actions instead of one.
169 * First we report movement to given coordinates, then action
170 * (if press or release happened).
172 * TODO: Perhaps we should feed touchscreen events to input.device instead.
173 * Well, this is very experimental anyway.
176 e.button = vHidd_Mouse_NoButton;
177 e.type = vHidd_Mouse_Motion;
178 e.x = pkt->x;
179 e.y = pkt->y;
180 e.flags = 0;
182 data->mouse_callback(data->callbackdata, &e);
184 switch (pkt->action)
186 case AMOTION_EVENT_ACTION_DOWN:
187 e.button = vHidd_Mouse_Button1;
188 e.type = vHidd_Mouse_Press;
189 break;
191 case AMOTION_EVENT_ACTION_UP:
192 e.button = vHidd_Mouse_Button1;
193 e.type = vHidd_Mouse_Release;
194 break;
196 default:
197 /* Ignore something we don't know about */
198 return;
201 /* Report the second action */
202 data->mouse_callback(data->callbackdata, &e);
205 /****************************************************************************************/
207 void AMouse_ReportButton(struct mouse_data *data, UWORD button, UWORD action)
209 struct pHidd_Mouse_ExtEvent e;
211 e.button = button;
212 e.type = action;
213 e.x = 0; /* Relative motion of (0, 0) = no motion */
214 e.y = 0;
215 e.flags = vHidd_Mouse_Relative;
217 data->mouse_callback(data->callbackdata, &e);