summaryrefslogtreecommitdiff
path: root/apps/core_keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/core_keymap.c')
-rw-r--r--apps/core_keymap.c49
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)
27static int keymap_handle = -1;
28
29static 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
35static 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 */
45int 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
27int core_load_key_remap(const char *filename) 64int 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;