From 9ceb982a63d61ea211ab6f0991c1bf2bbe430670 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Tue, 20 Jan 2026 12:21:42 +0000
Subject: [PATCH] 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>
---
src/video/dummy/SDL_nullvideo.c | 46 +++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c
index 228596cddb6d6..58063e2b469b9 100644
--- a/src/video/dummy/SDL_nullvideo.c
+++ b/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