summaryrefslogtreecommitdiff
path: root/apps/core_keymap.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-04-02 21:34:29 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2022-02-23 08:47:12 -0500
commitf7bb9e21672566308ab837c370f27c10c154e6fc (patch)
tree688aa4e1a44572452ee192838b0af510b57ce770 /apps/core_keymap.c
parent7952687185aa27fcecc0924efa45c0e64e0ed4fe (diff)
downloadrockbox-f7bb9e21672566308ab837c370f27c10c154e6fc.tar.gz
rockbox-f7bb9e21672566308ab837c370f27c10c154e6fc.zip
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
Diffstat (limited to 'apps/core_keymap.c')
-rw-r--r--apps/core_keymap.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/apps/core_keymap.c b/apps/core_keymap.c
new file mode 100644
index 0000000000..0a7241a9e0
--- /dev/null
+++ b/apps/core_keymap.c
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2020 by William Wilgus
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "action.h"
23#include "core_alloc.h"
24#include "core_keymap.h"
25
26#if !defined(__PCTOOL__) || defined(CHECKWPS)
27int core_load_key_remap(const char *filename)
28{
29 static int keymap_handle = -1;
30 char *buf;
31 int fd = -1;
32 int count = 0;
33 size_t fsize = 0;
34 if (keymap_handle > 0) /* free old buffer */
35 {
36 action_set_keymap(NULL, -1);
37 keymap_handle = core_free(keymap_handle);
38 }
39 if (filename != NULL)
40 count = open_key_remap(filename, &fd, &fsize);
41 while (count > 0)
42 {
43
44 keymap_handle = core_alloc_ex("key remap", fsize, &buflib_ops_locked);
45 if (keymap_handle <= 0)
46 {
47 count = -30;
48 break;
49 }
50 buf = core_get_data(keymap_handle);
51 if (read(fd, buf, fsize) == (ssize_t) fsize)
52 {
53 count = action_set_keymap((struct button_mapping *) buf, count);
54 }
55 else
56 count = -40;
57 break;
58 }
59 close(fd);
60 return count;
61}
62
63int open_key_remap(const char *filename, int *fd, size_t *fsize)
64{
65 int count = 0;
66
67 while (filename && fd && fsize)
68 {
69 *fsize = 0;
70 *fd = open(filename, O_RDONLY);
71 if (*fd)
72 {
73 *fsize = filesize(*fd);
74
75 count = *fsize / sizeof(struct button_mapping);
76
77 if (count * sizeof(struct button_mapping) != *fsize)
78 {
79 count = -10;
80 break;
81 }
82
83 if (count > 1)
84 {
85 struct button_mapping header = {0};
86 read(*fd, &header, sizeof(struct button_mapping));
87 if (KEYREMAP_VERSION == header.action_code &&
88 KEYREMAP_HEADERID == header.button_code &&
89 header.pre_button_code == count)
90 {
91 count--;
92 *fsize -= sizeof(struct button_mapping);
93 }
94 else /* Header mismatch */
95 {
96 count = -20;
97 break;
98 }
99 }
100 }
101 break;
102 }
103 return count;
104}
105
106#endif /* !defined(__PCTOOL__) */