xglcomp
diff src/xerr.cc @ 12:1c0d056ec360
moving slowly
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 05 Feb 2016 03:33:18 +0200 |
parents | cb636a23f4f2 |
children |
line diff
1.1 --- a/src/xerr.cc Thu Feb 04 04:15:15 2016 +0200 1.2 +++ b/src/xerr.cc Fri Feb 05 03:33:18 2016 +0200 1.3 @@ -6,14 +6,17 @@ 1.4 #include "xerr.h" 1.5 #include "logger.h" 1.6 1.7 -static int _XPrintDefaultError( Display *dpy, XErrorEvent *event, FILE *fp); 1.8 +static int _XPrintDefaultError( Display *dpy, XErrorEvent *event); 1.9 1.10 static std::stack<xerr_handler_type> func_stack; 1.11 1.12 void push_xerr_handler(xerr_handler_type func) 1.13 { 1.14 + xerr_handler_type prev = XSetErrorHandler(func); 1.15 + if(func_stack.empty()) { 1.16 + func_stack.push(prev); 1.17 + } 1.18 func_stack.push(func); 1.19 - XSetErrorHandler(func); 1.20 } 1.21 1.22 void pop_xerr_handler() 1.23 @@ -29,7 +32,7 @@ 1.24 1.25 int xerr_debug(Display *dpy, XErrorEvent *err) 1.26 { 1.27 - _XPrintDefaultError(dpy, err, stderr); 1.28 + _XPrintDefaultError(dpy, err); 1.29 return 0; 1.30 } 1.31 1.32 @@ -40,7 +43,7 @@ 1.33 1.34 typedef struct _XExten _XExtension; 1.35 1.36 -static int _XPrintDefaultError( Display *dpy, XErrorEvent *event, FILE *fp) 1.37 +static int _XPrintDefaultError(Display *dpy, XErrorEvent *event) 1.38 { 1.39 char buffer[BUFSIZ]; 1.40 char mesg[BUFSIZ]; 1.41 @@ -51,10 +54,10 @@ 1.42 1.43 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); 1.44 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); 1.45 - (void) fprintf(fp, "%s: %s\n ", mesg, buffer); 1.46 + log_error("%s: %s\n ", mesg, buffer); 1.47 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", 1.48 mesg, BUFSIZ); 1.49 - (void) fprintf(fp, mesg, event->request_code); 1.50 + log_error(mesg, event->request_code); 1.51 if (event->request_code < 128) { 1.52 sprintf(number, "%d", event->request_code); 1.53 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 1.54 @@ -69,18 +72,18 @@ 1.55 } else 1.56 buffer[0] = '\0'; 1.57 } 1.58 - (void) fprintf(fp, " (%s)\n", buffer); 1.59 + log_error(" (%s)\n", buffer); 1.60 if (event->request_code >= 128) { 1.61 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 1.62 mesg, BUFSIZ); 1.63 - fputs(" ", fp); 1.64 - (void) fprintf(fp, mesg, event->minor_code); 1.65 + log_error(" "); 1.66 + log_error(mesg, event->minor_code); 1.67 if (ext) { 1.68 sprintf(mesg, "%s.%d", ext->name, event->minor_code); 1.69 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); 1.70 - (void) fprintf(fp, " (%s)", buffer); 1.71 + log_error(" (%s)", buffer); 1.72 } 1.73 - fputs("\n", fp); 1.74 + log_error("\n"); 1.75 } 1.76 if (event->error_code >= 128) { 1.77 /* kludge, try to find the extension that caused it */ 1.78 @@ -105,14 +108,14 @@ 1.79 strcpy(buffer, "Value"); 1.80 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); 1.81 if (mesg[0]) { 1.82 - fputs(" ", fp); 1.83 - (void) fprintf(fp, mesg, event->resourceid); 1.84 - fputs("\n", fp); 1.85 + log_error(" "); 1.86 + log_error(mesg, event->resourceid); 1.87 + log_error("\n"); 1.88 } 1.89 /* let extensions try to print the values */ 1.90 for (ext = dpy->ext_procs; ext; ext = ext->next) { 1.91 if (ext->error_values) 1.92 - (*ext->error_values)(dpy, event, fp); 1.93 + (*ext->error_values)(dpy, event, stderr); 1.94 } 1.95 } else if ((event->error_code == BadWindow) || 1.96 (event->error_code == BadPixmap) || 1.97 @@ -133,19 +136,19 @@ 1.98 else 1.99 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 1.100 mesg, BUFSIZ); 1.101 - fputs(" ", fp); 1.102 - (void) fprintf(fp, mesg, event->resourceid); 1.103 - fputs("\n", fp); 1.104 + log_error(" "); 1.105 + log_error(mesg, event->resourceid); 1.106 + log_error("\n"); 1.107 } 1.108 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", 1.109 mesg, BUFSIZ); 1.110 - fputs(" ", fp); 1.111 - (void) fprintf(fp, mesg, event->serial); 1.112 + log_error(" "); 1.113 + log_error(mesg, event->serial); 1.114 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", 1.115 mesg, BUFSIZ); 1.116 - fputs("\n ", fp); 1.117 - (void) fprintf(fp, mesg, dpy->request); 1.118 - fputs("\n", fp); 1.119 + log_error("\n "); 1.120 + log_error(mesg, dpy->request); 1.121 + log_error("\n"); 1.122 if (event->error_code == BadImplementation) return 0; 1.123 return 1; 1.124 }