Skip to content

Commit 7388156

Browse files
committed
fix key mapping
Signed-off-by: Michel-FK <[email protected]>
1 parent ecfb930 commit 7388156

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ opkinfo
44
opkrun
55
libopk.plist
66
unsqfs.plist
7+
CMakeCache.txt
8+
CMakeFiles/
9+
Makefile
10+
bindings/
11+
*.cmake
12+
*.pc
13+
*.so

opkrun.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <errno.h>
77
#include <fcntl.h>
88
#include <getopt.h>
9+
#include <libgen.h>
910
#include <limits.h>
1011
#include <stdbool.h>
1112
#include <stdio.h>
@@ -43,7 +44,7 @@
4344

4445
struct params {
4546
char *exec[NB_PARAMS_MAX];
46-
char *keymap[NB_PARAMS_MAX];
47+
char *keymap;
4748
bool needs_terminal, needs_joystick, needs_gsensor, needs_downscaling;
4849
};
4950

@@ -108,6 +109,7 @@ static int read_params(struct OPK *opk, struct params *params)
108109
const char *exec_name = NULL;
109110
size_t exec_name_len = 0;
110111

112+
params->keymap = NULL;
111113
for (;;) {
112114
const char *key, *val;
113115
size_t skey, sval;
@@ -154,6 +156,11 @@ static int read_params(struct OPK *opk, struct params *params)
154156
params->needs_downscaling = !strncmp(val, "true", sval);
155157
continue;
156158
}
159+
160+
if (!strncmp(key, "FK-Keymap", skey)) {
161+
params->keymap = strndup(val, sval);
162+
continue;
163+
}
157164
}
158165

159166
if (!exec_name) {
@@ -386,6 +393,11 @@ int main(int argc, char **argv)
386393

387394
free(params.exec[0]);
388395

396+
printf("arg = %d\n", arg);
397+
for (arg = 0; args[arg]; arg++) {
398+
printf("args[%d] = \"%s\"\n", arg, args[arg]);
399+
}
400+
389401
umount(OPK_MOUNTPOINT);
390402
mkdir(OPK_MOUNTPOINT, 0755);
391403

@@ -424,65 +436,59 @@ int main(int argc, char **argv)
424436
if (params.needs_downscaling)
425437
enable_downscaling();
426438

427-
428439
/* Apply keymaps if found */
429440
char *dirc = strdup(args[arg - 1]);
430441
char *dname = dirname(dirc);
431442
char *basec = strdup(args[arg - 1]);
443+
char *bname = basename(basec);
432444
char *p, command[PATH_MAX];
433445
FILE *fp;
434-
446+
435447
/* Initialize keymap command */
436448
strcpy(command, "keymap ");
437449

438-
/* Compute basename without extension */
439-
p = strrchr(basec, '.');
450+
/* Compute basename without suffix */
451+
p = strrchr(bname, '.');
440452
if (p) {
441453
*p = '\0';
442454
}
443455

444456
/* Apply console (directory) keymap first, if any */
445457
sprintf(&command[7], "%s/default_config.key", dname);
446-
//printf("console keymap command: \"%s\"\n", command);
447458
if (!access(&command[7], R_OK)) {
448459
fp = popen(command, "r");
449460
if (fp != NULL) {
450-
printf("Applied console keymap command: \"%s\"\n", command);
451461
pclose(fp);
462+
} else {
463+
fprintf(stderr, "WARNING: Cannot apply console keymap command: \"%s\"\n",
464+
command);
452465
}
453-
else{
454-
fprintf(stderr, "WARNING: Cannot apply console keymap command: \"%s\"\n", command);
455-
}
456466
}
457467

458468
/* Then apply OPk keymap, if any */
459469
if (params.keymap != NULL) {
460-
sprintf(&command[7], "%s", params.keymap);
461-
//printf("OPK keymap command: \"%s\"\n", command);
470+
sprintf(&command[7], "%s/%s", OPK_MOUNTPOINT, params.keymap);
462471
if (!access(&command[7], R_OK)) {
463472
fp = popen(command, "r");
464473
if (fp != NULL) {
465-
printf("Applied FK-Keymap command: \"%s\"\n", command);
466474
pclose(fp);
475+
} else {
476+
fprintf(stderr, "WARNING: Cannot apply FK-Keymap command: \"%s\"\n",
477+
command);
467478
}
468-
else{
469-
fprintf(stderr, "WARNING: Cannot apply FK-Keymap command: \"%s\"\n", command);
470-
}
471479
}
472480
}
473481

474-
/* Apply game keymap, if any */
475-
sprintf(&command[7], "%s.key", basec);
476-
//printf("game keymap \"%s\"\n", command);
482+
/* Eventually apply game keymap, if any */
483+
sprintf(&command[7], "%s/%s.key", dname, bname);
477484
if (!access(&command[7], R_OK)) {
478485
fp = popen(command, "r");
479486
if (fp != NULL) {
480-
printf("Applied game keymap command: \"%s\"\n", command);
481487
pclose(fp);
488+
} else {
489+
fprintf(stderr, "WARNING: Cannot apply game keymap command: \"%s\"\n",
490+
command);
482491
}
483-
else{
484-
fprintf(stderr, "WARNING: Cannot apply game keymap command: \"%s\"\n", command);
485-
}
486492
}
487493
free(dirc);
488494
free(basec);
@@ -508,11 +514,11 @@ int main(int argc, char **argv)
508514
int status;
509515
waitpid(son, &status, 0);
510516

511-
/* move back to / folder */
517+
/* Move back to / folder */
512518
chdir("/");
513519

514520
/* Restore default keymap */
515-
fp = popen("keymap default", "r");
521+
fp = popen("keymap reset", "r");
516522
if (fp != NULL) {
517523
pclose(fp);
518524
}

0 commit comments

Comments
 (0)