Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+30 -7
+30 -7
apps/plugins/keyremap.c
··· 582 582 rb->splashf(HZ *2, "Saved %s", buf); 583 583 } 584 584 585 - static int keyremap_export_current(char *filenamebuf, size_t bufsz) 585 + static int keyremap_export_current(char *filenamebuf, size_t bufsz, const char *filename) 586 586 { 587 587 filenamebuf[bufsz - 1] = '\0'; 588 588 int i, j; ··· 596 596 logf("%s: Not enough entries", __func__); 597 597 return 0; 598 598 } 599 - int fd = rb->open(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0666); 599 + int fd = rb->open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); 600 600 601 601 if (fd < 0) 602 602 return -1; ··· 657 657 static void keyremap_export_user_keys(void) 658 658 { 659 659 const bool notify = true; 660 - char buf[MAX_PATH]; 660 + static char fnamebuf[MAX_PATH]; 661 + static char buf[MAX_PATH]; 661 662 int i = 0; 662 663 do 663 664 { ··· 670 671 return; 671 672 } 672 673 673 - if (keyremap_export_current(buf, sizeof(buf)) <= 0) 674 + if (keyremap_export_current(fnamebuf, sizeof(fnamebuf), buf) <= 0) 674 675 { 675 676 if(notify) 676 677 rb->splash(HZ *2, "Error Saving"); 677 678 } 678 679 else if (notify) 679 680 { 680 - rb->snprintf(buf, sizeof(buf), "%s/%s%d%s", "", KMFUSER, i, ".txt"); 681 681 rb->splashf(HZ *2, "Saved %s", buf); 682 682 } 683 683 } ··· 1085 1085 return 0; 1086 1086 } 1087 1087 1088 + static int context_encode_flags(int context) 1089 + { 1090 + int enctx = (context & 0xFF) % LAST_ACTION_PLACEHOLDER; /* strip flags */ 1091 + /* takes a context | flag and converts it to context x flag */ 1092 + for (int i = ARRAYLEN(context_flags) - 1; i > 0; i--) /* don't check idx 0*/ 1093 + { 1094 + /* convert context | flag to context x flag */ 1095 + if ((context & context_flags[i].flag) == context_flags[i].flag) 1096 + { 1097 + logf("found ctx flag %s", context_flags[i].name); 1098 + enctx &= ~context_flags[i].flag; 1099 + enctx += i * LAST_CONTEXT_PLACEHOLDER; 1100 + } 1101 + } 1102 + logf("%s in: %x out: %x\n", __func__, context, enctx); 1103 + return enctx; 1104 + } 1105 + 1088 1106 static int keyremap_load_file(const char *filename) 1089 1107 { 1090 1108 logf("keyremap: load %s", filename); ··· 1118 1136 } 1119 1137 if ((entry.action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) 1120 1138 { 1121 - int context = (entry.action_code & ~CONTEXT_REMAPPED); 1139 + int context = context_encode_flags(entry.action_code & ~CONTEXT_REMAPPED); 1140 + #if 0 1122 1141 for (int i = ARRAYLEN(context_flags) - 1; i > 0; i--) /* don't check idx 0*/ 1123 1142 { 1124 1143 /* convert context | flag to context x flag */ ··· 1129 1148 context += i * LAST_CONTEXT_PLACEHOLDER; 1130 1149 } 1131 1150 } 1151 + #endif 1132 1152 int offset = entry.button_code; 1133 1153 int entries = entry.pre_button_code; 1134 1154 if (offset == 0 || entries <= 0) ··· 1346 1366 if (keytest.context >= 0) 1347 1367 { 1348 1368 if (selected_item == 0) 1349 - rb->snprintf(buf, buf_len, "< %s >", ctx_name_and_flag(keytest.context)); 1369 + { 1370 + int ctx = context_encode_flags(keytest.context); 1371 + rb->snprintf(buf, buf_len, "< %s >", ctx_name_and_flag(ctx)); 1372 + } 1350 1373 else if (selected_item == 1) 1351 1374 { 1352 1375 if (keytest.countdown >= 10)