From 1bd3a5b6be520731f18da12e6cc33c843d7a4ca6 Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 15 May 2026 15:23:37 -0300 Subject: [PATCH] doomgeneric: add env support for input selection and map esc to joystick --- patches/doomgeneric/jinx-working-patch.patch | 68 +++++++++++++++++--- recipes/doomgeneric | 2 +- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/patches/doomgeneric/jinx-working-patch.patch b/patches/doomgeneric/jinx-working-patch.patch index 22776b48..59962512 100644 --- a/patches/doomgeneric/jinx-working-patch.patch +++ b/patches/doomgeneric/jinx-working-patch.patch @@ -100,7 +100,7 @@ new file mode 100644 index 0000000..b8e0de9 --- /dev/null +++ doomgeneric-workdir/doomgeneric/doomgeneric_astral.c -@@ -0,0 +1,441 @@ +@@ -0,0 +1,479 @@ +#define _GNU_SOURCE +#include "doomkeys.h" + @@ -108,6 +108,7 @@ index 0000000..b8e0de9 + +#include +#include ++#include +#include +#include +#include @@ -226,12 +227,17 @@ index 0000000..b8e0de9 + return 0; +} + ++static int open_evdev_path(const char *path) ++{ ++ return open(path, O_RDONLY | O_NONBLOCK, 0); ++} ++ +static int open_evdev_device(int index) +{ + char path[32]; + + snprintf(path, sizeof(path), "/dev/input/event%d", index); -+ return open(path, O_RDONLY | O_NONBLOCK, 0); ++ return open_evdev_path(path); +} + +static void init_axis(int fd, axis_state_t *axis) @@ -247,6 +253,38 @@ index 0000000..b8e0de9 + +static void init_evdev(void) +{ ++ const char *keyboard_path = getenv("DOOM_KEYBOARD"); ++ const char *joystick_path = getenv("DOOM_JOYSTICK"); ++ ++ if (keyboard_path != NULL) { ++ kbfd = open_evdev_path(keyboard_path); ++ if (kbfd == -1) { ++ printf("doomgeneric: failed to open DOOM_KEYBOARD=%s: %s\n", keyboard_path, strerror(errno)); ++ exit(errno); ++ } ++ ++ if (!is_keyboard(kbfd)) { ++ printf("doomgeneric: DOOM_KEYBOARD=%s is not a keyboard\n", keyboard_path); ++ exit(ENODEV); ++ } ++ } ++ ++ if (joystick_path != NULL) { ++ joyfd = open_evdev_path(joystick_path); ++ if (joyfd == -1) { ++ printf("doomgeneric: failed to open DOOM_JOYSTICK=%s: %s\n", joystick_path, strerror(errno)); ++ exit(errno); ++ } ++ ++ if (!is_joystick(joyfd)) { ++ printf("doomgeneric: DOOM_JOYSTICK=%s is not a joystick\n", joystick_path); ++ exit(ENODEV); ++ } ++ ++ init_axis(joyfd, &joystick_axes[0]); ++ init_axis(joyfd, &joystick_axes[1]); ++ } ++ + for (int i = 0; i < MAX_EVDEV_DEVICES; ++i) { + int fd = open_evdev_device(i); + if (fd == -1) @@ -287,7 +325,7 @@ index 0000000..b8e0de9 + return KEY_RIGHTARROW; + case KEY_ENTER: + case KEY_KPENTER: -+ return KEY_ENTER; ++ return '\r'; + case KEY_LEFTCTRL: + case KEY_RIGHTCTRL: + return KEY_FIRE; @@ -740,11 +778,11 @@ index bf63035..2c84bcc 100644 printf("I_InitGraphics: framebuffer: x_res: %d, y_res: %d, x_virtual: %d, y_virtual: %d, bpp: %d\n", s_Fb.xres, s_Fb.yres, s_Fb.xres_virtual, s_Fb.yres_virtual, s_Fb.bits_per_pixel); @@ -240,6 +241,7 @@ void I_StartFrame (void) - void I_StartTic (void) - { - I_GetEvent(); +void I_StartTic (void) +{ + I_GetEvent(); + I_UpdateJoystick(); - } +} void I_UpdateNoBlit (void) @@ -325,7 +327,7 @@ void I_SetPalette (byte* palette) @@ -755,4 +793,18 @@ index bf63035..2c84bcc 100644 + /* performance boost: - * map to the right pixel format over here! */ + * map to the right pixel format over here! */ + +diff --git doomgeneric-clean/doomgeneric/m_controls.c doomgeneric-workdir/doomgeneric/m_controls.c +index 10e46aa..0f9d79d 100644 +--- doomgeneric-clean/doomgeneric/m_controls.c ++++ doomgeneric-workdir/doomgeneric/m_controls.c +@@ -190,7 +190,7 @@ int joybjump = -1; + int joybprevweapon = -1; + int joybnextweapon = -1; + +-int joybmenu = -1; ++int joybmenu = 4; + + // Control whether if a mouse button is double clicked, it acts like + // "use" has been pressed diff --git a/recipes/doomgeneric b/recipes/doomgeneric index 515c4b7f..186930de 100644 --- a/recipes/doomgeneric +++ b/recipes/doomgeneric @@ -1,5 +1,5 @@ name=doomgeneric -revision=2 +revision=4 from_source=doomgeneric imagedeps="build-essential" hostdeps="xgcc xbinutils"