[clutter/android-enter-leave: 8/29] android: add initial support for keycode translation
- From: Lionel Landwerlin <llandwerlin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/android-enter-leave: 8/29] android: add initial support for keycode translation
- Date: Wed, 11 Jul 2012 17:07:44 +0000 (UTC)
commit e967a548ca1dd37dc072850bcd1b2deb2ae74597
Author: Lionel Landwerlin <llandwerlin gmail com>
Date: Sun May 27 14:39:40 2012 +0100
android: add initial support for keycode translation
clutter/Makefile.am | 6 +-
.../android/clutter-android-application-private.h | 2 +
clutter/android/clutter-android-application.c | 43 +++--
clutter/android/clutter-android-keycodes.c | 184 ++++++++++++++++++++
clutter/android/clutter-android-keycodes.h | 34 ++++
5 files changed, 251 insertions(+), 18 deletions(-)
---
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index e9ae411..60b5545 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -512,8 +512,9 @@ android_source_c = \
android_source_c_priv = \
$(srcdir)/android/android_jni_utils.cpp \
$(srcdir)/android/android_native_app_glue.c \
- $(srcdir)/android/clutter-device-manager-android.c \
+ $(srcdir)/android/clutter-android-keycodes.c \
$(srcdir)/android/clutter-backend-android.c \
+ $(srcdir)/android/clutter-device-manager-android.c \
$(srcdir)/android/clutter-event-android.c \
$(srcdir)/android/clutter-stage-android.c \
$(NULL)
@@ -526,8 +527,9 @@ android_source_h = \
android_source_h_priv = \
$(srcdir)/android/android_jni_utils.h \
$(srcdir)/android/android_native_app_glue.h \
- $(srcdir)/android/clutter-device-manager-android.h \
+ $(srcdir)/android/clutter-android-keycodes.h \
$(srcdir)/android/clutter-backend-android.h \
+ $(srcdir)/android/clutter-device-manager-android.h \
$(srcdir)/android/clutter-event-android.h \
$(srcdir)/android/clutter-stage-android.h \
$(NULL)
diff --git a/clutter/android/clutter-android-application-private.h b/clutter/android/clutter-android-application-private.h
index a31e36e..9f8340f 100644
--- a/clutter/android/clutter-android-application-private.h
+++ b/clutter/android/clutter-android-application-private.h
@@ -35,6 +35,8 @@ struct _ClutterAndroidApplication
struct android_app* android_application;
+ int32_t modifier_state;
+
gint have_window : 1;
GMainLoop *wait_for_window;
};
diff --git a/clutter/android/clutter-android-application.c b/clutter/android/clutter-android-application.c
index 8a8ab53..11dbcad 100644
--- a/clutter/android/clutter-android-application.c
+++ b/clutter/android/clutter-android-application.c
@@ -290,52 +290,63 @@ translate_motion_event (AInputEvent *a_event)
static gboolean
translate_key_event (AInputEvent *a_event)
{
- int32_t state;
+ int32_t action;
ClutterEvent *event;
ClutterDeviceManager *manager;
ClutterInputDevice *keyboard_device;
+ ClutterAndroidApplication *application =
+ _clutter_android_application_get_default ();
+ int32_t new_modifier_state = application->modifier_state;
- g_message ("key event");
-
- state = AMotionEvent_getMetaState (a_event);
+ action = AKeyEvent_getAction (a_event);
manager = clutter_device_manager_get_default ();
keyboard_device =
clutter_device_manager_get_core_device (manager,
CLUTTER_KEYBOARD_DEVICE);
- g_message ("\tflags = %x keycode = %i",
+ g_message ("\taction = %i flags = %x meta = %x keycode = %i",
+ AKeyEvent_getAction (a_event),
AKeyEvent_getFlags (a_event),
+ AKeyEvent_getMetaState (a_event),
AKeyEvent_getKeyCode (a_event));
- switch (state)
+ switch (action)
{
- case AKEY_STATE_UP:
+ case AKEY_EVENT_ACTION_DOWN:
+ g_message ("\tkey press");
+ event = clutter_event_new (CLUTTER_KEY_PRESS);
+ new_modifier_state |= AKeyEvent_getMetaState (a_event);
+ break;
+
+ case AKEY_EVENT_ACTION_UP:
g_message ("\tkey release");
event = clutter_event_new (CLUTTER_KEY_RELEASE);
+ new_modifier_state &= ~AKeyEvent_getMetaState (a_event);
break;
- case AKEY_STATE_DOWN:
- case AKEY_STATE_VIRTUAL: /* TODO: Should we synthetize release? */
- g_message ("\tkey press");
- event = clutter_event_new (CLUTTER_KEY_PRESS);
- break;
+ case AKEY_EVENT_ACTION_MULTIPLE:
+ g_message ("\tcomplex string");
+ return FALSE;
default:
- g_message ("\tmeh? %i", state);
+ g_message ("\tmeh? %i", action);
return FALSE;
}
- event->key.unicode_value = AKeyEvent_getKeyCode (a_event);
- g_message ("\tunicode value = %i", AKeyEvent_getKeyCode (a_event));
- event->key.device = keyboard_device;
+ _clutter_android_translate_key_event (event,
+ application->modifier_state,
+ a_event);
+ event->key.device = keyboard_device;
event->any.stage =
clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
_clutter_input_device_set_stage (keyboard_device, event->any.stage);
_clutter_event_push (event, FALSE);
+ application->modifier_state = new_modifier_state;
+
return TRUE;
}
diff --git a/clutter/android/clutter-android-keycodes.c b/clutter/android/clutter-android-keycodes.c
new file mode 100644
index 0000000..86d1b65
--- /dev/null
+++ b/clutter/android/clutter-android-keycodes.c
@@ -0,0 +1,184 @@
+/* Clutter - An OpenGL based 'interactive canvas' library.
+ * Android backend - initial entry point
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lionel Landwerlin <lionel g landwerlin linux intel com>
+ */
+
+#include "clutter-android-keycodes.h"
+
+#include "clutter-keysyms.h"
+
+#include <android/keycodes.h>
+
+static guint keycodes[AKEYCODE_BUTTON_MODE + 1] = {
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_UNKNOWN = 0, */
+ CLUTTER_KEY_Left, /* AKEYCODE_SOFT_LEFT = 1, */
+ CLUTTER_KEY_Right, /* AKEYCODE_SOFT_RIGHT = 2, */
+ CLUTTER_KEY_Home, /* AKEYCODE_HOME = 3, */
+ CLUTTER_KEY_Back, /* AKEYCODE_BACK = 4, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_CALL = 5, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_ENDCALL = 6, */
+ CLUTTER_KEY_0, /* AKEYCODE_0 = 7, */
+ CLUTTER_KEY_1, /* AKEYCODE_1 = 8, */
+ CLUTTER_KEY_2, /* AKEYCODE_2 = 9, */
+ CLUTTER_KEY_3, /* AKEYCODE_3 = 10, */
+ CLUTTER_KEY_4, /* AKEYCODE_4 = 11, */
+ CLUTTER_KEY_5, /* AKEYCODE_5 = 12, */
+ CLUTTER_KEY_6, /* AKEYCODE_6 = 13, */
+ CLUTTER_KEY_7, /* AKEYCODE_7 = 14, */
+ CLUTTER_KEY_8, /* AKEYCODE_8 = 15, */
+ CLUTTER_KEY_9, /* AKEYCODE_9 = 16, */
+ CLUTTER_KEY_asterisk, /* AKEYCODE_STAR = 17, */
+ CLUTTER_KEY_ssharp, /* AKEYCODE_POUND = 18, */
+ CLUTTER_KEY_KP_Up, /* AKEYCODE_DPAD_UP = 19, */
+ CLUTTER_KEY_KP_Down, /* AKEYCODE_DPAD_DOWN = 20, */
+ CLUTTER_KEY_KP_Left, /* AKEYCODE_DPAD_LEFT = 21, */
+ CLUTTER_KEY_KP_Right, /* AKEYCODE_DPAD_RIGHT = 22, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_DPAD_CENTER = 23, */
+ CLUTTER_KEY_AudioRaiseVolume, /* AKEYCODE_VOLUME_UP = 24, */
+ CLUTTER_KEY_AudioLowerVolume, /* AKEYCODE_VOLUME_DOWN = 25, */
+ CLUTTER_KEY_PowerOff, /* AKEYCODE_POWER = 26, */
+ CLUTTER_KEY_WebCam, /* AKEYCODE_CAMERA = 27, */
+ CLUTTER_KEY_Clear, /* AKEYCODE_CLEAR = 28, */
+ CLUTTER_KEY_A, /* AKEYCODE_A = 29, */
+ CLUTTER_KEY_B, /* AKEYCODE_B = 30, */
+ CLUTTER_KEY_C, /* AKEYCODE_C = 31, */
+ CLUTTER_KEY_D, /* AKEYCODE_D = 32, */
+ CLUTTER_KEY_E, /* AKEYCODE_E = 33, */
+ CLUTTER_KEY_F, /* AKEYCODE_F = 34, */
+ CLUTTER_KEY_G, /* AKEYCODE_G = 35, */
+ CLUTTER_KEY_H, /* AKEYCODE_H = 36, */
+ CLUTTER_KEY_I, /* AKEYCODE_I = 37, */
+ CLUTTER_KEY_J, /* AKEYCODE_J = 38, */
+ CLUTTER_KEY_K, /* AKEYCODE_K = 39, */
+ CLUTTER_KEY_L, /* AKEYCODE_L = 40, */
+ CLUTTER_KEY_M, /* AKEYCODE_M = 41, */
+ CLUTTER_KEY_N, /* AKEYCODE_N = 42, */
+ CLUTTER_KEY_O, /* AKEYCODE_O = 43, */
+ CLUTTER_KEY_P, /* AKEYCODE_P = 44, */
+ CLUTTER_KEY_Q, /* AKEYCODE_Q = 45, */
+ CLUTTER_KEY_R, /* AKEYCODE_R = 46, */
+ CLUTTER_KEY_S, /* AKEYCODE_S = 47, */
+ CLUTTER_KEY_T, /* AKEYCODE_T = 48, */
+ CLUTTER_KEY_U, /* AKEYCODE_U = 49, */
+ CLUTTER_KEY_V, /* AKEYCODE_V = 50, */
+ CLUTTER_KEY_W, /* AKEYCODE_W = 51, */
+ CLUTTER_KEY_X, /* AKEYCODE_X = 52, */
+ CLUTTER_KEY_Y, /* AKEYCODE_Y = 53, */
+ CLUTTER_KEY_Z, /* AKEYCODE_Z = 54, */
+ CLUTTER_KEY_comma, /* AKEYCODE_COMMA = 55, */
+ CLUTTER_KEY_period, /* AKEYCODE_PERIOD = 56, */
+ CLUTTER_KEY_Alt_L, /* AKEYCODE_ALT_LEFT = 57, */
+ CLUTTER_KEY_Alt_R, /* AKEYCODE_ALT_RIGHT = 58, */
+ CLUTTER_KEY_Shift_L, /* AKEYCODE_SHIFT_LEFT = 59, */
+ CLUTTER_KEY_Shift_R, /* AKEYCODE_SHIFT_RIGHT = 60, */
+ CLUTTER_KEY_Tab, /* AKEYCODE_TAB = 61, */
+ CLUTTER_KEY_space, /* AKEYCODE_SPACE = 62, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_SYM = 63, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_EXPLORER = 64, */
+ CLUTTER_KEY_Mail, /* AKEYCODE_ENVELOPE = 65, */
+ CLUTTER_KEY_Return, /* AKEYCODE_ENTER = 66, */
+ CLUTTER_KEY_BackSpace, /* AKEYCODE_DEL = 67, */
+ CLUTTER_KEY_grave, /* AKEYCODE_GRAVE = 68, */
+ CLUTTER_KEY_minus, /* AKEYCODE_MINUS = 69, */
+ CLUTTER_KEY_equal, /* AKEYCODE_EQUALS = 70, */
+ CLUTTER_KEY_bracketleft, /* AKEYCODE_LEFT_BRACKET = 71, */
+ CLUTTER_KEY_bracketright, /* AKEYCODE_RIGHT_BRACKET = 72, */
+ CLUTTER_KEY_backslash, /* AKEYCODE_BACKSLASH = 73, */
+ CLUTTER_KEY_semicolon, /* AKEYCODE_SEMICOLON = 74, */
+ CLUTTER_KEY_apostrophe, /* AKEYCODE_APOSTROPHE = 75, */
+ CLUTTER_KEY_slash, /* AKEYCODE_SLASH = 76, */
+ CLUTTER_KEY_at, /* AKEYCODE_AT = 77, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_NUM = 78, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_HEADSETHOOK = 79, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_FOCUS = 80, // *Camera* focus */
+ CLUTTER_KEY_plus, /* AKEYCODE_PLUS = 81, */
+ CLUTTER_KEY_Menu, /* AKEYCODE_MENU = 82, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_NOTIFICATION = 83, */
+ CLUTTER_KEY_Search, /* AKEYCODE_SEARCH = 84, */
+ CLUTTER_KEY_AudioPlay, /* AKEYCODE_MEDIA_PLAY_PAUSE= 85, */
+ CLUTTER_KEY_AudioStop, /* AKEYCODE_MEDIA_STOP = 86, */
+ CLUTTER_KEY_AudioNext, /* AKEYCODE_MEDIA_NEXT = 87, */
+ CLUTTER_KEY_AudioPrev, /* AKEYCODE_MEDIA_PREVIOUS = 88, */
+ CLUTTER_KEY_AudioRewind, /* AKEYCODE_MEDIA_REWIND = 89, */
+ CLUTTER_KEY_Forward, /* AKEYCODE_MEDIA_FAST_FORWARD = 90, */
+ CLUTTER_KEY_AudioMute, /* AKEYCODE_MUTE = 91, */
+ CLUTTER_KEY_Page_Up, /* AKEYCODE_PAGE_UP = 92, */
+ CLUTTER_KEY_Page_Down, /* AKEYCODE_PAGE_DOWN = 93, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_PICTSYMBOLS = 94, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_SWITCH_CHARSET = 95, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_A = 96, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_B = 97, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_C = 98, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_X = 99, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_Y = 100, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_Z = 101, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_L1 = 102, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_R1 = 103, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_L2 = 104, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_R2 = 105, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_THUMBL = 106, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_THUMBR = 107, */
+ CLUTTER_KEY_VoidSymbol, /* AKEYCODE_BUTTON_START = 108, */
+ CLUTTER_KEY_Select, /* AKEYCODE_BUTTON_SELECT = 109, */
+ CLUTTER_KEY_VoidSymbol /* AKEYCODE_BUTTON_MODE = 110, */
+};
+
+static ClutterModifierType
+_translate_modifier_state (int32_t modifier_state)
+{
+ ClutterModifierType clutter_modifier_state = 0;
+
+ if (modifier_state & AMETA_ALT_ON)
+ clutter_modifier_state = CLUTTER_MOD1_MASK;
+
+ if (modifier_state & AMETA_SHIFT_ON)
+ clutter_modifier_state |= CLUTTER_SHIFT_MASK;
+
+ return clutter_modifier_state;
+}
+
+void
+_clutter_android_translate_key_event (ClutterKeyEvent *event,
+ int32_t modifier_state,
+ AInputEvent *a_event)
+{
+ int32_t keycode = AKeyEvent_getKeyCode (a_event);
+
+ if (keycode < 0 || keycode > AKEYCODE_BUTTON_MODE)
+ {
+ g_message ("Invalid keycode : %i", keycode);
+ return;
+ }
+
+ if (keycode >= AKEYCODE_A && keycode < AKEYCODE_Z)
+ {
+ if (modifier_state & AMETA_SHIFT_ON)
+ event->unicode_value =
+ clutter_keysym_to_unicode (CLUTTER_KEY_A + (keycode - AKEYCODE_A));
+ else
+ event->unicode_value =
+ clutter_keysym_to_unicode (CLUTTER_KEY_a + (keycode - AKEYCODE_A));
+ }
+ else
+ event->unicode_value = clutter_keysym_to_unicode (keycodes[keycode]);
+
+ event->modifier_state = _translate_modifier_state (modifier_state);
+ event->keyval = keycode;
+}
diff --git a/clutter/android/clutter-android-keycodes.h b/clutter/android/clutter-android-keycodes.h
new file mode 100644
index 0000000..7f08359
--- /dev/null
+++ b/clutter/android/clutter-android-keycodes.h
@@ -0,0 +1,34 @@
+/* Clutter - An OpenGL based 'interactive canvas' library.
+ * Android backend - initial entry point
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lionel Landwerlin <lionel g landwerlin linux intel com>
+ */
+
+#ifndef __CLUTTER_ANDROID_KEYCODES_H__
+#define __CLUTTER_ANDROID_KEYCODES_H__
+
+#include <clutter/clutter-event.h>
+
+#include <android/input.h>
+
+void _clutter_android_translate_key_event (ClutterKeyEvent *event,
+ int32_t modifier_state,
+ AInputEvent *a_event);
+
+#endif /* __CLUTTER_ANDROID_KEYCODES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]