2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef HAVE_CONFIG_H */
|
2009-01-31 10:33:39 -08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
#include "Ecore.h"
|
2009-12-22 13:15:12 -08:00
|
|
|
#include "ecore_private.h"
|
2003-09-23 01:09:32 -07:00
|
|
|
#include "ecore_x_private.h"
|
|
|
|
#include "Ecore_X.h"
|
|
|
|
|
2011-12-03 12:05:48 -08:00
|
|
|
static int _ecore_x_error_handle(Display *d,
|
2011-10-20 22:40:59 -07:00
|
|
|
XErrorEvent *ev);
|
|
|
|
static int _ecore_x_io_error_handle(Display *d);
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2010-07-27 22:23:42 -07:00
|
|
|
static void (*_error_func)(void *data) = NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
static void *_error_data = NULL;
|
2010-07-27 22:23:42 -07:00
|
|
|
static void (*_io_error_func)(void *data) = NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
static void *_io_error_data = NULL;
|
2010-07-27 22:23:42 -07:00
|
|
|
static int _error_request_code = 0;
|
|
|
|
static int _error_code = 0;
|
2011-12-12 23:30:01 -08:00
|
|
|
static Ecore_X_ID _error_resource_id = 0;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the error handler.
|
|
|
|
* @param func The error handler function
|
|
|
|
* @param data The data to be passed to the handler function
|
2010-07-27 22:23:42 -07:00
|
|
|
*
|
2003-09-23 01:09:32 -07:00
|
|
|
* Set the X error handler function
|
|
|
|
*/
|
2006-01-06 12:22:09 -08:00
|
|
|
EAPI void
|
2011-12-03 12:05:48 -08:00
|
|
|
ecore_x_error_handler_set(void (*func)(void *data),
|
2011-10-20 22:40:59 -07:00
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
_error_func = func;
|
|
|
|
_error_data = (void *)data;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the I/O error handler.
|
|
|
|
* @param func The I/O error handler function
|
|
|
|
* @param data The data to be passed to the handler function
|
2010-07-27 22:23:42 -07:00
|
|
|
*
|
2003-09-23 01:09:32 -07:00
|
|
|
* Set the X I/O error handler function
|
|
|
|
*/
|
2006-01-06 12:22:09 -08:00
|
|
|
EAPI void
|
2011-12-03 12:05:48 -08:00
|
|
|
ecore_x_io_error_handler_set(void (*func)(void *data),
|
2011-10-20 22:40:59 -07:00
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
_io_error_func = func;
|
|
|
|
_io_error_data = (void *)data;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the request code that caused the error.
|
|
|
|
* @return The request code causing the X error
|
2010-07-27 22:23:42 -07:00
|
|
|
*
|
2003-09-23 01:09:32 -07:00
|
|
|
* Return the X request code that caused the last X error
|
|
|
|
*/
|
2006-01-06 12:22:09 -08:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_x_error_request_get(void)
|
|
|
|
{
|
|
|
|
return _error_request_code;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the error code from the error.
|
|
|
|
* @return The error code from the X error
|
2010-07-27 22:23:42 -07:00
|
|
|
*
|
2003-09-23 01:09:32 -07:00
|
|
|
* Return the error code from the last X error
|
|
|
|
*/
|
2012-07-06 23:29:29 -07:00
|
|
|
//FIXME: Use Ecore_X_Error_Code type when 2.0 is released
|
2012-05-28 19:42:13 -07:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_x_error_code_get(void)
|
|
|
|
{
|
|
|
|
return _error_code;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2011-12-12 23:30:01 -08:00
|
|
|
/**
|
|
|
|
* Get the resource id that caused the error.
|
|
|
|
* @return The resource id causing the X error
|
|
|
|
*
|
|
|
|
* Return the X resource id that caused the last X error
|
|
|
|
*/
|
|
|
|
EAPI Ecore_X_ID
|
|
|
|
ecore_x_error_resource_id_get(void)
|
|
|
|
{
|
|
|
|
return _error_resource_id;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
void
|
|
|
|
_ecore_x_error_handler_init(void)
|
|
|
|
{
|
|
|
|
XSetErrorHandler((XErrorHandler)_ecore_x_error_handle);
|
2010-07-27 22:23:42 -07:00
|
|
|
XSetIOErrorHandler((XIOErrorHandler)_ecore_x_io_error_handle);
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2010-08-27 21:28:15 -07:00
|
|
|
static int
|
2011-12-03 12:05:48 -08:00
|
|
|
_ecore_x_error_handle(Display *d,
|
2011-10-20 22:40:59 -07:00
|
|
|
XErrorEvent *ev)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2013-08-25 09:15:19 -07:00
|
|
|
if (!_ecore_xlib_sync) goto skip;
|
2013-07-17 00:35:34 -07:00
|
|
|
switch (ev->error_code)
|
|
|
|
{
|
|
|
|
case BadRequest: /* bad request code */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadRequest");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadValue: /* int parameter out of range */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadValue");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadWindow: /* parameter not a Window */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadWindow");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadPixmap: /* parameter not a Pixmap */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadPixmap");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadAtom: /* parameter not an Atom */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadAtom");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadCursor: /* parameter not a Cursor */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadCursor");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadFont: /* parameter not a Font */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadFont");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadMatch: /* parameter mismatch */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadMatch");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadDrawable: /* parameter not a Pixmap or Window */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadDrawable");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadAccess: /* depending on context */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadAccess");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadAlloc: /* insufficient resources */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadAlloc");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadColor: /* no such colormap */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadColor");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadGC: /* parameter not a GC */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadGC");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadIDChoice: /* choice not in range or already used */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadIDChoice");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadName: /* font or color name doesn't exist */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadName");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadLength: /* Request length incorrect */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadLength");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
case BadImplementation: /* server is defective */
|
2013-07-19 01:02:33 -07:00
|
|
|
ERR("BadImplementation");
|
2013-07-17 00:35:34 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-08-25 09:15:19 -07:00
|
|
|
skip:
|
2010-07-27 22:23:42 -07:00
|
|
|
if (d == _ecore_x_disp)
|
2005-06-21 23:47:44 -07:00
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
_error_request_code = ev->request_code;
|
|
|
|
_error_code = ev->error_code;
|
2011-12-12 23:30:01 -08:00
|
|
|
_error_resource_id = ev->resourceid;
|
2010-07-27 22:23:42 -07:00
|
|
|
if (_error_func)
|
2011-10-20 22:40:59 -07:00
|
|
|
_error_func(_error_data);
|
2005-06-21 23:47:44 -07:00
|
|
|
}
|
2010-08-27 21:28:15 -07:00
|
|
|
return 0;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
static int
|
2005-06-21 23:47:44 -07:00
|
|
|
_ecore_x_io_error_handle(Display *d)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
if (d == _ecore_x_disp)
|
2005-06-21 23:47:44 -07:00
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
if (_io_error_func)
|
2011-10-20 22:40:59 -07:00
|
|
|
_io_error_func(_io_error_data);
|
2010-07-27 22:23:42 -07:00
|
|
|
else
|
2011-10-20 22:40:59 -07:00
|
|
|
exit(-1);
|
2005-06-21 23:47:44 -07:00
|
|
|
}
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return 0;
|
2011-12-03 11:41:12 -08:00
|
|
|
}
|
2010-08-02 10:47:49 -07:00
|
|
|
|