Răsfoiți Sursa

dummy: Only initialize evdev input devices in the evdev driver

This avoids some misleading error messages when running unit tests with
the dummy driver: on a typical desktop Linux system, it's normal for
opening keyboards and mouse in `/dev/input/*` to fail with `EACCES`,
and in container technologies that share `/sys` but not `/dev` with the
container, we can find that we fail to open them with `ENOENT`.

Resolves: https://github.com/libsdl-org/SDL/issues/14872
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 9ceb982a63d61ea211ab6f0991c1bf2bbe430670)
Simon McVittie 1 lună în urmă
părinte
comite
b451b27427
1 a modificat fișierele cu 33 adăugiri și 13 ștergeri
  1. 33 13
      src/video/dummy/SDL_nullvideo.c

+ 33 - 13
src/video/dummy/SDL_nullvideo.c

@@ -52,8 +52,13 @@
 #define DUMMYVID_DRIVER_EVDEV_NAME "evdev"
 
 // Initialization/Query functions
+static bool DUMMY_VideoInitCommon(SDL_VideoDevice *_this);
 static bool DUMMY_VideoInit(SDL_VideoDevice *_this);
 static void DUMMY_VideoQuit(SDL_VideoDevice *_this);
+#ifdef SDL_INPUT_LINUXEV
+static bool DUMMY_EVDEV_VideoInit(SDL_VideoDevice *_this);
+static void DUMMY_EVDEV_VideoQuit(SDL_VideoDevice *_this);
+#endif
 
 static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
 {
@@ -125,6 +130,21 @@ VideoBootStrap DUMMY_bootstrap = {
 
 #ifdef SDL_INPUT_LINUXEV
 
+static bool DUMMY_EVDEV_VideoInit(SDL_VideoDevice *_this)
+{
+    if (!DUMMY_VideoInitCommon(_this)) {
+        return false;
+    }
+
+    SDL_EVDEV_Init();
+    return true;
+}
+
+static void DUMMY_EVDEV_VideoQuit(SDL_VideoDevice *_this)
+{
+    SDL_EVDEV_Quit();
+}
+
 static void DUMMY_EVDEV_Poll(SDL_VideoDevice *_this)
 {
     (void)_this;
@@ -135,6 +155,8 @@ static SDL_VideoDevice *DUMMY_EVDEV_CreateDevice(void)
 {
     SDL_VideoDevice *device = DUMMY_InternalCreateDevice(DUMMYVID_DRIVER_EVDEV_NAME);
     if (device) {
+        device->VideoInit = DUMMY_EVDEV_VideoInit;
+        device->VideoQuit = DUMMY_EVDEV_VideoQuit;
         device->PumpEvents = DUMMY_EVDEV_Poll;
     }
     return device;
@@ -147,16 +169,14 @@ VideoBootStrap DUMMY_evdev_bootstrap = {
     false
 };
 
-#else
+#endif // SDL_INPUT_LINUXEV
 
 static bool DUMMY_SetRelativeMouseMode(bool enabled)
 {
     return true;
 }
 
-#endif // SDL_INPUT_LINUXEV
-
-bool DUMMY_VideoInit(SDL_VideoDevice *_this)
+bool DUMMY_VideoInitCommon(SDL_VideoDevice *_this)
 {
     SDL_DisplayMode mode;
 
@@ -169,21 +189,21 @@ bool DUMMY_VideoInit(SDL_VideoDevice *_this)
         return false;
     }
 
-#ifdef SDL_INPUT_LINUXEV
-    SDL_EVDEV_Init();
-#else
-    SDL_GetMouse()->SetRelativeMouseMode = DUMMY_SetRelativeMouseMode;
-#endif
+    return true;
+}
+
+bool DUMMY_VideoInit(SDL_VideoDevice *_this)
+{
+    if (!DUMMY_VideoInitCommon(_this)) {
+        return false;
+    }
 
-    // We're done!
+    SDL_GetMouse()->SetRelativeMouseMode = DUMMY_SetRelativeMouseMode;
     return true;
 }
 
 void DUMMY_VideoQuit(SDL_VideoDevice *_this)
 {
-#ifdef SDL_INPUT_LINUXEV
-    SDL_EVDEV_Quit();
-#endif
 }
 
 #endif // SDL_VIDEO_DRIVER_DUMMY