2 * event.c - event handlers
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <xcb/randr.h>
24 #include <xcb/xcb_atom.h>
25 #include <xcb/xcb_icccm.h>
26 #include <xcb/xcb_event.h>
37 #include "keygrabber.h"
38 #include "mousegrabber.h"
42 #include "common/atoms.h"
43 #include "common/xutil.h"
45 #define DO_EVENT_HOOK_CALLBACK(type, xcbtype, xcbeventprefix, arraytype, match) \
47 event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
53 int abs_oud = oud < 0 ? ((lua_gettop(globalconf.L) + 1) + oud) : oud; \
54 int item_matching = 0; \
56 if(match(ev, *item, data)) \
59 luaA_object_push_item(globalconf.L, abs_oud, *item); \
61 luaA_object_push(globalconf.L, *item); \
64 for(; item_matching > 0; item_matching--) \
66 switch(ev->response_type) \
68 case xcbeventprefix##_PRESS: \
69 for(int i = 0; i < nargs; i++) \
70 lua_pushvalue(globalconf.L, - nargs - item_matching); \
71 luaA_object_emit_signal(globalconf.L, - nargs - 1, "press", nargs); \
73 case xcbeventprefix##_RELEASE: \
74 for(int i = 0; i < nargs; i++) \
75 lua_pushvalue(globalconf.L, - nargs - item_matching); \
76 luaA_object_emit_signal(globalconf.L, - nargs - 1, "release", nargs); \
79 lua_pop(globalconf.L, 1); \
81 lua_pop(globalconf.L, nargs); \
85 event_key_match(xcb_key_press_event_t
*ev
, keyb_t
*k
, void *data
)
88 xcb_keysym_t keysym
= *(xcb_keysym_t
*) data
;
89 return (((k
->keycode
&& ev
->detail
== k
->keycode
)
90 || (k
->keysym
&& keysym
== k
->keysym
))
91 && (k
->modifiers
== XCB_BUTTON_MASK_ANY
|| k
->modifiers
== ev
->state
));
95 event_button_match(xcb_button_press_event_t
*ev
, button_t
*b
, void *data
)
97 return ((!b
->button
|| ev
->detail
== b
->button
)
98 && (b
->modifiers
== XCB_BUTTON_MASK_ANY
|| b
->modifiers
== ev
->state
));
101 DO_EVENT_HOOK_CALLBACK(button_t
, button
, XCB_BUTTON
, button_array_t
, event_button_match
)
102 DO_EVENT_HOOK_CALLBACK(keyb_t
, key
, XCB_KEY
, key_array_t
, event_key_match
)
104 /** Handle an event with mouse grabber if needed
105 * \param x The x coordinate.
106 * \param y The y coordinate.
107 * \param mask The mask buttons.
108 * \return True if the event was handled.
111 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
113 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
115 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
116 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
117 if(lua_pcall(globalconf
.L
, 1, 1, 0))
119 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
120 luaA_mousegrabber_stop(globalconf
.L
);
122 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
123 luaA_mousegrabber_stop(globalconf
.L
);
124 lua_pop(globalconf
.L
, 1); /* pop returned value */
130 /** The button press event handler.
131 * \param data The type of mouse event.
132 * \param connection The connection to the X server.
133 * \param ev The event.
136 event_handle_button(void *data
, xcb_connection_t
*connection
, xcb_button_press_event_t
*ev
)
139 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(connection
));
143 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, 1 << (ev
->detail
- 1 + 8)))
147 * button status (8 bits) + modifiers status (8 bits)
148 * we don't care for button status that we get, especially on release, so
152 if((wibox
= wibox_getbywin(ev
->event
))
153 || (wibox
= wibox_getbywin(ev
->child
)))
155 /* If the wibox is child, then x,y are
156 * relative to root window */
157 if(wibox
->window
== ev
->child
)
159 ev
->event_x
-= wibox
->geometry
.x
;
160 ev
->event_y
-= wibox
->geometry
.y
;
163 luaA_object_push(globalconf
.L
, wibox
);
164 event_button_callback(ev
, &wibox
->buttons
, -1, 1, NULL
);
166 /* then try to match a widget binding */
167 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
168 wibox
->geometry
.width
,
169 wibox
->geometry
.height
,
170 &ev
->event_x
, &ev
->event_y
);
173 luaA_object_push(globalconf
.L
, w
);
174 luaA_object_push(globalconf
.L
, wibox
);
175 event_button_callback(ev
, &w
->buttons
, -2, 2, NULL
);
178 else if((c
= client_getbywin(ev
->event
)))
180 luaA_object_push(globalconf
.L
, c
);
181 event_button_callback(ev
, &c
->buttons
, -1, 1, NULL
);
182 xcb_allow_events(globalconf
.connection
,
183 XCB_ALLOW_REPLAY_POINTER
,
186 else if(ev
->child
== XCB_NONE
)
187 for(screen
= 0; screen
< nb_screen
; screen
++)
188 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
190 event_button_callback(ev
, &globalconf
.buttons
, 0, 0, NULL
);
198 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
200 uint16_t config_win_mask
= 0;
201 uint32_t config_win_vals
[7];
202 unsigned short i
= 0;
204 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
206 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
207 config_win_vals
[i
++] = ev
->x
;
209 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
211 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
212 config_win_vals
[i
++] = ev
->y
;
214 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
216 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
217 config_win_vals
[i
++] = ev
->width
;
219 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
221 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
222 config_win_vals
[i
++] = ev
->height
;
224 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
226 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
227 config_win_vals
[i
++] = ev
->border_width
;
229 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
231 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
232 config_win_vals
[i
++] = ev
->sibling
;
234 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
236 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
237 config_win_vals
[i
++] = ev
->stack_mode
;
240 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
243 /** The configure event handler.
244 * \param data currently unused.
245 * \param connection The connection to the X server.
246 * \param ev The event.
249 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
250 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
255 if((c
= client_getbywin(ev
->window
)))
257 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border_width
, c
->geometry
);
259 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
261 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
263 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
264 geometry
.width
= ev
->width
;
265 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
266 geometry
.height
= ev
->height
;
268 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
270 luaA_object_push(globalconf
.L
, c
);
271 client_set_border_width(globalconf
.L
, -1, ev
->border_width
);
272 lua_pop(globalconf
.L
, 1);
275 /* Clients are not allowed to directly mess with stacking parameters. */
276 ev
->value_mask
&= ~(XCB_CONFIG_WINDOW_SIBLING
|
277 XCB_CONFIG_WINDOW_STACK_MODE
);
279 /** Configure request are sent with size relative to real (internal)
280 * window size, i.e. without titlebars and borders. */
281 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border_width
, geometry
);
283 if(!client_resize(c
, geometry
, false))
285 /* Resize wasn't officially needed, but we don't want to break expectations. */
286 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border_width
, c
->geometry
);
287 window_configure(c
->window
, geometry
, c
->border_width
);
291 event_handle_configurerequest_configure_window(ev
);
296 /** The configure notify event handler.
297 * \param data currently unused.
298 * \param connection The connection to the X server.
299 * \param ev The event.
302 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
303 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
306 const xcb_screen_t
*screen
;
308 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
309 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
310 && ev
->window
== screen
->root
311 && (ev
->width
!= screen
->width_in_pixels
312 || ev
->height
!= screen
->height_in_pixels
))
313 /* it's not that we panic, but restart */
319 /** The destroy notify event handler.
320 * \param data currently unused.
321 * \param connection The connection to the X server.
322 * \param ev The event.
325 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
326 xcb_connection_t
*connection
__attribute__ ((unused
)),
327 xcb_destroy_notify_event_t
*ev
)
331 if((c
= client_getbywin(ev
->window
)))
334 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
335 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
337 xembed_window_array_take(&globalconf
.embedded
, i
);
338 widget_invalidate_bytype(widget_systray
);
344 /** Handle a motion notify over widgets.
345 * \param object The object.
346 * \param mouse_over The pointer to the registered mouse over widget.
347 * \param widget The new widget the mouse is over.
350 event_handle_widget_motionnotify(void *object
,
351 widget_t
**mouse_over
,
354 if(widget
!= *mouse_over
)
358 /* call mouse leave function on old widget */
359 luaA_object_push(globalconf
.L
, *mouse_over
);
360 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
361 lua_pop(globalconf
.L
, 1);
365 /* emit mouse::enter signal on new widget and register it */
366 *mouse_over
= widget
;
367 luaA_object_push(globalconf
.L
, widget
);
368 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
369 lua_pop(globalconf
.L
, 1);
374 /** The motion notify event handler.
375 * \param data currently unused.
376 * \param connection The connection to the X server.
377 * \param ev The event.
380 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
381 xcb_connection_t
*connection
,
382 xcb_motion_notify_event_t
*ev
)
386 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
389 if((wibox
= wibox_getbywin(ev
->event
)))
391 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
392 wibox
->geometry
.width
,
393 wibox
->geometry
.height
,
394 &ev
->event_x
, &ev
->event_y
);
396 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
402 /** The leave notify event handler.
403 * \param data currently unused.
404 * \param connection The connection to the X server.
405 * \param ev The event.
408 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
409 xcb_connection_t
*connection
,
410 xcb_leave_notify_event_t
*ev
)
415 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
418 if((c
= client_getbytitlebarwin(ev
->event
)) || (c
= client_getbywin(ev
->event
)))
420 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
422 luaA_object_push(globalconf
.L
, c
);
423 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
425 luaA_object_push(globalconf
.L
, c
);
426 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
427 lua_pop(globalconf
.L
, 1);
430 if((wibox
= wibox_getbywin(ev
->event
)))
432 if(wibox
->mouse_over
)
434 luaA_object_push(globalconf
.L
, wibox
->mouse_over
);
435 /* emit mouse::leave signal on widget the mouse was over */
436 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
437 lua_pop(globalconf
.L
, 1);
438 wibox
->mouse_over
= NULL
;
441 luaA_object_push(globalconf
.L
, wibox
);
442 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
443 lua_pop(globalconf
.L
, 1);
449 /** The enter notify event handler.
450 * \param data currently unused.
451 * \param connection The connection to the X server.
452 * \param ev The event.
455 event_handle_enternotify(void *data
__attribute__ ((unused
)),
456 xcb_connection_t
*connection
,
457 xcb_enter_notify_event_t
*ev
)
462 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
465 if((wibox
= wibox_getbywin(ev
->event
)))
467 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
468 wibox
->geometry
.width
,
469 wibox
->geometry
.height
,
470 &ev
->event_x
, &ev
->event_y
);
472 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
474 luaA_object_push(globalconf
.L
, wibox
);
475 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
476 lua_pop(globalconf
.L
, 1);
479 if((c
= client_getbytitlebarwin(ev
->event
))
480 || (c
= client_getbywin(ev
->event
)))
482 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
484 luaA_object_push(globalconf
.L
, c
);
485 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
487 luaA_object_push(globalconf
.L
, c
);
488 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
489 lua_pop(globalconf
.L
, 1);
495 /** The focus in event handler.
496 * \param data currently unused.
497 * \param connection The connection to the X server.
498 * \param ev The event.
501 event_handle_focusin(void *data
__attribute__ ((unused
)),
502 xcb_connection_t
*connection
,
503 xcb_focus_in_event_t
*ev
)
507 /* Events that we are interested in: */
510 /* These are events that jump between root windows.
512 case XCB_NOTIFY_DETAIL_ANCESTOR
:
513 case XCB_NOTIFY_DETAIL_INFERIOR
:
515 /* These are events that jump between clients.
516 * Virtual events ensure we always get an event on our top-level window.
518 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
519 case XCB_NOTIFY_DETAIL_NONLINEAR
:
520 if((c
= client_getbytitlebarwin(ev
->event
))
521 || (c
= client_getbywin(ev
->event
)))
522 client_focus_update(c
);
523 /* all other events are ignored */
530 /** The expose event handler.
531 * \param data currently unused.
532 * \param connection The connection to the X server.
533 * \param ev The event.
536 event_handle_expose(void *data
__attribute__ ((unused
)),
537 xcb_connection_t
*connection
__attribute__ ((unused
)),
538 xcb_expose_event_t
*ev
)
542 /* If the wibox got need_update set, skip this because it will be repainted
543 * soon anyway. Without this we could be painting garbage to the screen!
545 if((wibox
= wibox_getbywin(ev
->window
)) && !wibox
->need_update
)
546 wibox_refresh_pixmap_partial(wibox
,
548 ev
->width
, ev
->height
);
553 /** The key press event handler.
554 * \param data currently unused.
555 * \param connection The connection to the X server.
556 * \param ev The event.
559 event_handle_key(void *data
__attribute__ ((unused
)),
560 xcb_connection_t
*connection
__attribute__ ((unused
)),
561 xcb_key_press_event_t
*ev
)
563 if(globalconf
.keygrabber
!= LUA_REFNIL
)
565 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
566 if(keygrabber_handlekpress(globalconf
.L
, ev
))
568 if(lua_pcall(globalconf
.L
, 3, 1, 0))
570 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
571 luaA_keygrabber_stop(globalconf
.L
);
573 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
574 luaA_keygrabber_stop(globalconf
.L
);
576 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
580 /* get keysym ignoring all modifiers */
581 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
583 if((c
= client_getbywin(ev
->event
)))
585 luaA_object_push(globalconf
.L
, c
);
586 event_key_callback(ev
, &c
->keys
, -1, 1, &keysym
);
589 event_key_callback(ev
, &globalconf
.keys
, 0, 0, &keysym
);
595 /** The map request event handler.
596 * \param data currently unused.
597 * \param connection The connection to the X server.
598 * \param ev The event.
601 event_handle_maprequest(void *data
__attribute__ ((unused
)),
602 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
604 int phys_screen
, ret
= 0;
606 xcb_get_window_attributes_cookie_t wa_c
;
607 xcb_get_window_attributes_reply_t
*wa_r
;
608 xcb_get_geometry_cookie_t geom_c
;
609 xcb_get_geometry_reply_t
*geom_r
;
611 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
613 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
616 if(wa_r
->override_redirect
)
619 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
621 xcb_map_window(connection
, ev
->window
);
622 xembed_window_activate(connection
, ev
->window
);
624 else if((c
= client_getbywin(ev
->window
)))
626 /* Check that it may be visible, but not asked to be hidden */
627 if(client_maybevisible(c
, c
->screen
) && !c
->hidden
)
629 luaA_object_push(globalconf
.L
, c
);
630 client_set_minimized(globalconf
.L
, -1, false);
631 lua_pop(globalconf
.L
, 1);
632 /* it will be raised, so just update ourself */
638 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
640 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
646 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
648 client_manage(ev
->window
, geom_r
, phys_screen
, false);
658 /** The unmap notify event handler.
659 * \param data currently unused.
660 * \param connection The connection to the X server.
661 * \param ev The event.
664 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
665 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
669 if((c
= client_getbywin(ev
->window
)))
671 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
672 && XCB_EVENT_SENT(ev
)
673 && window_state_get_reply(window_state_get_unchecked(c
->window
)) == XCB_WM_STATE_NORMAL
)
677 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
678 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
680 xembed_window_array_take(&globalconf
.embedded
, i
);
681 widget_invalidate_bytype(widget_systray
);
687 /** The randr screen change notify event handler.
688 * \param data currently unused.
689 * \param connection The connection to the X server.
690 * \param ev The event.
693 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
694 xcb_connection_t
*connection
__attribute__ ((unused
)),
695 xcb_randr_screen_change_notify_event_t
*ev
)
697 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
698 * (only the code relevant to RRScreenChangeNotify) as the latter
699 * doesn't provide this kind of function */
700 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
701 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
702 ev
->mheight
, ev
->mwidth
);
704 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
705 ev
->mwidth
, ev
->mheight
);
707 /* XRRUpdateConfiguration also executes the following instruction
708 * but it's not useful because SubpixelOrder is not used at all at
711 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
719 /** The client message event handler.
720 * \param data currently unused.
721 * \param connection The connection to the X server.
722 * \param ev The event.
725 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
726 xcb_connection_t
*connection
,
727 xcb_client_message_event_t
*ev
)
729 /* check for startup notification messages */
730 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
733 if(ev
->type
== WM_CHANGE_STATE
)
736 if((c
= client_getbywin(ev
->window
))
738 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
740 luaA_object_push(globalconf
.L
, c
);
741 client_set_minimized(globalconf
.L
, -1, true);
742 lua_pop(globalconf
.L
, 1);
745 else if(ev
->type
== _XEMBED
)
746 return xembed_process_client_message(ev
);
747 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
748 return systray_process_client_message(ev
);
749 return ewmh_process_client_message(ev
);
752 /** The keymap change notify event handler.
753 * \param data Unused data.
754 * \param connection The connection to the X server.
755 * \param ev The event.
756 * \return Status code, 0 if everything's fine.
759 event_handle_mappingnotify(void *data
,
760 xcb_connection_t
*connection
,
761 xcb_mapping_notify_event_t
*ev
)
763 if(ev
->request
== XCB_MAPPING_MODIFIER
764 || ev
->request
== XCB_MAPPING_KEYBOARD
)
766 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
767 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
769 /* Free and then allocate the key symbols */
770 xcb_key_symbols_free(globalconf
.keysyms
);
771 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
773 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
774 globalconf
.keysyms
, &globalconf
.numlockmask
,
775 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
776 &globalconf
.modeswitchmask
);
778 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
780 /* regrab everything */
781 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
783 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
784 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
785 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
786 window_grabkeys(s
->root
, &globalconf
.keys
);
789 foreach(_c
, globalconf
.clients
)
792 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->window
, XCB_BUTTON_MASK_ANY
);
793 window_grabkeys(c
->window
, &c
->keys
);
801 event_handle_reparentnotify(void *data
,
802 xcb_connection_t
*connection
,
803 xcb_reparent_notify_event_t
*ev
)
807 if((c
= client_getbywin(ev
->window
)))
813 void a_xcb_set_event_handlers(void)
815 const xcb_query_extension_reply_t
*randr_query
;
817 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
818 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
819 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
820 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
821 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
822 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
823 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
824 xcb_event_set_focus_in_handler(&globalconf
.evenths
, event_handle_focusin
, NULL
);
825 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
826 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
827 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
828 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
829 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
830 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
831 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
832 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
833 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
835 /* check for randr extension */
836 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
837 if(randr_query
->present
)
838 xcb_event_set_handler(&globalconf
.evenths
,
839 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
840 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
845 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80