From 295ec3790d191c41006d04b41db878dc1091b117 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 23 Feb 2022 21:26:37 -0500 Subject: Core Keyremap Allow setting keymap from plugin Allow setting and removing keyremap on the fly It was pretty annoying trying to work out a keyremap with a restart required to set the remap and was quite annoying when I was no longer able to navigate to the plugin or filebrowser due to setting the wrong remap now you can try out a keymap and if it doesn't work a restart will sort things out Change-Id: I848fb3bd759f9684ac2497324a371f92b7464f7b --- apps/plugins/keyremap.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'apps/plugins') diff --git a/apps/plugins/keyremap.c b/apps/plugins/keyremap.c index acd23172f0..593dc5a3b0 100644 --- a/apps/plugins/keyremap.c +++ b/apps/plugins/keyremap.c @@ -105,7 +105,9 @@ enum { M_SAVEKEYS, M_LOADKEYS, M_DELKEYS, + M_TMPCORE, M_SETCORE, + M_DELCORE, M_EXIT, M_LAST_MAINITEM, //MAIN MENU ITEM COUNT /*Menus not directly accessible from main menu*/ @@ -126,7 +128,9 @@ MENU_ITEM(M_RESETKEYS, "Reset Keymap", 1), MENU_ITEM(M_SAVEKEYS, "Save Keymap", 1), MENU_ITEM(M_LOADKEYS, "Load Keymaps", 1), MENU_ITEM(M_DELKEYS, "Delete Keymaps", 1), +MENU_ITEM(M_TMPCORE, "Temp Core Remap", 1), MENU_ITEM(M_SETCORE, "Set Core Remap", 1), +MENU_ITEM(M_DELCORE, "Delete Core Remap", 1), MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), MENU_ITEM(M_BUTTONS, "Buttons", -1), /* Set at runtime in plugin_start: */ @@ -878,6 +882,17 @@ int menu_action_root(int *action, int selected_item, bool* exit, struct gui_sync { keyset.view_lastcol = -1; } + else if (cur->menuid == MENU_ID(M_TMPCORE)) + { + int entry_count;/* (ctx_count + ctx_count + act_count + 1) */ + struct button_mapping *keymap = keyremap_create_temp(&entry_count); + if (rb->core_set_keyremap(keymap, entry_count) >= 0) + rb->splash(HZ *2, "Keymap Applied"); + else + rb->splash(HZ *2, "Error Applying"); + + goto default_handler; + } else if (cur->menuid == MENU_ID(M_SETCORE)) { if (rb->file_exists(CORE_KEYREMAP_FILE) && 0 == core_savecount++) @@ -887,7 +902,25 @@ int menu_action_root(int *action, int selected_item, bool* exit, struct gui_sync if (keyremap_save_current(CORE_KEYREMAP_FILE) == 0) rb->splash(HZ *2, "Error Saving"); else - rb->splash(HZ *2, "Saved, Restart Device"); + { + rb->splash(HZ *2, "Saved"); + int entry_count;/* (ctx_count + ctx_count + act_count + 1) */ + struct button_mapping *keymap = keyremap_create_temp(&entry_count); + rb->core_set_keyremap(keymap, entry_count); + } + goto default_handler; + } + else if (cur->menuid == MENU_ID(M_DELCORE)) + { + rb->core_set_keyremap(NULL, -1); + if (rb->file_exists(CORE_KEYREMAP_FILE)) + { + rb->rename(CORE_KEYREMAP_FILE, KMFDIR "/core_deleted" KMFEXT2); + rb->splash(HZ *2, "Removed"); + } + else + rb->splash(HZ *2, "Error Removing"); + goto default_handler; } else if (cur->menuid == MENU_ID(M_SAVEKEYS)) -- cgit v1.2.3