Skip to content

Commit f0efffc

Browse files
committed
x11: Be a little less aggressive with Xinput2IsInitialized checks.
Just in case this ever get deinitialized sooner, we'd still like to SDL_free() things on shutdown, etc. Reference PR #13148. (cherry picked from commit 9e0d9f3)
1 parent 1b41cd7 commit f0efffc

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/video/x11/SDL_x11pen.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,22 @@ static X11_PenHandle *X11_MaybeAddPen(SDL_VideoDevice *_this, const XIDeviceInfo
283283

284284
X11_PenHandle *X11_MaybeAddPenByDeviceID(SDL_VideoDevice *_this, int deviceid)
285285
{
286-
if (!X11_Xinput2IsInitialized()) return NULL;
287-
SDL_VideoData *data = _this->internal;
288-
int num_device_info = 0;
289-
XIDeviceInfo *device_info = X11_XIQueryDevice(data->display, deviceid, &num_device_info);
290-
if (device_info) {
291-
SDL_assert(num_device_info == 1);
292-
X11_PenHandle *handle = X11_MaybeAddPen(_this, device_info);
293-
X11_XIFreeDeviceInfo(device_info);
294-
return handle;
286+
if (X11_Xinput2IsInitialized()) {
287+
SDL_VideoData *data = _this->internal;
288+
int num_device_info = 0;
289+
XIDeviceInfo *device_info = X11_XIQueryDevice(data->display, deviceid, &num_device_info);
290+
if (device_info) {
291+
SDL_assert(num_device_info == 1);
292+
X11_PenHandle *handle = X11_MaybeAddPen(_this, device_info);
293+
X11_XIFreeDeviceInfo(device_info);
294+
return handle;
295+
}
295296
}
296297
return NULL;
297298
}
298299

299300
void X11_RemovePenByDeviceID(int deviceid)
300301
{
301-
if (!X11_Xinput2IsInitialized()) return;
302302
X11_PenHandle *handle = X11_FindPenByDeviceID(deviceid);
303303
if (handle) {
304304
SDL_RemovePenDevice(0, handle->pen);
@@ -308,7 +308,10 @@ void X11_RemovePenByDeviceID(int deviceid)
308308

309309
void X11_InitPen(SDL_VideoDevice *_this)
310310
{
311-
if (!X11_Xinput2IsInitialized()) return;
311+
if (!X11_Xinput2IsInitialized()) {
312+
return; // we need XIQueryDevice() for this.
313+
}
314+
312315
SDL_VideoData *data = _this->internal;
313316

314317
#define LOOKUP_PEN_ATOM(X) X11_XInternAtom(data->display, X, False)
@@ -338,7 +341,6 @@ static void X11_FreePenHandle(SDL_PenID instance_id, void *handle, void *userdat
338341

339342
void X11_QuitPen(SDL_VideoDevice *_this)
340343
{
341-
if (!X11_Xinput2IsInitialized()) return;
342344
SDL_RemoveAllPenDevices(X11_FreePenHandle, NULL);
343345
}
344346

0 commit comments

Comments
 (0)