2 * x11misc.c: miscellaneous stuff for dealing directly with X servers.
16 #include <X11/Xutil.h>
17 #include <X11/Xatom.h>
21 /* ----------------------------------------------------------------------
22 * Error handling mechanism which permits us to ignore specific X11
23 * errors from particular requests. We maintain a list of upcoming
24 * potential error events that we want to not treat as fatal errors.
27 static int (*orig_x11_error_handler)(Display *thisdisp, XErrorEvent *err);
29 struct x11_err_to_ignore {
31 unsigned char error_code;
35 struct x11_err_to_ignore *errs;
39 static int x11_error_handler(Display *thisdisp, XErrorEvent *err)
42 for (i = 0; i < nerrs; i++) {
43 if (thisdisp == errs[i].display &&
44 err->serial == errs[i].serial &&
45 err->error_code == errs[i].error_code) {
46 /* Ok, this is an error we're happy to ignore */
51 return (*orig_x11_error_handler)(thisdisp, err);
54 void x11_ignore_error(Display *disp, unsigned char errcode)
57 * Install our error handler, if we haven't already.
59 if (!orig_x11_error_handler)
60 orig_x11_error_handler = XSetErrorHandler(x11_error_handler);
63 * This is as good a moment as any to winnow the ignore list based
64 * on requests we know to have been processed.
67 unsigned long last = LastKnownRequestProcessed(disp);
69 for (i = j = 0; i < nerrs; i++) {
70 if (errs[i].display == disp && errs[i].serial <= last)
77 if (nerrs >= errsize) {
78 errsize = nerrs * 5 / 4 + 16;
79 errs = sresize(errs, errsize, struct x11_err_to_ignore);
81 errs[nerrs].display = disp;
82 errs[nerrs].error_code = errcode;
83 errs[nerrs].serial = NextRequest(disp);