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

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 314becf2ac3eadbcc952b9fed1d2184219327737
Author: William Wilgus <[email protected]>
Date:   Sat Mar 14 10:54:56 2026 -0400

    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

diff --git a/apps/plugins/keyremap.c b/apps/plugins/keyremap.c
index bb7e965963..410f4096e4 100644
--- a/apps/plugins/keyremap.c
+++ b/apps/plugins/keyremap.c
@@ -582,7 +582,7 @@ static void keyremap_save_user_keys(bool notify)
         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';
     int i, j;
@@ -596,7 +596,7 @@ static int keyremap_export_current(char *filenamebuf, size_t bufsz)
         logf("%s: Not enough entries", __func__);
         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)
         return -1;
@@ -657,7 +657,8 @@ fail:
 static void keyremap_export_user_keys(void)
 {
     const bool notify = true;
-    char buf[MAX_PATH];
+    static char fnamebuf[MAX_PATH];
+    static char buf[MAX_PATH];
     int i = 0;
     do
     {
@@ -670,14 +671,13 @@ static void keyremap_export_user_keys(void)
         return;
     }
 
-    if (keyremap_export_current(buf, sizeof(buf)) <= 0)
+    if (keyremap_export_current(fnamebuf, sizeof(fnamebuf), buf) <= 0)
     {
         if(notify)
             rb->splash(HZ *2, "Error Saving");
     }
     else if (notify)
     {
-        rb->snprintf(buf, sizeof(buf), "%s/%s%d%s", "", KMFUSER, i, ".txt");
         rb->splashf(HZ *2, "Saved %s", buf);
     }
 }
@@ -1085,6 +1085,24 @@ fail:
     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)
 {
     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)
             {
-                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*/
                 {
                     /* convert context | flag to context x flag */
@@ -1129,6 +1148,7 @@ static int keyremap_load_file(const char *filename)
                         context += i * LAST_CONTEXT_PLACEHOLDER;
                     }
                 }
+#endif
                 int offset = entry.button_code;
                 int entries = entry.pre_button_code;
                 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 (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)
         {
             if (keytest.countdown >= 10)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.