blob: 837ff535448d36b4cd9acdf68a78ac06b2c84899 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */
#include <stdlib.h>
#include "Ecore.h"
#include "ecore_private.h"
#include "ecore_x_private.h"
#include "Ecore_X.h"
static int _ecore_x_error_handle(Display *d,
XErrorEvent *ev);
static int _ecore_x_io_error_handle(Display *d);
static void (*_error_func)(void *data) = NULL;
static void *_error_data = NULL;
static void (*_io_error_func)(void *data) = NULL;
static void *_io_error_data = NULL;
static int _error_request_code = 0;
static int _error_code = 0;
/**
* Set the error handler.
* @param func The error handler function
* @param data The data to be passed to the handler function
*
* Set the X error handler function
*/
EAPI void
ecore_x_error_handler_set(void (*func)(void *data),
const void *data)
{
_error_func = func;
_error_data = (void *)data;
} /* ecore_x_error_handler_set */
/**
* 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
*
* Set the X I/O error handler function
*/
EAPI void
ecore_x_io_error_handler_set(void (*func)(void *data),
const void *data)
{
_io_error_func = func;
_io_error_data = (void *)data;
} /* ecore_x_io_error_handler_set */
/**
* Get the request code that caused the error.
* @return The request code causing the X error
*
* Return the X request code that caused the last X error
*/
EAPI int
ecore_x_error_request_get(void)
{
return _error_request_code;
} /* ecore_x_error_request_get */
/**
* Get the error code from the error.
* @return The error code from the X error
*
* Return the error code from the last X error
*/
EAPI int
ecore_x_error_code_get(void)
{
return _error_code;
} /* ecore_x_error_code_get */
void
_ecore_x_error_handler_init(void)
{
XSetErrorHandler((XErrorHandler)_ecore_x_error_handle);
XSetIOErrorHandler((XIOErrorHandler)_ecore_x_io_error_handle);
} /* _ecore_x_error_handler_init */
static int
_ecore_x_error_handle(Display *d,
XErrorEvent *ev)
{
if (d == _ecore_x_disp)
{
_error_request_code = ev->request_code;
_error_code = ev->error_code;
if (_error_func)
_error_func(_error_data);
}
return 0;
} /* _ecore_x_error_handle */
static int
_ecore_x_io_error_handle(Display *d)
{
if (d == _ecore_x_disp)
{
if (_io_error_func)
_io_error_func(_io_error_data);
else
exit(-1);
}
return 0;
} /* _ecore_x_io_error_handle */
|