FS#13824 - In keyremap plugin in "test keymap" context is wrong

The context was supplied with context|flag but expected context x flag

Also fixes a bug where the user export doesn't show the correct save location
if changed -- it still saved properly anyway..

Change-Id: I061d63e15475d2cb73d070737dc18d56d7800472
This commit is contained in:
William Wilgus 2026-03-14 10:54:56 -04:00
parent 72969fee7e
commit 314becf2ac

View file

@ -582,7 +582,7 @@ static void keyremap_save_user_keys(bool notify)
rb->splashf(HZ *2, "Saved %s", buf); rb->splashf(HZ *2, "Saved %s", buf);
} }
static int keyremap_export_current(char *filenamebuf, size_t bufsz) static int keyremap_export_current(char *filenamebuf, size_t bufsz, const char *filename)
{ {
filenamebuf[bufsz - 1] = '\0'; filenamebuf[bufsz - 1] = '\0';
int i, j; int i, j;
@ -596,7 +596,7 @@ static int keyremap_export_current(char *filenamebuf, size_t bufsz)
logf("%s: Not enough entries", __func__); logf("%s: Not enough entries", __func__);
return 0; return 0;
} }
int fd = rb->open(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0666); int fd = rb->open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) if (fd < 0)
return -1; return -1;
@ -657,7 +657,8 @@ fail:
static void keyremap_export_user_keys(void) static void keyremap_export_user_keys(void)
{ {
const bool notify = true; const bool notify = true;
char buf[MAX_PATH]; static char fnamebuf[MAX_PATH];
static char buf[MAX_PATH];
int i = 0; int i = 0;
do do
{ {
@ -670,14 +671,13 @@ static void keyremap_export_user_keys(void)
return; return;
} }
if (keyremap_export_current(buf, sizeof(buf)) <= 0) if (keyremap_export_current(fnamebuf, sizeof(fnamebuf), buf) <= 0)
{ {
if(notify) if(notify)
rb->splash(HZ *2, "Error Saving"); rb->splash(HZ *2, "Error Saving");
} }
else if (notify) else if (notify)
{ {
rb->snprintf(buf, sizeof(buf), "%s/%s%d%s", "", KMFUSER, i, ".txt");
rb->splashf(HZ *2, "Saved %s", buf); rb->splashf(HZ *2, "Saved %s", buf);
} }
} }
@ -1085,6 +1085,24 @@ fail:
return 0; return 0;
} }
static int context_encode_flags(int context)
{
int enctx = (context & 0xFF) % LAST_ACTION_PLACEHOLDER; /* strip flags */
/* takes a context | flag and converts it to context x flag */
for (int i = ARRAYLEN(context_flags) - 1; i > 0; i--) /* don't check idx 0*/
{
/* convert context | flag to context x flag */
if ((context & context_flags[i].flag) == context_flags[i].flag)
{
logf("found ctx flag %s", context_flags[i].name);
enctx &= ~context_flags[i].flag;
enctx += i * LAST_CONTEXT_PLACEHOLDER;
}
}
logf("%s in: %x out: %x\n", __func__, context, enctx);
return enctx;
}
static int keyremap_load_file(const char *filename) static int keyremap_load_file(const char *filename)
{ {
logf("keyremap: load %s", filename); logf("keyremap: load %s", filename);
@ -1118,7 +1136,8 @@ static int keyremap_load_file(const char *filename)
} }
if ((entry.action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) if ((entry.action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED)
{ {
int context = (entry.action_code & ~CONTEXT_REMAPPED); int context = context_encode_flags(entry.action_code & ~CONTEXT_REMAPPED);
#if 0
for (int i = ARRAYLEN(context_flags) - 1; i > 0; i--) /* don't check idx 0*/ for (int i = ARRAYLEN(context_flags) - 1; i > 0; i--) /* don't check idx 0*/
{ {
/* convert context | flag to context x flag */ /* convert context | flag to context x flag */
@ -1129,6 +1148,7 @@ static int keyremap_load_file(const char *filename)
context += i * LAST_CONTEXT_PLACEHOLDER; context += i * LAST_CONTEXT_PLACEHOLDER;
} }
} }
#endif
int offset = entry.button_code; int offset = entry.button_code;
int entries = entry.pre_button_code; int entries = entry.pre_button_code;
if (offset == 0 || entries <= 0) if (offset == 0 || entries <= 0)
@ -1346,7 +1366,10 @@ static const char *test_keymap_name_cb(int selected_item, void* data,
if (keytest.context >= 0) if (keytest.context >= 0)
{ {
if (selected_item == 0) if (selected_item == 0)
rb->snprintf(buf, buf_len, "< %s >", ctx_name_and_flag(keytest.context)); {
int ctx = context_encode_flags(keytest.context);
rb->snprintf(buf, buf_len, "< %s >", ctx_name_and_flag(ctx));
}
else if (selected_item == 1) else if (selected_item == 1)
{ {
if (keytest.countdown >= 10) if (keytest.countdown >= 10)