diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-02-23 21:26:37 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-02-23 21:38:27 -0500 |
commit | 295ec3790d191c41006d04b41db878dc1091b117 (patch) | |
tree | beafe7409e2722f199abb96a657e6a52adce9ea6 /apps/core_keymap.c | |
parent | f7bb9e21672566308ab837c370f27c10c154e6fc (diff) | |
download | rockbox-295ec3790d191c41006d04b41db878dc1091b117.tar.gz rockbox-295ec3790d191c41006d04b41db878dc1091b117.zip |
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
Diffstat (limited to 'apps/core_keymap.c')
-rw-r--r-- | apps/core_keymap.c | 49 |
1 files changed, 40 insertions, 9 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; |