2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Android mouse input hidd class.
9 #include <aros/debug.h>
10 #include <proto/utility.h>
11 #include <proto/oop.h>
13 #include <hidd/mouse.h>
15 #include <android/input.h>
18 #include "agfx_mouse.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
)
33 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, &msg
->mID
);
34 D(bug("[AMouse] Object created by superclass: 0x%p\n", o
));
38 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
39 struct TagItem
*tstate
= msg
->attrList
;
42 while ((tag
= NextTagItem(&tstate
)))
46 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, 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
;
55 case aoHidd_Mouse_IrqHandlerData
:
56 D(bug("[AMouse] Callback data 0x%p\n", tag
->ti_Data
));
57 data
->callbackdata
= (APTR
)tag
->ti_Data
;
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
69 XSD(cl
)->mousehidd
= data
;
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
);
91 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
))
95 case aoHidd_Mouse_IrqHandler
:
96 *msg
->storage
= (IPTR
)data
->mouse_callback
;
99 case aoHidd_Mouse_IrqHandlerData
:
100 *msg
->storage
= (IPTR
)data
->callbackdata
;
103 /* case aoHidd_Mouse_State:
109 /* We can report both absolute and relative coordinates */
110 case aoHidd_Mouse_Extended
:
111 *msg
->storage
= TRUE
;
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
));
129 case AMOTION_EVENT_ACTION_DOWN
:
130 e
.button
= vHidd_Mouse_Button1
;
131 e
.type
= vHidd_Mouse_Press
;
134 case AMOTION_EVENT_ACTION_UP
:
135 e
.button
= vHidd_Mouse_Button1
;
136 e
.type
= vHidd_Mouse_Release
;
139 case AMOTION_EVENT_ACTION_MOVE
:
140 e
.button
= vHidd_Mouse_NoButton
;
141 e
.type
= vHidd_Mouse_Motion
;
145 /* Ignore something we don't know about */
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
;
182 data
->mouse_callback(data
->callbackdata
, &e
);
186 case AMOTION_EVENT_ACTION_DOWN
:
187 e
.button
= vHidd_Mouse_Button1
;
188 e
.type
= vHidd_Mouse_Press
;
191 case AMOTION_EVENT_ACTION_UP
:
192 e
.button
= vHidd_Mouse_Button1
;
193 e
.type
= vHidd_Mouse_Release
;
197 /* Ignore something we don't know about */
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
;
213 e
.x
= 0; /* Relative motion of (0, 0) = no motion */
215 e
.flags
= vHidd_Mouse_Relative
;
217 data
->mouse_callback(data
->callbackdata
, &e
);