From ef54e1be7f6c88ad89422e29ba289c166dad8d43 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 25 Jan 2021 06:52:23 +1100 Subject: [PATCH] [client] x11: add error checking around XIGrabDevice --- client/displayservers/X11/x11.c | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index 7b2d8931..618c1ecd 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -572,6 +572,25 @@ static bool x11EventFilter(SDL_Event * event) } } +static void x11PrintGrabError(const char * type, int dev, Status ret) +{ + const char * errStr; + switch(ret) + { + case AlreadyGrabbed : errStr = "AlreadyGrabbed" ; break; + case GrabNotViewable: errStr = "GrabNotViewable"; break; + case GrabFrozen : errStr = "GrabFrozen" ; break; + case GrabInvalidTime: errStr = "GrabInvalidTime"; break; + default: + errStr = "Unknown"; + break; + } + + DEBUG_ERROR("XIGrabDevice failed for %s dev %d with 0x%x (%s)", + type, dev, ret, errStr); + +} + static void x11GrabPointer(void) { if (x11.pointerGrabbed) @@ -589,7 +608,7 @@ static void x11GrabPointer(void) XISetMask(mask.mask, XI_RawMotion ); XISetMask(mask.mask, XI_Motion ); - XIGrabDevice( + Status ret = XIGrabDevice( x11.display, x11.pointerDev, x11.window, @@ -600,6 +619,12 @@ static void x11GrabPointer(void) false, &mask); + if (ret != Success) + { + x11PrintGrabError("pointer", x11.pointerDev, ret); + return; + } + XSync(x11.display, False); x11.pointerGrabbed = true; @@ -631,7 +656,7 @@ static void x11GrabKeyboard(void) XISetMask(mask.mask, XI_RawKeyPress ); XISetMask(mask.mask, XI_RawKeyRelease); - XIGrabDevice( + Status ret = XIGrabDevice( x11.display, x11.keyboardDev, x11.window, @@ -642,6 +667,12 @@ static void x11GrabKeyboard(void) false, &mask); + if (ret != Success) + { + x11PrintGrabError("keyboard", x11.keyboardDev, ret); + return; + } + XSync(x11.display, False); x11.keyboardGrabbed = true;