From 21a377707f1ca91b42727ec848ee4375c33e8ef0 Mon Sep 17 00:00:00 2001 From: imterah Date: Tue, 10 Jun 2025 21:19:02 -0400 Subject: [PATCH] Disable stdin input by default and add ability to disable EVDEV input --- CMakeOptions.txt | 4 +- cmake/LibraryConfigurations.cmake | 8 ++++ src/config.h | 2 +- src/platforms/rcore_drm.c | 76 +++++++++++++++++-------------- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index b865fb981..563f40f8f 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -1,4 +1,4 @@ -# ## Config options ### +### Config options ### include(CMakeDependentOption) include(EnumOption) @@ -29,6 +29,8 @@ set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \$ # DRM build options option(ENABLE_WAYLAND_DRM_LEASING "Enables DRM leasing in the DRM backend via the Wayland desktop" OFF) +option(DISABLE_EVDEV_INPUT "Disable evdev input in the DRM backend" OFF) +option(SUPPORT_SSH_KEYBOARD_RPI "Support using keyboard input from stdin" ON) include(ParseConfigHeader) diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index 061bb4364..72e81978c 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -103,6 +103,14 @@ elseif ("${PLATFORM}" MATCHES "DRM") list(APPEND LIBS_PRIVATE ${WAYLAND_CLIENT}) endif () + if (DISABLE_EVDEV_INPUT) + add_definitions(-DDISABLE_EVDEV_INPUT) + endif () + + if (SUPPORT_SSH_KEYBOARD_RPI) + add_definitions(-DSUPPORT_SSH_KEYBOARD_RPI) + endif () + elseif ("${PLATFORM}" MATCHES "SDL") find_package(SDL2 REQUIRED) set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL") diff --git a/src/config.h b/src/config.h index e3749c560..06b69eec7 100644 --- a/src/config.h +++ b/src/config.h @@ -50,7 +50,7 @@ // Mouse gestures are directly mapped like touches and processed by gestures system #define SUPPORT_MOUSE_GESTURES 1 // Reconfigure standard input to receive key inputs, works with SSH connection. -#define SUPPORT_SSH_KEYBOARD_RPI 1 +#define SUPPORT_SSH_KEYBOARD_RPI 0 // Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. // However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. #define SUPPORT_WINMM_HIGHRES_TIMER 1 diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 94b48e9ce..c556290d0 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -1639,46 +1639,52 @@ static void ProcessKeyboard(void) // this means mouse, keyboard or gamepad devices static void InitEvdevInput(void) { - char path[MAX_FILEPATH_LENGTH] = { 0 }; - DIR *directory = NULL; - struct dirent *entity = NULL; + #if !defined(DISABLE_EVDEV_INPUT) + char path[MAX_FILEPATH_LENGTH] = { 0 }; + DIR *directory = NULL; + struct dirent *entity = NULL; - // Initialise keyboard file descriptor - platform.keyboardFd = -1; - platform.mouseFd = -1; + // Initialise keyboard file descriptor + platform.keyboardFd = -1; + platform.mouseFd = -1; - // Reset variables - for (int i = 0; i < MAX_TOUCH_POINTS; ++i) - { - CORE.Input.Touch.position[i].x = -1; - CORE.Input.Touch.position[i].y = -1; - } - - // Reset keyboard key state - for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) - { - CORE.Input.Keyboard.currentKeyState[i] = 0; - CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; - } - - // Open the linux directory of "/dev/input" - directory = opendir(DEFAULT_EVDEV_PATH); - - if (directory) - { - while ((entity = readdir(directory)) != NULL) + // Reset variables + for (int i = 0; i < MAX_TOUCH_POINTS; ++i) { - if ((strncmp("event", entity->d_name, strlen("event")) == 0) || // Search for devices named "event*" - (strncmp("mouse", entity->d_name, strlen("mouse")) == 0)) // Search for devices named "mouse*" - { - sprintf(path, "%s%s", DEFAULT_EVDEV_PATH, entity->d_name); - ConfigureEvdevDevice(path); // Configure the device if appropriate - } + CORE.Input.Touch.position[i].x = -1; + CORE.Input.Touch.position[i].y = -1; } - closedir(directory); - } - else TRACELOG(LOG_WARNING, "INPUT: Failed to open linux event directory: %s", DEFAULT_EVDEV_PATH); + // Reset keyboard key state + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) + { + CORE.Input.Keyboard.currentKeyState[i] = 0; + CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; + } + + // Open the linux directory of "/dev/input" + directory = opendir(DEFAULT_EVDEV_PATH); + + if (directory) + { + while ((entity = readdir(directory)) != NULL) + { + if ((strncmp("event", entity->d_name, strlen("event")) == 0) || // Search for devices named "event*" + (strncmp("mouse", entity->d_name, strlen("mouse")) == 0)) // Search for devices named "mouse*" + { + sprintf(path, "%s%s", DEFAULT_EVDEV_PATH, entity->d_name); + ConfigureEvdevDevice(path); // Configure the device if appropriate + } + } + + closedir(directory); + } + else TRACELOG(LOG_WARNING, "INPUT: Failed to open linux event directory: %s", DEFAULT_EVDEV_PATH); + #else + TRACELOG(LOG_INFO, "INPUT: Not doing evdev input configuration as it's disabled"); + platform.keyboardFd = -1; + platform.mouseFd = -1; + #endif } // Identifies a input device and configures it for use if appropriate