XSetErrorHandler user data

Viewed 49

Hi I'm developing an application that uses XGrabKey to register global hotkey. I would like to use XSetErrorHandler to replace the default handler which exits program.
But I can't change the variables that are out of the scope of the handler function:

bool hasX11Error = false;
auto x11_error_handler = [&](Display* dpy, XErrorEvent* e) -> int
{
  hasX11Error = true;
  return 0;
};
XSetErrorHandler(x11_error_handler); // this line won't work, requires non-capture lambda

Is there anyway to pass user defined data to this function?
Or a boolean indicator of error event occurred?

Update
OK in my trivial case I just need to define a static boolean value:

static bool hasX11Error = false;
auto x11_error_handler = [](Display* dpy, XErrorEvent* e) -> int
{
  hasX11Error = true;
  return 0;
};
XSetErrorHandler(x11_error_handler);

Would be great if there are any non-static methods.

0 Answers
Related