summaryrefslogtreecommitdiff
path: root/libs/ui/KeyCharacterMap.cpp
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2010-09-12 17:55:08 -0700
committer Jeff Brown <jeffbrown@google.com> 2010-10-15 16:00:07 -0700
commit6a817e22e4b09a982ba17c1aff57f9fcb735c950 (patch)
treeff280b6d55af358c8735de45c4e6cd0b0f9099ae /libs/ui/KeyCharacterMap.cpp
parentcc13ed145c3bcd5692b77a57866588737d6b45e4 (diff)
Add keycodes and meta-key modifiers to support external keyboards.
Added new key maps for external keyboards. These maps are intended to be shared across devices by inheriting the "keyboards.mk" product makefile as part of the device's product definition. One of the trickier changes here was to unwind some code in MetaKeyKeyListener that assumed that only the low 8 bits of the meta key state were actually used. The new code abandons bitshifts in favor of simple conditionals that are probably easier to read anyways. The special meta key state constants used by MetaKeyKeyListener are now (@hide) defined in KeyEvent now so as to make it clearer that they share the same code space even if those codes are not valid for KeyEvents. The EventHub now takes care of detecting the appropriate key layout map and key character map when the device is added and sets system properties accordingly. This avoids having duplicate code in KeyCharacterMap to probe for the appropriate key character map although the current probing mechanism has been preserved for legacy reasons just in case. Added support for tracking caps lock, num lock and scroll lock and turning their corresponding LEDs on and off as needed. The key character map format will need to be updated to correctly support PC style external keyboard semantics related to modifier keys. That will come in a later change so caps lock doesn't actually do anything right now except turn the shiny LEDs on and off... Added a list of symbolic key names to KeyEvent and improved the toString() output for debug diagnosis. Having this list in a central place in the framework also allows us to remove it from Monkey so there is one less thing to maintain when we add new keycodes. Bug: 2912307 Change-Id: If8c25e8d50a7c29bbf5d663c94284f5f86de5da4
Diffstat (limited to 'libs/ui/KeyCharacterMap.cpp')
-rw-r--r--libs/ui/KeyCharacterMap.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/libs/ui/KeyCharacterMap.cpp b/libs/ui/KeyCharacterMap.cpp
index e891181c82..870a45c169 100644
--- a/libs/ui/KeyCharacterMap.cpp
+++ b/libs/ui/KeyCharacterMap.cpp
@@ -156,26 +156,38 @@ KeyCharacterMap::find_key(int keycode)
KeyCharacterMap*
KeyCharacterMap::load(int id)
{
- KeyCharacterMap* rv = NULL;
+ KeyCharacterMap* map;
char path[PATH_MAX];
char propName[100];
char dev[PROPERTY_VALUE_MAX];
- char tmpfn[PROPERTY_VALUE_MAX];
+ char fn[PROPERTY_VALUE_MAX];
int err;
+
+ // Check whether the EventHub has set a key character map filename for us already.
+ sprintf(propName, "hw.keyboards.%u.kcmfile", id);
+ err = property_get(propName, fn, "");
+ if (err > 0) {
+ map = try_file(fn);
+ if (map) {
+ return map;
+ }
+ LOGW("Error loading keycharmap file '%s'. %s='%s'", path, propName, fn);
+ }
+
+ // Try using the device name.
const char* root = getenv("ANDROID_ROOT");
sprintf(propName, "hw.keyboards.%u.devname", id);
err = property_get(propName, dev, "");
if (err > 0) {
// replace all the spaces with underscores
- strcpy(tmpfn, dev);
- for (char *p = strchr(tmpfn, ' '); p && *p; p = strchr(tmpfn, ' '))
+ strcpy(fn, dev);
+ for (char *p = strchr(fn, ' '); p && *p; p = strchr(p + 1, ' '))
*p = '_';
- snprintf(path, sizeof(path), "%s/usr/keychars/%s.kcm.bin", root, tmpfn);
- //LOGD("load: dev='%s' path='%s'\n", dev, path);
- rv = try_file(path);
- if (rv != NULL) {
- return rv;
+ snprintf(path, sizeof(path), "%s/usr/keychars/%s.kcm.bin", root, fn);
+ map = try_file(path);
+ if (map) {
+ return map;
}
LOGW("Error loading keycharmap file '%s'. %s='%s'", path, propName, dev);
} else {
@@ -183,14 +195,14 @@ KeyCharacterMap::load(int id)
}
snprintf(path, sizeof(path), "%s/usr/keychars/qwerty.kcm.bin", root);
- rv = try_file(path);
- if (rv == NULL) {
- LOGE("Can't find any keycharmaps (also tried %s)", path);
- return NULL;
+ map = try_file(path);
+ if (map) {
+ LOGW("Using default keymap: %s", path);
+ return map;
}
- LOGW("Using default keymap: %s", path);
- return rv;
+ LOGE("Can't find any keycharmaps (also tried %s)", path);
+ return NULL;
}
KeyCharacterMap*