diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/core_keymap.c | 49 | ||||
-rw-r--r-- | apps/core_keymap.h | 4 | ||||
-rw-r--r-- | apps/plugin.c | 2 | ||||
-rw-r--r-- | apps/plugin.h | 1 | ||||
-rw-r--r-- | apps/plugins/keyremap.c | 35 |
5 files changed, 81 insertions, 10 deletions
diff --git a/apps/core_keymap.c b/apps/core_keymap.c index 0a7241a9e0..131c48f45d 100644 --- a/apps/core_keymap.c +++ b/apps/core_keymap.c | |||
@@ -24,25 +24,56 @@ | |||
24 | #include "core_keymap.h" | 24 | #include "core_keymap.h" |
25 | 25 | ||
26 | #if !defined(__PCTOOL__) || defined(CHECKWPS) | 26 | #if !defined(__PCTOOL__) || defined(CHECKWPS) |
27 | static int keymap_handle = -1; | ||
28 | |||
29 | static int core_alloc_keymap(size_t bufsz) | ||
30 | { | ||
31 | keymap_handle = core_alloc_ex("key remap", bufsz, &buflib_ops_locked); | ||
32 | return keymap_handle; | ||
33 | } | ||
34 | |||
35 | static void core_free_keymap(void) | ||
36 | { | ||
37 | action_set_keymap(NULL, -1); | ||
38 | if (keymap_handle > 0) /* free old buffer */ | ||
39 | { | ||
40 | keymap_handle = core_free(keymap_handle); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | /* Allocates buffer from core and copies keymap into it */ | ||
45 | int core_set_keyremap(struct button_mapping* core_keymap, int count) | ||
46 | { | ||
47 | |||
48 | core_free_keymap(); | ||
49 | if (count > 0) | ||
50 | { | ||
51 | size_t bufsize = count * sizeof(struct button_mapping); | ||
52 | if (core_keymap != NULL && core_alloc_keymap(bufsize) > 0) | ||
53 | { | ||
54 | char *buf = core_get_data(keymap_handle); | ||
55 | memcpy(buf, core_keymap, bufsize); | ||
56 | count = action_set_keymap((struct button_mapping *) buf, count); | ||
57 | } | ||
58 | else | ||
59 | count = -1; | ||
60 | } | ||
61 | return count; | ||
62 | } | ||
63 | |||
27 | int core_load_key_remap(const char *filename) | 64 | int core_load_key_remap(const char *filename) |
28 | { | 65 | { |
29 | static int keymap_handle = -1; | ||
30 | char *buf; | 66 | char *buf; |
31 | int fd = -1; | 67 | int fd = -1; |
32 | int count = 0; | 68 | int count = 0; |
33 | size_t fsize = 0; | 69 | size_t fsize = 0; |
34 | if (keymap_handle > 0) /* free old buffer */ | 70 | core_free_keymap(); |
35 | { | 71 | |
36 | action_set_keymap(NULL, -1); | ||
37 | keymap_handle = core_free(keymap_handle); | ||
38 | } | ||
39 | if (filename != NULL) | 72 | if (filename != NULL) |
40 | count = open_key_remap(filename, &fd, &fsize); | 73 | count = open_key_remap(filename, &fd, &fsize); |
41 | while (count > 0) | 74 | while (count > 0) |
42 | { | 75 | { |
43 | 76 | if (core_alloc_keymap(fsize) <= 0) | |
44 | keymap_handle = core_alloc_ex("key remap", fsize, &buflib_ops_locked); | ||
45 | if (keymap_handle <= 0) | ||
46 | { | 77 | { |
47 | count = -30; | 78 | count = -30; |
48 | break; | 79 | break; |
diff --git a/apps/core_keymap.h b/apps/core_keymap.h index 39d35e9cd9..dad9875364 100644 --- a/apps/core_keymap.h +++ b/apps/core_keymap.h | |||
@@ -24,12 +24,16 @@ | |||
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | #include <inttypes.h> | 25 | #include <inttypes.h> |
26 | #include "config.h" | 26 | #include "config.h" |
27 | #include "action.h" | ||
27 | #define KEYREMAP_VERSION 1 | 28 | #define KEYREMAP_VERSION 1 |
28 | #define KEYREMAP_HEADERID (LAST_ACTION_PLACEHOLDER | (TARGET_ID << 8)) | 29 | #define KEYREMAP_HEADERID (LAST_ACTION_PLACEHOLDER | (TARGET_ID << 8)) |
29 | 30 | ||
30 | /* If exists remap file will be loaded at startup */ | 31 | /* If exists remap file will be loaded at startup */ |
31 | #define CORE_KEYREMAP_FILE ROCKBOX_DIR "/keyremap.kmf" | 32 | #define CORE_KEYREMAP_FILE ROCKBOX_DIR "/keyremap.kmf" |
32 | 33 | ||
34 | /* Allocates core buffer, copies keymap to allow buttons for actions to be remapped*/ | ||
35 | int core_set_keyremap(struct button_mapping* core_keymap, int count); | ||
36 | |||
33 | /* open_key_remap(filename , *fd (you must close file_descriptor), *fsize) | 37 | /* open_key_remap(filename , *fd (you must close file_descriptor), *fsize) |
34 | * checks/strips header and returns remaining count | 38 | * checks/strips header and returns remaining count |
35 | * fd is opened and set to first record | 39 | * fd is opened and set to first record |
diff --git a/apps/plugin.c b/apps/plugin.c index 8434fea07d..670770dfc6 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include "pathfuncs.h" | 46 | #include "pathfuncs.h" |
47 | #include "load_code.h" | 47 | #include "load_code.h" |
48 | #include "file.h" | 48 | #include "file.h" |
49 | #include "core_keymap.h" | ||
49 | 50 | ||
50 | #if CONFIG_CHARGING | 51 | #if CONFIG_CHARGING |
51 | #include "power.h" | 52 | #include "power.h" |
@@ -807,6 +808,7 @@ static const struct plugin_api rockbox_api = { | |||
807 | battery_current, | 808 | battery_current, |
808 | onplay_show_playlist_menu, | 809 | onplay_show_playlist_menu, |
809 | queue_remove_from_head, | 810 | queue_remove_from_head, |
811 | core_set_keyremap, | ||
810 | }; | 812 | }; |
811 | 813 | ||
812 | static int plugin_buffer_handle; | 814 | static int plugin_buffer_handle; |
diff --git a/apps/plugin.h b/apps/plugin.h index 8ade3a05ac..de1077c9b4 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -934,6 +934,7 @@ struct plugin_api { | |||
934 | int (*battery_current)(void); | 934 | int (*battery_current)(void); |
935 | void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb)); | 935 | void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb)); |
936 | void (*queue_remove_from_head)(struct event_queue *q, long id); | 936 | void (*queue_remove_from_head)(struct event_queue *q, long id); |
937 | int (*core_set_keyremap)(struct button_mapping* core_keymap, int count); | ||
937 | }; | 938 | }; |
938 | 939 | ||
939 | /* plugin header */ | 940 | /* plugin header */ |
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 { | |||
105 | M_SAVEKEYS, | 105 | M_SAVEKEYS, |
106 | M_LOADKEYS, | 106 | M_LOADKEYS, |
107 | M_DELKEYS, | 107 | M_DELKEYS, |
108 | M_TMPCORE, | ||
108 | M_SETCORE, | 109 | M_SETCORE, |
110 | M_DELCORE, | ||
109 | M_EXIT, | 111 | M_EXIT, |
110 | M_LAST_MAINITEM, //MAIN MENU ITEM COUNT | 112 | M_LAST_MAINITEM, //MAIN MENU ITEM COUNT |
111 | /*Menus not directly accessible from main menu*/ | 113 | /*Menus not directly accessible from main menu*/ |
@@ -126,7 +128,9 @@ MENU_ITEM(M_RESETKEYS, "Reset Keymap", 1), | |||
126 | MENU_ITEM(M_SAVEKEYS, "Save Keymap", 1), | 128 | MENU_ITEM(M_SAVEKEYS, "Save Keymap", 1), |
127 | MENU_ITEM(M_LOADKEYS, "Load Keymaps", 1), | 129 | MENU_ITEM(M_LOADKEYS, "Load Keymaps", 1), |
128 | MENU_ITEM(M_DELKEYS, "Delete Keymaps", 1), | 130 | MENU_ITEM(M_DELKEYS, "Delete Keymaps", 1), |
131 | MENU_ITEM(M_TMPCORE, "Temp Core Remap", 1), | ||
129 | MENU_ITEM(M_SETCORE, "Set Core Remap", 1), | 132 | MENU_ITEM(M_SETCORE, "Set Core Remap", 1), |
133 | MENU_ITEM(M_DELCORE, "Delete Core Remap", 1), | ||
130 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), | 134 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), |
131 | MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), | 135 | MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), |
132 | MENU_ITEM(M_BUTTONS, "Buttons", -1), /* Set at runtime in plugin_start: */ | 136 | 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 | |||
878 | { | 882 | { |
879 | keyset.view_lastcol = -1; | 883 | keyset.view_lastcol = -1; |
880 | } | 884 | } |
885 | else if (cur->menuid == MENU_ID(M_TMPCORE)) | ||
886 | { | ||
887 | int entry_count;/* (ctx_count + ctx_count + act_count + 1) */ | ||
888 | struct button_mapping *keymap = keyremap_create_temp(&entry_count); | ||
889 | if (rb->core_set_keyremap(keymap, entry_count) >= 0) | ||
890 | rb->splash(HZ *2, "Keymap Applied"); | ||
891 | else | ||
892 | rb->splash(HZ *2, "Error Applying"); | ||
893 | |||
894 | goto default_handler; | ||
895 | } | ||
881 | else if (cur->menuid == MENU_ID(M_SETCORE)) | 896 | else if (cur->menuid == MENU_ID(M_SETCORE)) |
882 | { | 897 | { |
883 | if (rb->file_exists(CORE_KEYREMAP_FILE) && 0 == core_savecount++) | 898 | 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 | |||
887 | if (keyremap_save_current(CORE_KEYREMAP_FILE) == 0) | 902 | if (keyremap_save_current(CORE_KEYREMAP_FILE) == 0) |
888 | rb->splash(HZ *2, "Error Saving"); | 903 | rb->splash(HZ *2, "Error Saving"); |
889 | else | 904 | else |
890 | rb->splash(HZ *2, "Saved, Restart Device"); | 905 | { |
906 | rb->splash(HZ *2, "Saved"); | ||
907 | int entry_count;/* (ctx_count + ctx_count + act_count + 1) */ | ||
908 | struct button_mapping *keymap = keyremap_create_temp(&entry_count); | ||
909 | rb->core_set_keyremap(keymap, entry_count); | ||
910 | } | ||
911 | goto default_handler; | ||
912 | } | ||
913 | else if (cur->menuid == MENU_ID(M_DELCORE)) | ||
914 | { | ||
915 | rb->core_set_keyremap(NULL, -1); | ||
916 | if (rb->file_exists(CORE_KEYREMAP_FILE)) | ||
917 | { | ||
918 | rb->rename(CORE_KEYREMAP_FILE, KMFDIR "/core_deleted" KMFEXT2); | ||
919 | rb->splash(HZ *2, "Removed"); | ||
920 | } | ||
921 | else | ||
922 | rb->splash(HZ *2, "Error Removing"); | ||
923 | |||
891 | goto default_handler; | 924 | goto default_handler; |
892 | } | 925 | } |
893 | else if (cur->menuid == MENU_ID(M_SAVEKEYS)) | 926 | else if (cur->menuid == MENU_ID(M_SAVEKEYS)) |