3 #endif /* ifdef HAVE_CONFIG_H */
8 #include "ecore_private.h"
9 #include "ecore_x_private.h"
12 static int _ecore_x_error_handle(Display *d,
14 static int _ecore_x_io_error_handle(Display *d);
16 static void (*_error_func)(void *data) = NULL;
17 static void *_error_data = NULL;
18 static void (*_io_error_func)(void *data) = NULL;
19 static void *_io_error_data = NULL;
20 static int _error_request_code = 0;
21 static int _error_code = 0;
22 static Ecore_X_ID _error_resource_id = 0;
25 * Set the error handler.
26 * @param func The error handler function
27 * @param data The data to be passed to the handler function
29 * Set the X error handler function
32 ecore_x_error_handler_set(void (*func)(void *data),
36 _error_data = (void *)data;
40 * Set the I/O error handler.
41 * @param func The I/O error handler function
42 * @param data The data to be passed to the handler function
44 * Set the X I/O error handler function
47 ecore_x_io_error_handler_set(void (*func)(void *data),
50 _io_error_func = func;
51 _io_error_data = (void *)data;
55 * Get the request code that caused the error.
56 * @return The request code causing the X error
58 * Return the X request code that caused the last X error
61 ecore_x_error_request_get(void)
63 return _error_request_code;
67 * Get the error code from the error.
68 * @return The error code from the X error
70 * Return the error code from the last X error
72 //FIXME: Use Ecore_X_Error_Code type when 2.0 is released
74 ecore_x_error_code_get(void)
80 * Get the resource id that caused the error.
81 * @return The resource id causing the X error
83 * Return the X resource id that caused the last X error
86 ecore_x_error_resource_id_get(void)
88 return _error_resource_id;
92 _ecore_x_error_handler_init(void)
94 XSetErrorHandler((XErrorHandler)_ecore_x_error_handle);
95 XSetIOErrorHandler((XIOErrorHandler)_ecore_x_io_error_handle);
99 _ecore_x_error_handle(Display *d,
102 if (!_ecore_xlib_sync) goto skip;
103 switch (ev->error_code)
105 case BadRequest: /* bad request code */
108 case BadValue: /* int parameter out of range */
111 case BadWindow: /* parameter not a Window */
114 case BadPixmap: /* parameter not a Pixmap */
117 case BadAtom: /* parameter not an Atom */
120 case BadCursor: /* parameter not a Cursor */
123 case BadFont: /* parameter not a Font */
126 case BadMatch: /* parameter mismatch */
129 case BadDrawable: /* parameter not a Pixmap or Window */
132 case BadAccess: /* depending on context */
135 case BadAlloc: /* insufficient resources */
138 case BadColor: /* no such colormap */
141 case BadGC: /* parameter not a GC */
144 case BadIDChoice: /* choice not in range or already used */
147 case BadName: /* font or color name doesn't exist */
150 case BadLength: /* Request length incorrect */
153 case BadImplementation: /* server is defective */
154 ERR("BadImplementation");
158 if (d == _ecore_x_disp)
160 _error_request_code = ev->request_code;
161 _error_code = ev->error_code;
162 _error_resource_id = ev->resourceid;
164 _error_func(_error_data);
170 _ecore_x_io_error_handle(Display *d)
172 if (d == _ecore_x_disp)
175 _io_error_func(_io_error_data);