SDL: Checks if xinput is loaded before trying to call xinput functions (1b41c)

From 1b41cd759cf136202ff1082c8d2fcb8133b25e79 Mon Sep 17 00:00:00 2001
From: Mason Remaley <[EMAIL REDACTED]>
Date: Thu, 29 May 2025 14:23:44 -0700
Subject: [PATCH] Checks if xinput is loaded before trying to call xinput
 functions

(cherry picked from commit 57b6e6c7f9cc13dcd6fd2b3756037c88dc840f6f)
---
 src/video/x11/SDL_x11pen.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/video/x11/SDL_x11pen.c b/src/video/x11/SDL_x11pen.c
index f16da51c5abde..95629da5539f0 100644
--- a/src/video/x11/SDL_x11pen.c
+++ b/src/video/x11/SDL_x11pen.c
@@ -283,6 +283,7 @@ static X11_PenHandle *X11_MaybeAddPen(SDL_VideoDevice *_this, const XIDeviceInfo
 
 X11_PenHandle *X11_MaybeAddPenByDeviceID(SDL_VideoDevice *_this, int deviceid)
 {
+    if (!X11_Xinput2IsInitialized()) return NULL;
     SDL_VideoData *data = _this->internal;
     int num_device_info = 0;
     XIDeviceInfo *device_info = X11_XIQueryDevice(data->display, deviceid, &num_device_info);
@@ -297,6 +298,7 @@ X11_PenHandle *X11_MaybeAddPenByDeviceID(SDL_VideoDevice *_this, int deviceid)
 
 void X11_RemovePenByDeviceID(int deviceid)
 {
+    if (!X11_Xinput2IsInitialized()) return;
     X11_PenHandle *handle = X11_FindPenByDeviceID(deviceid);
     if (handle) {
         SDL_RemovePenDevice(0, handle->pen);
@@ -306,6 +308,7 @@ void X11_RemovePenByDeviceID(int deviceid)
 
 void X11_InitPen(SDL_VideoDevice *_this)
 {
+    if (!X11_Xinput2IsInitialized()) return;
     SDL_VideoData *data = _this->internal;
 
     #define LOOKUP_PEN_ATOM(X) X11_XInternAtom(data->display, X, False)
@@ -335,6 +338,7 @@ static void X11_FreePenHandle(SDL_PenID instance_id, void *handle, void *userdat
 
 void X11_QuitPen(SDL_VideoDevice *_this)
 {
+    if (!X11_Xinput2IsInitialized()) return;
     SDL_RemoveAllPenDevices(X11_FreePenHandle, NULL);
 }