2 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Except as contained in this notice, the names of the authors or
24 * their institutions shall not be used in advertising or otherwise to
25 * promote the sale, use or other dealings in this Software without
26 * prior written authorization from the authors.
33 #include "xcb_event.h"
34 #include "../xcb-util-common.h"
37 xcb_event_handlers_init(xcb_connection_t *c, xcb_event_handlers_t *evenths)
39 memset(evenths, 0, sizeof(xcb_event_handlers_t));
44 xcb_event_get_xcb_connection(xcb_event_handlers_t *evenths)
49 static xcb_event_handler_t *
50 get_event_handler(xcb_event_handlers_t *evenths, int event)
53 event &= XCB_EVENT_RESPONSE_TYPE_MASK;
55 return &evenths->event[event - 2];
58 static xcb_event_handler_t *
59 get_error_handler(xcb_event_handlers_t *evenths, int error)
61 assert(error >= 0 && error < 256);
62 return &evenths->error[error];
66 xcb_event_handle(xcb_event_handlers_t *evenths, xcb_generic_event_t *event)
68 xcb_event_handler_t *eventh = 0;
69 assert(event->response_type != 1);
71 if(event->response_type == 0)
72 eventh = get_error_handler(evenths, ((xcb_generic_error_t *) event)->error_code);
74 eventh = get_event_handler(evenths, event->response_type);
77 return eventh->handler(eventh->data, evenths->c, event);
82 xcb_event_wait_for_event_loop(xcb_event_handlers_t *evenths)
84 xcb_generic_event_t *event;
85 while((event = xcb_wait_for_event(evenths->c)))
87 xcb_event_handle(evenths, event);
93 xcb_event_poll_for_event_loop(xcb_event_handlers_t *evenths)
95 xcb_generic_event_t *event;
96 while ((event = xcb_poll_for_event(evenths->c)))
98 xcb_event_handle(evenths, event);
104 set_handler(xcb_generic_event_handler_t handler, void *data, xcb_event_handler_t *place)
106 xcb_event_handler_t eventh = { handler, data };
111 xcb_event_set_handler(xcb_event_handlers_t *evenths, int event, xcb_generic_event_handler_t handler, void *data)
113 set_handler(handler, data, get_event_handler(evenths, event));
117 xcb_event_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generic_error_handler_t handler, void *data)
119 set_handler((xcb_generic_event_handler_t) handler, data, get_error_handler(evenths, error));
122 static const char *labelError[] =
144 static const char *labelRequest[] =
148 "ChangeWindowAttributes",
149 "GetWindowAttributes",
176 "ChangeActivePointerGrab",
226 "CopyColormapAndFree",
229 "ListInstalledColormaps",
246 "ChangeKeyboardMapping",
247 "GetKeyboardMapping",
248 "ChangeKeyboardControl",
249 "GetKeyboardControl",
251 "ChangePointerControl",
264 "SetModifierMapping",
265 "GetModifierMapping",
276 static const char *labelEvent[] =
316 xcb_event_get_label(uint8_t type)
318 if(type < countof(labelEvent))
319 return labelEvent[type];
324 xcb_event_get_error_label(uint8_t type)
326 if(type < countof(labelError))
327 return labelError[type];
332 xcb_event_get_request_label(uint8_t type)
334 if(type < countof(labelRequest))
335 return labelRequest[type];