1
#ifndef __XCB_EVENTS_H__
2
#define __XCB_EVENTS_H__
2
* Copyright (C) 2008 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.
30
* @defgroup xcb__event_t XCB Event Functions
32
* These functions ease the handling of X events received.
37
#ifndef __XCB_EVENT_H__
38
#define __XCB_EVENT_H__
4
40
#include <xcb/xcb.h>
12
typedef struct xcb_event_handlers_t xcb_event_handlers_t;
13
xcb_event_handlers_t *xcb_alloc_event_handlers(xcb_connection_t *c);
14
void xcb_free_event_handlers(xcb_event_handlers_t *evenths);
15
xcb_connection_t *xcb_get_xcb_connection(xcb_event_handlers_t *evenths);
17
void xcb_wait_for_event_loop(xcb_event_handlers_t *evenths);
18
void xcb_poll_for_event_loop(xcb_event_handlers_t *evenths);
19
int xcb_handle_event(xcb_event_handlers_t *evenths, xcb_generic_event_t *event);
47
* @brief Bit mask to find event type regardless of event source.
49
* Each event in the X11 protocol contains an 8-bit type code.
50
* The most-significant bit in this code is set if the event was
51
* generated from a SendEvent request. This mask can be used to
52
* determine the type of event regardless of how the event was
53
* generated. See the X11R6 protocol specification for details.
55
#define XCB_EVENT_RESPONSE_TYPE_MASK (0x7f)
56
#define XCB_EVENT_RESPONSE_TYPE(e) (e->response_type & XCB_EVENT_RESPONSE_TYPE_MASK)
57
#define XCB_EVENT_SENT(e) (e->response_type & ~XCB_EVENT_RESPONSE_TYPE_MASK)
21
59
typedef int (*xcb_generic_event_handler_t)(void *data, xcb_connection_t *c, xcb_generic_event_t *event);
22
60
typedef int (*xcb_generic_error_handler_t)(void *data, xcb_connection_t *c, xcb_generic_error_t *error);
24
void xcb_set_event_handler(xcb_event_handlers_t *evenths, int event, xcb_generic_event_handler_t handler, void *data);
25
void xcb_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generic_error_handler_t handler, void *data);
27
#define MAKE_HANDLER(cls,lkind, ukind) \
28
static inline void set_##lkind##_##cls##_handler(xcb_event_handlers_t *evenths, int (*handler)(void *, xcb_connection_t *, xcb_##lkind##_##cls##_t *), void *data) \
62
typedef struct xcb_event_handler xcb_event_handler_t;
63
struct xcb_event_handler
65
xcb_generic_event_handler_t handler;
69
typedef struct xcb_event_handlers xcb_event_handlers_t;
70
struct xcb_event_handlers
72
xcb_event_handler_t event[126];
73
xcb_event_handler_t error[256];
78
* @brief Initialize event handlers data structure.
79
* @param c The connection to the X server.
80
* @param evenths A pointer to the event handler data structure to initialize.
82
void xcb_event_handlers_init(xcb_connection_t *c, xcb_event_handlers_t *evenths);
85
* @brief Get X connection used in event handlers.
86
* @param evenths The event handlers.
87
* @return The connection to the X server.
89
xcb_connection_t *xcb_event_get_xcb_connection(xcb_event_handlers_t *evenths);
92
* @brief Wait for event and handle it with event handler.
93
* @param evenths The event handlers.
95
void xcb_event_wait_for_event_loop(xcb_event_handlers_t *evenths);
98
* @brief Poll for event and handle it with event handler.
99
* @param evenths The event handlers.
101
void xcb_event_poll_for_event_loop(xcb_event_handlers_t *evenths);
104
* @brief Handle an event using event handlers from event handlers data
106
* @param evenths The event handlers.
107
* @param event The event to handle.
108
* @return The return value of the handler, or 0 if no handler exists for this
111
int xcb_event_handle(xcb_event_handlers_t *evenths, xcb_generic_event_t *event);
114
* @brief Set an event handler for an event type.
115
* @param evenths The event handlers data structure.
116
* @param event The event type.
117
* @param handler The callback function to call for this event type.
118
* @param data Optional data pointer to pass to handler callback function.
120
void xcb_event_set_handler(xcb_event_handlers_t *evenths, int event, xcb_generic_event_handler_t handler, void *data);
123
* @brief Set an error handler for an error type.
124
* @param evenths The error handlers data structure.
125
* @param error The error type.
126
* @param handler The callback function to call for this error type.
127
* @param data Optional data pointer to pass to handler callback function.
129
void xcb_event_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generic_error_handler_t handler, void *data);
131
#define XCB_EVENT_MAKE_EVENT_HANDLER(lkind, ukind) \
132
static inline void xcb_event_set_##lkind##_handler(xcb_event_handlers_t *evenths, int (*handler)(void *, xcb_connection_t *, xcb_##lkind##_event_t *), void *data) \
30
xcb_set_##cls##_handler(evenths, XCB_##ukind, (xcb_generic_event_handler_t) handler, data); \
134
xcb_event_set_handler(evenths, XCB_##ukind, (xcb_generic_event_handler_t) handler, data); \
33
MAKE_HANDLER(event, key_press, KEY_PRESS)
34
MAKE_HANDLER(event, key_release, KEY_RELEASE)
35
MAKE_HANDLER(event, button_press, BUTTON_PRESS)
36
MAKE_HANDLER(event, button_release, BUTTON_RELEASE)
37
MAKE_HANDLER(event, motion_notify, MOTION_NOTIFY)
38
MAKE_HANDLER(event, enter_notify, ENTER_NOTIFY)
39
MAKE_HANDLER(event, leave_notify, LEAVE_NOTIFY)
40
MAKE_HANDLER(event, focus_in, FOCUS_IN)
41
MAKE_HANDLER(event, focus_out, FOCUS_OUT)
42
MAKE_HANDLER(event, keymap_notify, KEYMAP_NOTIFY)
43
MAKE_HANDLER(event, expose, EXPOSE)
44
MAKE_HANDLER(event, graphics_exposure, GRAPHICS_EXPOSURE)
45
MAKE_HANDLER(event, no_exposure, NO_EXPOSURE)
46
MAKE_HANDLER(event, visibility_notify, VISIBILITY_NOTIFY)
47
MAKE_HANDLER(event, create_notify, CREATE_NOTIFY)
48
MAKE_HANDLER(event, destroy_notify, DESTROY_NOTIFY)
49
MAKE_HANDLER(event, unmap_notify, UNMAP_NOTIFY)
50
MAKE_HANDLER(event, map_notify, MAP_NOTIFY)
51
MAKE_HANDLER(event, map_request, MAP_REQUEST)
52
MAKE_HANDLER(event, reparent_notify, REPARENT_NOTIFY)
53
MAKE_HANDLER(event, configure_notify, CONFIGURE_NOTIFY)
54
MAKE_HANDLER(event, configure_request, CONFIGURE_REQUEST)
55
MAKE_HANDLER(event, gravity_notify, GRAVITY_NOTIFY)
56
MAKE_HANDLER(event, resize_request, RESIZE_REQUEST)
57
MAKE_HANDLER(event, circulate_notify, CIRCULATE_NOTIFY)
58
MAKE_HANDLER(event, circulate_request, CIRCULATE_REQUEST)
59
MAKE_HANDLER(event, property_notify, PROPERTY_NOTIFY)
60
MAKE_HANDLER(event, selection_clear, SELECTION_CLEAR)
61
MAKE_HANDLER(event, selection_request, SELECTION_REQUEST)
62
MAKE_HANDLER(event, selection_notify, SELECTION_NOTIFY)
63
MAKE_HANDLER(event, colormap_notify, COLORMAP_NOTIFY)
64
MAKE_HANDLER(event, client_message, CLIENT_MESSAGE)
65
MAKE_HANDLER(event, mapping_notify, MAPPING_NOTIFY)
137
XCB_EVENT_MAKE_EVENT_HANDLER(key_press, KEY_PRESS)
138
XCB_EVENT_MAKE_EVENT_HANDLER(key_release, KEY_RELEASE)
139
XCB_EVENT_MAKE_EVENT_HANDLER(button_press, BUTTON_PRESS)
140
XCB_EVENT_MAKE_EVENT_HANDLER(button_release, BUTTON_RELEASE)
141
XCB_EVENT_MAKE_EVENT_HANDLER(motion_notify, MOTION_NOTIFY)
142
XCB_EVENT_MAKE_EVENT_HANDLER(enter_notify, ENTER_NOTIFY)
143
XCB_EVENT_MAKE_EVENT_HANDLER(leave_notify, LEAVE_NOTIFY)
144
XCB_EVENT_MAKE_EVENT_HANDLER(focus_in, FOCUS_IN)
145
XCB_EVENT_MAKE_EVENT_HANDLER(focus_out, FOCUS_OUT)
146
XCB_EVENT_MAKE_EVENT_HANDLER(keymap_notify, KEYMAP_NOTIFY)
147
XCB_EVENT_MAKE_EVENT_HANDLER(expose, EXPOSE)
148
XCB_EVENT_MAKE_EVENT_HANDLER(graphics_exposure, GRAPHICS_EXPOSURE)
149
XCB_EVENT_MAKE_EVENT_HANDLER(no_exposure, NO_EXPOSURE)
150
XCB_EVENT_MAKE_EVENT_HANDLER(visibility_notify, VISIBILITY_NOTIFY)
151
XCB_EVENT_MAKE_EVENT_HANDLER(create_notify, CREATE_NOTIFY)
152
XCB_EVENT_MAKE_EVENT_HANDLER(destroy_notify, DESTROY_NOTIFY)
153
XCB_EVENT_MAKE_EVENT_HANDLER(unmap_notify, UNMAP_NOTIFY)
154
XCB_EVENT_MAKE_EVENT_HANDLER(map_notify, MAP_NOTIFY)
155
XCB_EVENT_MAKE_EVENT_HANDLER(map_request, MAP_REQUEST)
156
XCB_EVENT_MAKE_EVENT_HANDLER(reparent_notify, REPARENT_NOTIFY)
157
XCB_EVENT_MAKE_EVENT_HANDLER(configure_notify, CONFIGURE_NOTIFY)
158
XCB_EVENT_MAKE_EVENT_HANDLER(configure_request, CONFIGURE_REQUEST)
159
XCB_EVENT_MAKE_EVENT_HANDLER(gravity_notify, GRAVITY_NOTIFY)
160
XCB_EVENT_MAKE_EVENT_HANDLER(resize_request, RESIZE_REQUEST)
161
XCB_EVENT_MAKE_EVENT_HANDLER(circulate_notify, CIRCULATE_NOTIFY)
162
XCB_EVENT_MAKE_EVENT_HANDLER(circulate_request, CIRCULATE_REQUEST)
163
XCB_EVENT_MAKE_EVENT_HANDLER(property_notify, PROPERTY_NOTIFY)
164
XCB_EVENT_MAKE_EVENT_HANDLER(selection_clear, SELECTION_CLEAR)
165
XCB_EVENT_MAKE_EVENT_HANDLER(selection_request, SELECTION_REQUEST)
166
XCB_EVENT_MAKE_EVENT_HANDLER(selection_notify, SELECTION_NOTIFY)
167
XCB_EVENT_MAKE_EVENT_HANDLER(colormap_notify, COLORMAP_NOTIFY)
168
XCB_EVENT_MAKE_EVENT_HANDLER(client_message, CLIENT_MESSAGE)
169
XCB_EVENT_MAKE_EVENT_HANDLER(mapping_notify, MAPPING_NOTIFY)
68
171
#ifdef __cplusplus
73
#endif /* __XCB_EVENTS_H__ */
179
#endif /* __XCB_EVENT_H__ */