2
0
Эх сурвалжийг харах

Add config SUPPORT_SSH_KEYBOARD_RPI

Allow to reconfigure stdin to read input keys, this process could lead to undesired effects. Use with care.

Disabled by default.
Ray 6 жил өмнө
parent
commit
b1806f6600
3 өөрчлөгдсөн 24 нэмэгдсэн , 8 устгасан
  1. 1 0
      src/CMakeOptions.txt
  2. 2 0
      src/config.h
  3. 21 8
      src/core.c

+ 1 - 0
src/CMakeOptions.txt

@@ -25,6 +25,7 @@ set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \$
 option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON)
 option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag" ON)
 option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON)
+option(SUPPORT_SSH_KEYBOARD_RPI "Reconfigure standard input to receive key inputs, works with SSH connection" OFF)
 option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON)
 option(SUPPORT_SCREEN_CAPTURE "Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()" ON)
 option(SUPPORT_GIF_RECORDING "Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()" ON)

+ 2 - 0
src/config.h

@@ -43,6 +43,8 @@
 // Mouse gestures are directly mapped like touches and processed by gestures system
 #define SUPPORT_MOUSE_GESTURES      1
 // Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
+//#define SUPPORT_SSH_KEYBOARD_RPI    1
+//Reconfigure standard input to receive key inputs, works with SSH connection.
 //#define SUPPORT_BUSY_WAIT_LOOP      1
 // Wait for events passively (sleeping while no events) instead of polling them actively every frame
 //#define SUPPORT_EVENTS_WAITING      1

+ 21 - 8
src/core.c

@@ -50,6 +50,11 @@
 *   #define SUPPORT_TOUCH_AS_MOUSE
 *       Touch input and mouse input are shared. Mouse functions also return touch information.
 *
+*   #define SUPPORT_SSH_KEYBOARD_RPI (Raspberry Pi only)
+*       Reconfigure standard input to receive key inputs, works with SSH connection.
+*       WARNING: Reconfiguring standard input could lead to undesired effects, like breaking other running processes or
+*       blocking the device is not restored properly. Use with care.
+*
 *   #define SUPPORT_BUSY_WAIT_LOOP
 *       Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
 *
@@ -489,16 +494,19 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
 #endif
 
 #if defined(PLATFORM_RPI)
+#if defined(SUPPORT_SSH_KEYBOARD_RPI)
+static void InitKeyboard(void);                         // Init raw keyboard system (standard input reading)
+static void ProcessKeyboard(void);                      // Process keyboard events
+static void RestoreKeyboard(void);                      // Restore keyboard system
+#endif
+
 static void InitEvdevInput(void);                       // Evdev inputs initialization
 static void EventThreadSpawn(char *device);             // Identifies a input device and spawns a thread to handle it if needed
 static void *EventThread(void *arg);                    // Input device events reading thread
 
-static void InitKeyboard(void);                         // Init raw keyboard system (standard input reading)
-static void ProcessKeyboard(void);                      // Process keyboard events
-static void RestoreKeyboard(void);                      // Restore keyboard system
 static void InitGamepad(void);                          // Init raw gamepad input
 static void *GamepadThread(void *arg);                  // Mouse reading thread
-#endif
+#endif  // PLATFORM_RPI
 
 #if defined(_WIN32)
     // NOTE: We include Sleep() function signature here to avoid windows.h inclusion
@@ -610,8 +618,10 @@ void InitWindow(int width, int height, const char *title)
 #if defined(PLATFORM_RPI)
     // Init raw input system
     InitEvdevInput();   // Evdev inputs initialization
-    InitKeyboard();     // Keyboard init
     InitGamepad();      // Gamepad init
+#if defined(SUPPORT_SSH_KEYBOARD_RPI)
+    InitKeyboard();     // Keyboard init
+#endif
 #endif
 
 #if defined(PLATFORM_WEB)
@@ -3544,7 +3554,7 @@ static void PollInputEvents(void)
     }
 #endif
 
-#if defined(PLATFORM_RPI)
+#if defined(PLATFORM_RPI) && defined(SUPPORT_SSH_KEYBOARD_RPI)
     // NOTE: Keyboard reading could be done using input_event(s) reading or just read from stdin,
     // we now use both methods inside here. 2nd method is still used for legacy purposes (Allows for input trough SSH console)
     ProcessKeyboard();
@@ -4181,6 +4191,8 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
 #endif
 
 #if defined(PLATFORM_RPI)
+
+#if defined(SUPPORT_SSH_KEYBOARD_RPI)
 // Initialize Keyboard system (using standard input)
 static void InitKeyboard(void)
 {
@@ -4341,6 +4353,7 @@ static void RestoreKeyboard(void)
     // Reconfigure keyboard to default mode
     ioctl(STDIN_FILENO, KDSKBMODE, defaultKeyboardMode);
 }
+#endif      //SUPPORT_SSH_KEYBOARD_RPI
 
 // Initialise user input from evdev(/dev/input/event<N>) this means mouse, keyboard or gamepad devices
 static void InitEvdevInput(void)
@@ -4739,7 +4752,7 @@ static void *EventThread(void *arg)
             // Gesture update
             if (gestureUpdate)
             {
-#if defined(SUPPORT_GESTURES_SYSTEM)
+            #if defined(SUPPORT_GESTURES_SYSTEM)
                 GestureEvent gestureEvent = { 0 };
 
                 gestureEvent.pointCount = 0;
@@ -4761,7 +4774,7 @@ static void *EventThread(void *arg)
                 gestureEvent.position[3] = touchPosition[3];
 
                 ProcessGestureEvent(gestureEvent);
-#endif
+            #endif
             }
         }
         else