Skip to content

Commit 262b012

Browse files
committed
Fix X11 compilation if XI2 Gesture are not supported
1 parent 08c6827 commit 262b012

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

cmake/sdlchecks.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,23 @@ macro(CheckX11)
408408
if(HAVE_XINPUT2_MULTITOUCH)
409409
set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
410410
endif()
411+
412+
# Check for gesture
413+
check_c_source_compiles("
414+
#include <X11/Xlib.h>
415+
#include <X11/Xproto.h>
416+
#include <X11/extensions/XInput2.h>
417+
int event_type = XI_GesturePinchBegin;
418+
XITouchClassInfo *t;
419+
Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f) {
420+
return (Status)0;
421+
}
422+
int main(int argc, char **argv) { return 0; }" HAVE_XINPUT2_GESTURE)
423+
if(HAVE_XINPUT2_GESTURE)
424+
set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE 1)
425+
endif()
426+
427+
411428
endif()
412429

413430
# check along with XInput2.h because we use Xfixes with XIBarrierReleasePointer

include/build_config/SDL_build_config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@
406406
#cmakedefine SDL_VIDEO_DRIVER_X11_XFIXES @SDL_VIDEO_DRIVER_X11_XFIXES@
407407
#cmakedefine SDL_VIDEO_DRIVER_X11_XINPUT2 @SDL_VIDEO_DRIVER_X11_XINPUT2@
408408
#cmakedefine SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH @SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH@
409+
#cmakedefine SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE @SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE@
409410
#cmakedefine SDL_VIDEO_DRIVER_X11_XRANDR @SDL_VIDEO_DRIVER_X11_XRANDR@
410411
#cmakedefine SDL_VIDEO_DRIVER_X11_XSCRNSAVER @SDL_VIDEO_DRIVER_X11_XSCRNSAVER@
411412
#cmakedefine SDL_VIDEO_DRIVER_X11_XSHAPE @SDL_VIDEO_DRIVER_X11_XSHAPE@

src/video/x11/SDL_x11xinput2.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static int xinput2_initialized = 0;
3737

3838
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
3939
static int xinput2_multitouch_supported = 0;
40+
#endif
41+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE
4042
static int xinput2_pinch_swipe_supported = 0;
4143
#endif
4244

@@ -157,6 +159,8 @@ SDL_bool X11_InitXinput2(SDL_VideoDevice *_this)
157159
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
158160
/* Multitouch needs XInput 2.2 */
159161
xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
162+
#endif
163+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE
160164
/* Gesture and Swipe needs XInput 2.4 */
161165
xinput2_pinch_swipe_supported = xinput2_version_atleast(version, 2, 4);
162166
#endif
@@ -482,7 +486,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
482486
{
483487
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
484488
const SDL_Pen *pen = SDL_GetPenPtr(X11_PenIDFromDeviceID(xev->deviceid));
485-
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
489+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
486490
SDL_bool pointer_emulated = ((xev->flags & XIPointerEmulated) != 0);
487491
#else
488492
SDL_bool pointer_emulated = SDL_FALSE;
@@ -525,7 +529,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
525529
}
526530
} break;
527531

528-
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
532+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
529533
case XI_TouchBegin:
530534
{
531535
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
@@ -552,7 +556,9 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
552556
xinput2_normalize_touch_coordinates(window, xev->event_x, xev->event_y, &x, &y);
553557
SDL_SendTouchMotion(0, xev->sourceid, xev->detail, window, x, y, 1.0);
554558
} break;
559+
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
555560

561+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE
556562
case XI_GesturePinchBegin:
557563
case XI_GesturePinchUpdate:
558564
case XI_GesturePinchEnd:
@@ -584,7 +590,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
584590
SDL_SendSwipe(0, window, x, y);
585591
} break;
586592

587-
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
593+
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE */
588594
}
589595
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
590596
}
@@ -617,15 +623,19 @@ void X11_Xinput2SelectTouch(SDL_VideoDevice *_this, SDL_Window *window)
617623
XISetMask(mask, XI_TouchEnd);
618624
XISetMask(mask, XI_Motion);
619625

626+
620627
if (X11_Xinput2IsPinchSwipeSupported()) {
628+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE
621629
XISetMask(mask, XI_GesturePinchBegin);
622630
XISetMask(mask, XI_GesturePinchUpdate);
623631
XISetMask(mask, XI_GesturePinchEnd);
624632
XISetMask(mask, XI_GestureSwipeBegin);
625633
XISetMask(mask, XI_GestureSwipeUpdate);
626634
XISetMask(mask, XI_GestureSwipeEnd);
635+
#endif
627636
}
628637

638+
629639
X11_XISelectEvents(data->display, window_data->xwindow, &eventmask, 1);
630640
#endif
631641
}
@@ -699,7 +709,7 @@ int X11_Xinput2IsMultitouchSupported(void)
699709

700710
int X11_Xinput2IsPinchSwipeSupported(void)
701711
{
702-
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
712+
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_GESTURE
703713
return xinput2_initialized && xinput2_pinch_swipe_supported;
704714
#else
705715
return 0;

0 commit comments

Comments
 (0)