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
2021-04-03 01:34:29 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 by William Wilgus
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "action.h"
|
|
|
|
#include "core_alloc.h"
|
|
|
|
#include "core_keymap.h"
|
|
|
|
|
2022-02-26 04:50:38 +00:00
|
|
|
/*#define LOGF_ENABLE*/
|
|
|
|
#include "logf.h"
|
|
|
|
|
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
2021-04-03 01:34:29 +00:00
|
|
|
#if !defined(__PCTOOL__) || defined(CHECKWPS)
|
2022-04-03 12:48:52 +00:00
|
|
|
int core_set_keyremap(struct button_mapping* core_keymap, int count)
|
2022-02-24 02:26:37 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
return action_set_keymap(core_keymap, count);
|
2022-02-24 02:26:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:48:52 +00:00
|
|
|
static int open_key_remap(const char *filename, int *countp)
|
2022-02-24 02:26:37 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
int fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
size_t fsize = filesize(fd);
|
|
|
|
int count = fsize / sizeof(struct button_mapping);
|
|
|
|
if (count == 0 || (size_t)(count * sizeof(struct button_mapping)) != fsize)
|
2022-02-24 02:26:37 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
logf("core_keyremap: bad filesize %d / %lu", count, (unsigned long)fsize);
|
|
|
|
goto error;
|
2022-02-24 02:26:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:48:52 +00:00
|
|
|
struct button_mapping header;
|
|
|
|
if(read(fd, &header, sizeof(header)) != (ssize_t)sizeof(header))
|
2022-02-24 02:26:37 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
logf("core_keyremap: read error");
|
|
|
|
goto error;
|
2022-02-24 02:26:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:48:52 +00:00
|
|
|
if (header.action_code != KEYREMAP_VERSION ||
|
|
|
|
header.button_code != KEYREMAP_HEADERID ||
|
|
|
|
header.pre_button_code != count)
|
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
2021-04-03 01:34:29 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
logf("core_keyremap: bad header %d", count);
|
|
|
|
goto error;
|
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
2021-04-03 01:34:29 +00:00
|
|
|
}
|
2022-04-03 12:48:52 +00:00
|
|
|
|
|
|
|
*countp = count - 1;
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
error:
|
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
2021-04-03 01:34:29 +00:00
|
|
|
close(fd);
|
2022-04-03 12:48:52 +00:00
|
|
|
return -1;
|
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
2021-04-03 01:34:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:48:52 +00:00
|
|
|
int core_load_key_remap(const char *filename)
|
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
2021-04-03 01:34:29 +00:00
|
|
|
{
|
2022-04-03 12:48:52 +00:00
|
|
|
int count = 0; /* gcc falsely believes this may be used uninitialized */
|
|
|
|
int fd = open_key_remap(filename, &count);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
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
2021-04-03 01:34:29 +00:00
|
|
|
|
2022-04-03 12:48:52 +00:00
|
|
|
size_t bufsize = count * sizeof(struct button_mapping);
|
2022-10-15 22:55:39 +00:00
|
|
|
int handle = core_alloc(bufsize);
|
2022-04-03 12:48:52 +00:00
|
|
|
if (handle > 0)
|
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
2021-04-03 01:34:29 +00:00
|
|
|
{
|
2023-01-14 18:50:15 +00:00
|
|
|
void *data = core_get_data_pinned(handle);
|
|
|
|
|
|
|
|
if (read(fd, data, bufsize) == (ssize_t)bufsize)
|
2022-04-03 12:48:52 +00:00
|
|
|
count = action_set_keymap_handle(handle, count);
|
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
2021-04-03 01:34:29 +00:00
|
|
|
|
2023-01-14 18:50:15 +00:00
|
|
|
core_put_data_pinned(data);
|
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
2021-04-03 01:34:29 +00:00
|
|
|
}
|
2022-04-03 12:48:52 +00:00
|
|
|
|
|
|
|
close(fd);
|
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
2021-04-03 01:34:29 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(__PCTOOL__) */
|