From f7bb9e21672566308ab837c370f27c10c154e6fc Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 2 Apr 2021 21:34:29 -0400 Subject: Add custom action mapping to core results of an idea I discussed in IRC changed the way the lookup in the remap file works.. entries consist of 3 int [action, button, prebtn] context look up table is at the beginning action_code contains the (context | CONTEXT_REMAPPED) button_code contains the index of the first remapped action for the matched context [0] CORE_CONTEXT_REMAP(ctx1) offset1=(3), count=(1) [1] CORE_CONTEXT_REMAP(ctx2, offset2=(5), count=(1) [2] sentinel, 0, 0 [3] act0, btn, 0 [4] sentinel 0, 0 [5] act1, btn, 0 [6] sentinel, 0, 0 Note: last entry of each group is always the sentinel [CONTEXT_STOPSEARCHING, BUTTON_NONE, BUTTON_NONE] contexts must match exactly -- re-mapped contexts run before the built in w/ fall through contexts ie. you can't remap std_context and expect it to match std_context actions from the WPS context. -- Done -- Code for reading core remap entries -- Done -- import of core remap entires from disk -- Done -- plugin to set new key mapping (the hard part) The plugin is started and FULLY functional you can add actions and contexts you can change context, action, button, prebtn delete keymap files load keymapfiles save user keymaps test keymaps before applying them loading keymaps to core still requires restart ----------------------------------------------------------------------------------------------- Change-Id: Ib8b88c5ae91af4d540e1829de5db32669cd68203 --- apps/action.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 2 deletions(-) (limited to 'apps/action.c') diff --git a/apps/action.c b/apps/action.c index b31c4fa927..3a4cc2ff64 100644 --- a/apps/action.c +++ b/apps/action.c @@ -69,6 +69,11 @@ static action_last_t action_last = .tick = 0, .wait_for_release = false, +#ifndef DISABLE_ACTION_REMAP + .check_remap = false, + .core_keymap = NULL, +#endif + #ifdef HAVE_TOUCHSCREEN .ts_data = 0, .ts_short_press = false, @@ -499,7 +504,7 @@ static inline int action_code_worker(action_last_t *last, int *end ) { int ret = ACTION_UNKNOWN; - int i = 0; + int i = *end; unsigned int found = 0; while (cur->items[i].button_code != BUTTON_NONE) { @@ -588,7 +593,9 @@ static inline void action_code_lookup(action_last_t *last, action_cur_t *cur) int action = ACTION_NONE; 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 @@ -609,9 +616,42 @@ static inline void action_code_lookup(action_last_t *last, action_cur_t *cur) #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 */ + { + 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) + { + if (cur->items[i].action_code == CORE_CONTEXT_REMAP(context)) + { + i = cur->items[i].button_code; + action = action_code_worker(last, cur, &i); + break; + } + i++; + } + + 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); + } + } +#endif else + { cur->items = get_context_mapping(context); + } if (cur->items != NULL) { @@ -1150,6 +1190,66 @@ int get_action(int context, int timeout) return action; } +int action_set_keymap(struct button_mapping* core_keymap, int count) +{ + +#ifdef DISABLE_ACTION_REMAP + count = -1; +#else + 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*/ + count = -1; + + /* check the lut at the beginning for invalid offsets */ + while (count > 0 && core_keymap[i].action_code != (int) CONTEXT_STOPSEARCHING) + { + if ((core_keymap[i].action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) + { + int firstbtn = core_keymap[i].button_code; + int endpos = firstbtn + core_keymap[i].pre_button_code; + if (firstbtn > count || firstbtn < i || endpos > count) + { + /* offset out of bounds */ + count = -2; + break; + } + + if (core_keymap[endpos].action_code != (int) CONTEXT_STOPSEARCHING) + { + /* stop sentinel is not at end of action lut*/ + count = -3; + } + } + else /* something other than a context remap in the lut */ + { + count = -4; + break; + } + + i++; + + if (i >= count) /* no sentinel in the lut */ + { + count = -5; + break; + } + } + + if (count <= 0) + core_keymap = NULL; + } + else +#endif + { + core_keymap = NULL; + } + action_last.core_keymap = core_keymap; + return count; +} + int get_custom_action(int context,int timeout, const struct button_mapping* (*get_context_map)(int)) { -- cgit v1.2.3