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((wibox
= wibox_getbywin(ev
->window
)))
543 wibox_refresh_pixmap_partial(wibox
,
545 ev
->width
, ev
->height
);
550 /** The key press event handler.
551 * \param data currently unused.
552 * \param connection The connection to the X server.
553 * \param ev The event.
556 event_handle_key(void *data
__attribute__ ((unused
)),
557 xcb_connection_t
*connection
__attribute__ ((unused
)),
558 xcb_key_press_event_t
*ev
)
560 if(globalconf
.keygrabber
!= LUA_REFNIL
)
562 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
563 if(keygrabber_handlekpress(globalconf
.L
, ev
))
565 if(lua_pcall(globalconf
.L
, 3, 1, 0))
567 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
568 luaA_keygrabber_stop(globalconf
.L
);
570 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
571 luaA_keygrabber_stop(globalconf
.L
);
573 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
577 /* get keysym ignoring all modifiers */
578 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
580 if((c
= client_getbywin(ev
->event
)))
582 luaA_object_push(globalconf
.L
, c
);
583 event_key_callback(ev
, &c
->keys
, -1, 1, &keysym
);
586 event_key_callback(ev
, &globalconf
.keys
, 0, 0, &keysym
);
592 /** The map request event handler.
593 * \param data currently unused.
594 * \param connection The connection to the X server.
595 * \param ev The event.
598 event_handle_maprequest(void *data
__attribute__ ((unused
)),
599 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
601 int phys_screen
, ret
= 0;
603 xcb_get_window_attributes_cookie_t wa_c
;
604 xcb_get_window_attributes_reply_t
*wa_r
;
605 xcb_get_geometry_cookie_t geom_c
;
606 xcb_get_geometry_reply_t
*geom_r
;
608 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
610 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
613 if(wa_r
->override_redirect
)
616 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
618 xcb_map_window(connection
, ev
->window
);
619 xembed_window_activate(connection
, ev
->window
);
621 else if((c
= client_getbywin(ev
->window
)))
623 /* Check that it may be visible, but not asked to be hidden */
624 if(client_maybevisible(c
, c
->screen
) && !c
->hidden
)
626 luaA_object_push(globalconf
.L
, c
);
627 client_set_minimized(globalconf
.L
, -1, false);
628 lua_pop(globalconf
.L
, 1);
629 /* it will be raised, so just update ourself */
635 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
637 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
643 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
645 client_manage(ev
->window
, geom_r
, phys_screen
, false);
655 /** The unmap notify event handler.
656 * \param data currently unused.
657 * \param connection The connection to the X server.
658 * \param ev The event.
661 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
662 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
666 if((c
= client_getbywin(ev
->window
)))
668 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
669 && XCB_EVENT_SENT(ev
)
670 && window_state_get_reply(window_state_get_unchecked(c
->window
)) == XCB_WM_STATE_NORMAL
)
674 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
675 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
677 xembed_window_array_take(&globalconf
.embedded
, i
);
678 widget_invalidate_bytype(widget_systray
);
684 /** The randr screen change notify event handler.
685 * \param data currently unused.
686 * \param connection The connection to the X server.
687 * \param ev The event.
690 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
691 xcb_connection_t
*connection
__attribute__ ((unused
)),
692 xcb_randr_screen_change_notify_event_t
*ev
)
694 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
695 * (only the code relevant to RRScreenChangeNotify) as the latter
696 * doesn't provide this kind of function */
697 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
698 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
699 ev
->mheight
, ev
->mwidth
);
701 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
702 ev
->mwidth
, ev
->mheight
);
704 /* XRRUpdateConfiguration also executes the following instruction
705 * but it's not useful because SubpixelOrder is not used at all at
708 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
716 /** The client message event handler.
717 * \param data currently unused.
718 * \param connection The connection to the X server.
719 * \param ev The event.
722 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
723 xcb_connection_t
*connection
,
724 xcb_client_message_event_t
*ev
)
726 /* check for startup notification messages */
727 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
730 if(ev
->type
== WM_CHANGE_STATE
)
733 if((c
= client_getbywin(ev
->window
))
735 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
737 luaA_object_push(globalconf
.L
, c
);
738 client_set_minimized(globalconf
.L
, -1, true);
739 lua_pop(globalconf
.L
, 1);
742 else if(ev
->type
== _XEMBED
)
743 return xembed_process_client_message(ev
);
744 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
745 return systray_process_client_message(ev
);
746 return ewmh_process_client_message(ev
);
749 /** The keymap change notify event handler.
750 * \param data Unused data.
751 * \param connection The connection to the X server.
752 * \param ev The event.
753 * \return Status code, 0 if everything's fine.
756 event_handle_mappingnotify(void *data
,
757 xcb_connection_t
*connection
,
758 xcb_mapping_notify_event_t
*ev
)
760 if(ev
->request
== XCB_MAPPING_MODIFIER
761 || ev
->request
== XCB_MAPPING_KEYBOARD
)
763 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
764 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
766 /* Free and then allocate the key symbols */
767 xcb_key_symbols_free(globalconf
.keysyms
);
768 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
770 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
771 globalconf
.keysyms
, &globalconf
.numlockmask
,
772 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
773 &globalconf
.modeswitchmask
);
775 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
777 /* regrab everything */
778 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
780 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
781 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
782 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
783 window_grabkeys(s
->root
, &globalconf
.keys
);
786 foreach(_c
, globalconf
.clients
)
789 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->window
, XCB_BUTTON_MASK_ANY
);
790 window_grabkeys(c
->window
, &c
->keys
);
798 event_handle_reparentnotify(void *data
,
799 xcb_connection_t
*connection
,
800 xcb_reparent_notify_event_t
*ev
)
804 if((c
= client_getbywin(ev
->window
)))
810 void a_xcb_set_event_handlers(void)
812 const xcb_query_extension_reply_t
*randr_query
;
814 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
815 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
816 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
817 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
818 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
819 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
820 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
821 xcb_event_set_focus_in_handler(&globalconf
.evenths
, event_handle_focusin
, NULL
);
822 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
823 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
824 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
825 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
826 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
827 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
828 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
829 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
830 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
832 /* check for randr extension */
833 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
834 if(randr_query
->present
)
835 xcb_event_set_handler(&globalconf
.evenths
,
836 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
837 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
842 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80