From 6b360d8b0401bf3337b1b4f70e0bf630abdc421b Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 25 Feb 2022 23:50:38 -0500 Subject: action.c keyremap clean-up add logf to core_keymap.c move the remap out of the loop and eliminate a status flag Change-Id: I9ab841037a8ea7dff736b452ff55e8242084af82 --- apps/action.c | 85 +++++++++++++++++++++++++++++------------------------- apps/action.h | 1 - apps/core_keymap.c | 9 ++++++ 3 files changed, 54 insertions(+), 41 deletions(-) (limited to 'apps') diff --git a/apps/action.c b/apps/action.c index 3a4cc2ff64..9ef10936f2 100644 --- a/apps/action.c +++ b/apps/action.c @@ -70,7 +70,6 @@ static action_last_t action_last = .wait_for_release = false, #ifndef DISABLE_ACTION_REMAP - .check_remap = false, .core_keymap = NULL, #endif @@ -590,12 +589,8 @@ static inline int get_next_context(const struct button_mapping *items, int i) */ static inline void action_code_lookup(action_last_t *last, action_cur_t *cur) { - int action = ACTION_NONE; + int action, i; int context = cur->context; - int i = 0; -#ifndef DISABLE_ACTION_REMAP - last->check_remap = (last->core_keymap != NULL); -#endif cur->is_prebutton = false; #ifdef HAVE_LOCKED_ACTIONS @@ -605,49 +600,55 @@ static inline void action_code_lookup(action_last_t *last, action_cur_t *cur) context |= CONTEXT_LOCKED; #endif - for(;;) - { - /* logf("context = %x",context); */ -#if (BUTTON_REMOTE != 0) - if ((cur->button & BUTTON_REMOTE) != 0) - { - context |= CONTEXT_REMOTE; - } -#endif - - if ((context & CONTEXT_PLUGIN) && cur->get_context_map) - { - cur->items = cur->get_context_map(context); - } #ifndef DISABLE_ACTION_REMAP - else if(last->check_remap) /* attempt to look up the button in user supplied remap */ + bool check_remap = (last->core_keymap != NULL); + /* attempt to look up the button in user supplied remap */ + if(check_remap && (context & CONTEXT_PLUGIN) == 0) { +#if 0 /*Disable the REMOTE context for remap for now (BUTTON_REMOTE != 0)*/ + if ((cur->button & BUTTON_REMOTE) != 0) + { + context |= CONTEXT_REMOTE; + } +#endif cur->items = last->core_keymap; i = 0; action = ACTION_UNKNOWN; /* check the lut at the beginning for the desired context */ - while (cur->items[i].action_code != (int) CONTEXT_STOPSEARCHING) + while (cur->items[i].button_code != BUTTON_NONE) { if (cur->items[i].action_code == CORE_CONTEXT_REMAP(context)) { i = cur->items[i].button_code; action = action_code_worker(last, cur, &i); - break; + if (action != ACTION_UNKNOWN) + { + cur->action = action; + return; + } } i++; } + } +#endif - if (action != ACTION_UNKNOWN) - break; - else - { - /* Not found -- fall through to inbuilt keymaps */ - i = 0; - last->check_remap = false; - cur->items = get_context_mapping(context); - } + i = 0; + action = ACTION_NONE; + /* attempt to look up the button in the in-built keymaps */ + for(;;) + { + /* logf("context = %x",context); */ +#if (BUTTON_REMOTE != 0) + if ((cur->button & BUTTON_REMOTE) != 0) + { + context |= CONTEXT_REMOTE; } #endif + + if ((context & CONTEXT_PLUGIN) && cur->get_context_map) + { + cur->items = cur->get_context_map(context); + } else { cur->items = get_context_mapping(context); @@ -1199,17 +1200,21 @@ int action_set_keymap(struct button_mapping* core_keymap, int count) if (count > 0 && core_keymap != NULL) /* saf-tey checks :) */ { int i = 0; - if (core_keymap[count - 1].action_code != (int) CONTEXT_STOPSEARCHING || - core_keymap[count - 1].button_code != BUTTON_NONE) /* check for sentinel at end*/ + struct button_mapping* entry = &core_keymap[count - 1]; + if (entry->action_code != (int) CONTEXT_STOPSEARCHING || + entry->button_code != BUTTON_NONE) /* check for sentinel at end*/ + { count = -1; + } - /* check the lut at the beginning for invalid offsets */ - while (count > 0 && core_keymap[i].action_code != (int) CONTEXT_STOPSEARCHING) + while (count > 0 && /* check the lut at the beginning for invalid offsets */ + (entry = &core_keymap[i])->action_code != (int) CONTEXT_STOPSEARCHING) { - if ((core_keymap[i].action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) + + if ((entry->action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) { - int firstbtn = core_keymap[i].button_code; - int endpos = firstbtn + core_keymap[i].pre_button_code; + int firstbtn = entry->button_code; + int endpos = firstbtn + entry->pre_button_code; if (firstbtn > count || firstbtn < i || endpos > count) { /* offset out of bounds */ @@ -1217,7 +1222,7 @@ int action_set_keymap(struct button_mapping* core_keymap, int count) break; } - if (core_keymap[endpos].action_code != (int) CONTEXT_STOPSEARCHING) + if (core_keymap[endpos].button_code != BUTTON_NONE) { /* stop sentinel is not at end of action lut*/ count = -3; diff --git a/apps/action.h b/apps/action.h index 7fadc015c8..35f08a3dbd 100644 --- a/apps/action.h +++ b/apps/action.h @@ -419,7 +419,6 @@ typedef struct bool wait_for_release; #ifndef DISABLE_ACTION_REMAP - bool check_remap; struct button_mapping* core_keymap; #endif diff --git a/apps/core_keymap.c b/apps/core_keymap.c index 131c48f45d..dbe7ae0072 100644 --- a/apps/core_keymap.c +++ b/apps/core_keymap.c @@ -23,6 +23,9 @@ #include "core_alloc.h" #include "core_keymap.h" +/*#define LOGF_ENABLE*/ +#include "logf.h" + #if !defined(__PCTOOL__) || defined(CHECKWPS) static int keymap_handle = -1; @@ -76,6 +79,7 @@ int core_load_key_remap(const char *filename) if (core_alloc_keymap(fsize) <= 0) { count = -30; + logf("core_keymap: %d Failed to allocate buffer", count); break; } buf = core_get_data(keymap_handle); @@ -84,7 +88,10 @@ int core_load_key_remap(const char *filename) count = action_set_keymap((struct button_mapping *) buf, count); } else + { count = -40; + logf("core_keymap: %d Failed to read", count); + } break; } close(fd); @@ -108,6 +115,7 @@ int open_key_remap(const char *filename, int *fd, size_t *fsize) if (count * sizeof(struct button_mapping) != *fsize) { count = -10; + logf("core_keymap: %d Size mismatch", count); break; } @@ -125,6 +133,7 @@ int open_key_remap(const char *filename, int *fd, size_t *fsize) else /* Header mismatch */ { count = -20; + logf("core_keymap: %d Header mismatch", count); break; } } -- cgit v1.2.3