Added a test for MUIA_Listview_SelectChange.
[AROS.git] / arch / all-android / hidd / androidgfx / akbd.c
blob722719b895ba87272c274e31419e0237ae428f32
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Android keyboard hidd class.
6 Lang: English.
7 */
9 #include <aros/debug.h>
10 #include <devices/inputevent.h>
11 #include <devices/rawkeycodes.h>
12 #include <hidd/keyboard.h>
13 #include <oop/oop.h>
15 #include <proto/utility.h>
16 #include <proto/oop.h>
18 #include <android/keycodes.h>
20 #include "agfx.h"
21 #include "agfx_keyboard.h"
22 #include "server.h"
24 /****************************************************************************************/
26 OOP_Object *AKbd__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
28 EnterFunc(bug("AKbd::New()\n"));
30 if (XSD(cl)->kbdhidd)
31 return NULL;
33 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
34 if (o)
36 struct kbd_data *data = OOP_INST_DATA(cl, o);
37 struct TagItem *tag, *tstate = msg->attrList;
39 while ((tag = NextTagItem(&tstate)))
41 ULONG idx;
43 if (IS_HIDDKBD_ATTR(tag->ti_Tag, idx))
45 switch (idx)
47 case aoHidd_Kbd_IrqHandler:
48 data->callback = (APTR)tag->ti_Data;
49 D(bug("Got callback %p\n", tag->ti_Data));
50 break;
52 case aoHidd_Kbd_IrqHandlerData:
53 data->callbackdata = (APTR)tag->ti_Data;
54 D(bug("Got data %p\n", tag->ti_Data));
55 break;
59 XSD(cl)->kbdhidd = data;
62 ReturnPtr("AKbd::New", OOP_Object *, o);
65 /****************************************************************************************/
67 VOID AKbd__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
69 EnterFunc(bug("[AKbd] Dispose()\n"));
71 XSD(cl)->kbdhidd = NULL;
72 OOP_DoSuperMethod(cl, o, msg);
75 /****************************************************************************************/
78 * Raw key codes conversion table (Android->AROS). Currently tested only with
79 * Sony Ericsson XPeria (running Android 2.1).
80 * Please feel free to modify and improve.
82 * Note 1: Sony Ericsson XPeria have only Alt and Sym keys on their keyboard.
83 * Sym is used by Android to pop up extra virtual keyboard. However, under AROS it
84 * does not produce any input events, but serves instead as additional modifier.
85 * Currently i don't know how to make it generating events. Wound be nice to use it
86 * as RAmiga to make hotkeys working.
87 * Note 2: Alt (Blue square) key on XPeria keyboard is meant to produce additional characters,
88 * which are marked in blue. An appropriate keymap on AROS side is needed for this. The
89 * key itself doesn't produce an input event, instead it triggers a mode when keys generate
90 * a sequence of two codes: ALT then key itself.
91 * Note 3: XPeria keyboard doesn't handle autorepeats. Every physical keypress generates two codes:
92 * press then release.
94 static const UWORD KeyTable[] =
96 -1, /* AKEYCODE_UNKNOWN */
97 RAWKEY_LEFT, /* AKEYCODE_SOFT_LEFT */
98 RAWKEY_RIGHT, /* AKEYCODE_SOFT_RIGHT */
99 RAWKEY_HOME, /* AKEYCODE_HOME */
100 -1, /* AKEYCODE_BACK - Emulates LAmiga+M */
101 -1, /* AKEYCODE_CALL - Green button (Ok on a requester? Shift+Enter? What?) */
102 RAWKEY_ESCAPE, /* AKEYCODE_ENDCALL - Red button */
103 RAWKEY_0, /* AKEYCODE_0 */
104 RAWKEY_1, /* AKEYCODE_1 */
105 RAWKEY_2, /* AKEYCODE_2 */
106 RAWKEY_3, /* AKEYCODE_3 */
107 RAWKEY_4, /* AKEYCODE_4 */
108 RAWKEY_5, /* AKEYCODE_5 */
109 RAWKEY_6, /* AKEYCODE_6 */
110 RAWKEY_7, /* AKEYCODE_7 */
111 RAWKEY_8, /* AKEYCODE_8 */
112 RAWKEY_9, /* AKEYCODE_9 */
113 RAWKEY_KP_MULTIPLY, /* AKEYCODE_STAR */
114 RAWKEY_KP_DIVIDE, /* AKEYCODE_POUND - perhaps not good */
115 RAWKEY_UP, /* AKEYCODE_DPAD_UP */
116 RAWKEY_DOWN, /* AKEYCODE_DPAD_DOWN */
117 RAWKEY_LEFT, /* AKEYCODE_DPAD_LEFT */
118 RAWKEY_RIGHT, /* AKEYCODE_DPAD_RIGHT */
119 RAWKEY_KP_ENTER, /* AKEYCODE_DPAD_CENTER */
120 -1, /* AKEYCODE_VOLUME_UP - There is no adequate Amiga equivalent */
121 -1, /* AKEYCODE_VOLUME_DOWN */
122 -1, /* AKEYCODE_POWER */
123 -1, /* AKEYCODE_CAMERA */
124 RAWKEY_DELETE, /* AKEYCODE_CLEAR */
125 RAWKEY_A, /* AKEYCODE_A */
126 RAWKEY_B, /* AKEYCODE_B */
127 RAWKEY_C, /* AKEYCODE_C */
128 RAWKEY_D, /* AKEYCODE_D */
129 RAWKEY_E, /* AKEYCODE_E */
130 RAWKEY_F, /* AKEYCODE_F */
131 RAWKEY_G, /* AKEYCODE_G */
132 RAWKEY_H, /* AKEYCODE_H */
133 RAWKEY_I, /* AKEYCODE_I */
134 RAWKEY_J, /* AKEYCODE_J */
135 RAWKEY_K, /* AKEYCODE_K */
136 RAWKEY_L, /* AKEYCODE_L */
137 RAWKEY_M, /* AKEYCODE_M */
138 RAWKEY_N, /* AKEYCODE_N */
139 RAWKEY_O, /* AKEYCODE_O */
140 RAWKEY_P, /* AKEYCODE_P */
141 RAWKEY_Q, /* AKEYCODE_Q */
142 RAWKEY_R, /* AKEYCODE_R */
143 RAWKEY_S, /* AKEYCODE_S */
144 RAWKEY_T, /* AKEYCODE_T */
145 RAWKEY_U, /* AKEYCODE_U */
146 RAWKEY_V, /* AKEYCODE_V */
147 RAWKEY_W, /* AKEYCODE_W */
148 RAWKEY_X, /* AKEYCODE_X */
149 RAWKEY_Y, /* AKEYCODE_Y */
150 RAWKEY_Z, /* AKEYCODE_Z */
151 RAWKEY_COMMA, /* AKEYCODE_COMMA */
152 RAWKEY_PERIOD, /* AKEYCODE_PERIOD */
153 RAWKEY_LALT, /* AKEYCODE_ALT_LEFT */
154 RAWKEY_RALT, /* AKEYCODE_ALT_RIGHT */
155 RAWKEY_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
156 RAWKEY_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
157 RAWKEY_TAB, /* AKEYCODE_TAB */
158 RAWKEY_SPACE, /* AKEYCODE_SPACE */
159 RAWKEY_RAMIGA, /* AKEYCODE_SYM - See note 1 */
160 -1, /* AKEYCODE_EXPLORER - There's neither adequate Amiga equivalent, */
161 -1, /* AKEYCODE_ENVELOPE nor adequate reason for these keys to exist :) */
162 RAWKEY_RETURN, /* AKEYCODE_ENTER */
163 RAWKEY_BACKSPACE, /* AKEYCODE_DEL - This key is actually marked as Backspace key */
164 RAWKEY_TILDE, /* AKEYCODE_GRAVE */
165 RAWKEY_MINUS, /* AKEYCODE_MINUS */
166 RAWKEY_EQUAL, /* AKEYCODE_EQUALS */
167 RAWKEY_LBRACKET, /* AKEYCODE_LEFT_BRACKET */
168 RAWKEY_RBRACKET, /* AKEYCODE_RIGHT_BRACKET */
169 RAWKEY_BACKSLASH, /* AKEYCODE_BACKSLASH */
170 RAWKEY_SEMICOLON, /* AKEYCODE_SEMICOLON */
171 RAWKEY_QUOTE, /* AKEYCODE_APOSTROPHE */
172 RAWKEY_SLASH, /* AKEYCODE_SLASH */
173 -1, /* AKEYCODE_AT */
174 RAWKEY_NUMLOCK, /* AKEYCODE_NUM */
175 -1, /* AKEYCODE_HEADSETHOOK */
176 -1, /* AKEYCODE_FOCUS */
177 -1, /* AKEYCODE_PLUS - Should be Shift + '=', however keymap-dependent. Not good... */
178 -1, /* AKEYCODE_MENU - Used for RMB emulation */
179 -1, /* AKEYCODE_NOTIFICATION */
180 RAWKEY_HELP, /* AKEYCODE_SEARCH */
181 RAWKEY_MEDIA2, /* AKEYCODE_MEDIA_PLAY_PAUSE */
182 RAWKEY_MEDIA1, /* AKEYCODE_MEDIA_STOP */
183 RAWKEY_MEDIA4, /* AKEYCODE_MEDIA_NEXT */
184 RAWKEY_MEDIA3, /* AKEYCODE_MEDIA_PREVIOUS */
185 RAWKEY_MEDIA5, /* AKEYCODE_MEDIA_REWIND */
186 RAWKEY_MEDIA4, /* AKEYCODE_MEDIA_FAST_FORWARD */
187 -1, /* AKEYCODE_MUTE */
188 RAWKEY_PAGEUP, /* AKEYCODE_PAGE_UP */
189 RAWKEY_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
190 -1, /* AKEYCODE_PICTSYMBOLS */
191 RAWKEY_CAPSLOCK, /* AKEYCODE_SWITCH_CHARSET */
192 RAWKEY_F1, /* AKEYCODE_BUTTON_A */
193 RAWKEY_F2, /* AKEYCODE_BUTTON_B */
194 RAWKEY_F3, /* AKEYCODE_BUTTON_C */
195 RAWKEY_F4, /* AKEYCODE_BUTTON_X */
196 RAWKEY_F5, /* AKEYCODE_BUTTON_Y */
197 RAWKEY_F6, /* AKEYCODE_BUTTON_Z */
198 RAWKEY_LAMIGA, /* AKEYCODE_BUTTON_L1 - These four perhaps not good. Need a device with keyboard. */
199 RAWKEY_RAMIGA, /* AKEYCODE_BUTTON_R1 */
200 RAWKEY_CONTROL, /* AKEYCODE_BUTTON_L2 */
201 RAWKEY_CONTROL, /* AKEYCODE_BUTTON_R2 */
202 -1, /* AKEYCODE_BUTTON_THUMBL - simply don't know. May be F7-F11? */
203 -1, /* AKEYCODE_BUTTON_THUMBR */
204 -1, /* AKEYCODE_BUTTON_START */
205 -1, /* AKEYCODE_BUTTON_SELECT */
206 -1 /* AKEYCODE_BUTTON_MODE */
209 static inline void PostRawKey(struct kbd_data *data, UWORD code)
211 data->callback(data->callbackdata, code);
214 void AKbd_ReportKey(struct kbd_data *data, struct KeyEvent *e)
216 UWORD code;
218 /* Skip unknown codes */
219 if (e->code > AKEYCODE_BUTTON_MODE)
220 return;
222 switch (e->code)
224 case AKEYCODE_BACK:
225 /* LAmiga + M (cycle screens) emulation */
226 if (e->flags & IECODE_UP_PREFIX)
228 /* Release in reverse order */
229 PostRawKey(data, RAWKEY_M | IECODE_UP_PREFIX);
230 PostRawKey(data, RAWKEY_LAMIGA | IECODE_UP_PREFIX);
232 else
234 PostRawKey(data, RAWKEY_LAMIGA);
235 PostRawKey(data, RAWKEY_M);
237 break;
239 default:
240 /* 1:1 mapping to Amiga raw key */
241 code = KeyTable[e->code];
243 /* Ignore the key if there's no assignment */
244 if (code != -1)
245 PostRawKey(data, code | e->flags);