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(xcbtype, xcbeventprefix, type, arraytype, match) \
47 event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
53 if(match(ev, *item, data)) \
54 switch(ev->response_type) \
56 case xcbeventprefix##_PRESS: \
57 if((*item)->press != LUA_REFNIL) \
59 for(int i = 0; i < nargs; i++) \
60 lua_pushvalue(globalconf.L, - nargs); \
61 luaA_dofunction(globalconf.L, (*item)->press, nargs, 0); \
64 case xcbeventprefix##_RELEASE: \
65 if((*item)->release != LUA_REFNIL) \
67 for(int i = 0; i < nargs; i++) \
68 lua_pushvalue(globalconf.L, - nargs); \
69 luaA_dofunction(globalconf.L, (*item)->release, nargs, 0); \
73 lua_pop(globalconf.L, nargs); \
77 event_button_match(xcb_button_press_event_t
*ev
, button_t
*b
, void *data
)
79 return ((!b
->button
|| ev
->detail
== b
->button
)
80 && (b
->mod
== XCB_BUTTON_MASK_ANY
|| b
->mod
== ev
->state
));
84 event_key_match(xcb_key_press_event_t
*ev
, keyb_t
*k
, void *data
)
87 xcb_keysym_t keysym
= *(xcb_keysym_t
*) data
;
88 return (((k
->keycode
&& ev
->detail
== k
->keycode
)
89 || (k
->keysym
&& keysym
== k
->keysym
))
90 && (k
->mod
== XCB_BUTTON_MASK_ANY
|| k
->mod
== ev
->state
));
93 DO_EVENT_HOOK_CALLBACK(button
, XCB_BUTTON
, button_t
, button_array_t
, event_button_match
)
94 DO_EVENT_HOOK_CALLBACK(key
, XCB_KEY
, keyb_t
, key_array_t
, event_key_match
)
96 /** Handle an event with mouse grabber if needed
97 * \param x The x coordinate.
98 * \param y The y coordinate.
99 * \param mask The mask buttons.
100 * \return True if the event was handled.
103 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
105 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
107 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
108 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
109 if(lua_pcall(globalconf
.L
, 1, 1, 0))
111 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
112 luaA_mousegrabber_stop(globalconf
.L
);
114 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
115 luaA_mousegrabber_stop(globalconf
.L
);
116 lua_pop(globalconf
.L
, 1); /* pop returned value */
122 /** The button press event handler.
123 * \param data The type of mouse event.
124 * \param connection The connection to the X server.
125 * \param ev The event.
128 event_handle_button(void *data
, xcb_connection_t
*connection
, xcb_button_press_event_t
*ev
)
131 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(connection
));
135 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, 1 << (ev
->detail
- 1 + 8)))
139 * button status (8 bits) + modifiers status (8 bits)
140 * we don't care for button status that we get, especially on release, so
144 if((wibox
= wibox_getbywin(ev
->event
))
145 || (wibox
= wibox_getbywin(ev
->child
)))
147 /* If the wibox is child, then x,y are
148 * relative to root window */
149 if(wibox
->sw
.window
== ev
->child
)
151 ev
->event_x
-= wibox
->sw
.geometry
.x
;
152 ev
->event_y
-= wibox
->sw
.geometry
.y
;
155 wibox_push(globalconf
.L
, wibox
);
156 event_button_callback(ev
, &wibox
->buttons
, 1, NULL
);
158 /* then try to match a widget binding */
159 widget_t
*w
= widget_getbycoords(wibox
->sw
.orientation
, &wibox
->widgets
,
160 wibox
->sw
.geometry
.width
,
161 wibox
->sw
.geometry
.height
,
162 &ev
->event_x
, &ev
->event_y
);
165 widget_push(globalconf
.L
, w
);
166 wibox_push(globalconf
.L
, wibox
);
167 event_button_callback(ev
, &w
->buttons
, 2, NULL
);
170 else if((c
= client_getbywin(ev
->event
)))
172 client_push(globalconf
.L
, c
);
173 event_button_callback(ev
, &c
->buttons
, 1, NULL
);
174 xcb_allow_events(globalconf
.connection
,
175 XCB_ALLOW_REPLAY_POINTER
,
178 else if(ev
->child
== XCB_NONE
)
179 for(screen
= 0; screen
< nb_screen
; screen
++)
180 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
182 event_button_callback(ev
, &globalconf
.buttons
, 0, NULL
);
190 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
192 uint16_t config_win_mask
= 0;
193 uint32_t config_win_vals
[7];
194 unsigned short i
= 0;
196 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
198 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
199 config_win_vals
[i
++] = ev
->x
;
201 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
203 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
204 config_win_vals
[i
++] = ev
->y
;
206 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
208 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
209 config_win_vals
[i
++] = ev
->width
;
211 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
213 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
214 config_win_vals
[i
++] = ev
->height
;
216 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
218 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
219 config_win_vals
[i
++] = ev
->border_width
;
221 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
223 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
224 config_win_vals
[i
++] = ev
->sibling
;
226 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
228 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
229 config_win_vals
[i
++] = ev
->stack_mode
;
232 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
235 /** The configure event handler.
236 * \param data currently unused.
237 * \param connection The connection to the X server.
238 * \param ev The event.
241 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
242 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
247 if((c
= client_getbywin(ev
->window
)))
249 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
251 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
253 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
255 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
256 geometry
.width
= ev
->width
;
257 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
258 geometry
.height
= ev
->height
;
260 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
261 client_setborder(c
, ev
->border_width
);
263 /* Clients are not allowed to directly mess with stacking parameters. */
264 ev
->value_mask
&= ~(XCB_CONFIG_WINDOW_SIBLING
|
265 XCB_CONFIG_WINDOW_STACK_MODE
);
269 /* We'll be sending protocol geometry, so don't readd borders and titlebar. */
270 /* We do have to ensure the windows don't end up in the visible screen. */
271 ev
->x
= geometry
.x
= - (geometry
.width
+ 2*c
->border
);
272 ev
->y
= geometry
.y
= - (geometry
.height
+ 2*c
->border
);
273 window_configure(c
->win
, geometry
, c
->border
);
274 event_handle_configurerequest_configure_window(ev
);
278 /** Configure request are sent with size relative to real (internal)
279 * window size, i.e. without titlebars and borders. */
280 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry
);
282 if(client_resize(c
, geometry
, false))
284 /* All the wiboxes (may) need to be repositioned. */
285 if(client_hasstrut(c
))
286 wibox_update_positions();
287 client_need_arrange(c
);
291 /* Resize wasn't officially needed, but we don't want to break expectations. */
292 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
293 window_configure(c
->win
, geometry
, c
->border
);
298 event_handle_configurerequest_configure_window(ev
);
303 /** The configure notify event handler.
304 * \param data currently unused.
305 * \param connection The connection to the X server.
306 * \param ev The event.
309 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
310 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
313 const xcb_screen_t
*screen
;
315 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
316 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
317 && ev
->window
== screen
->root
318 && (ev
->width
!= screen
->width_in_pixels
319 || ev
->height
!= screen
->height_in_pixels
))
320 /* it's not that we panic, but restart */
326 /** The destroy notify event handler.
327 * \param data currently unused.
328 * \param connection The connection to the X server.
329 * \param ev The event.
332 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
333 xcb_connection_t
*connection
__attribute__ ((unused
)),
334 xcb_destroy_notify_event_t
*ev
)
338 if((c
= client_getbywin(ev
->window
)))
341 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
342 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
344 xembed_window_array_take(&globalconf
.embedded
, i
);
345 foreach(screen
, globalconf
.screens
)
346 widget_invalidate_bytype(screen
, widget_systray
);
352 /** Handle a motion notify over widgets.
353 * \param object The object.
354 * \param mouse_over The pointer to the registered mouse over widget.
355 * \param widget The new widget the mouse is over.
358 event_handle_widget_motionnotify(void *object
,
359 widget_t
**mouse_over
,
362 if(widget
!= *mouse_over
)
366 if((*mouse_over
)->mouse_leave
!= LUA_REFNIL
)
368 /* call mouse leave function on old widget */
369 widget_push(globalconf
.L
, *mouse_over
);
370 luaA_dofunction(globalconf
.L
, (*mouse_over
)->mouse_leave
, 1, 0);
375 /* call mouse enter function on new widget and register it */
376 *mouse_over
= widget
;
377 if(widget
->mouse_enter
!= LUA_REFNIL
)
379 widget_push(globalconf
.L
, widget
);
380 luaA_dofunction(globalconf
.L
, widget
->mouse_enter
, 1, 0);
386 /** The motion notify event handler.
387 * \param data currently unused.
388 * \param connection The connection to the X server.
389 * \param ev The event.
392 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
393 xcb_connection_t
*connection
,
394 xcb_motion_notify_event_t
*ev
)
398 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
401 if((wibox
= wibox_getbywin(ev
->event
)))
403 widget_t
*w
= widget_getbycoords(wibox
->sw
.orientation
, &wibox
->widgets
,
404 wibox
->sw
.geometry
.width
,
405 wibox
->sw
.geometry
.height
,
406 &ev
->event_x
, &ev
->event_y
);
408 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
414 /** The leave notify event handler.
415 * \param data currently unused.
416 * \param connection The connection to the X server.
417 * \param ev The event.
420 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
421 xcb_connection_t
*connection
,
422 xcb_leave_notify_event_t
*ev
)
427 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
430 if((c
= client_getbytitlebarwin(ev
->event
)) || (c
= client_getbywin(ev
->event
)))
431 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
433 client_push(globalconf
.L
, c
);
434 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
437 if((wibox
= wibox_getbywin(ev
->event
)))
439 if(wibox
->mouse_over
)
441 if(wibox
->mouse_over
->mouse_leave
!= LUA_REFNIL
)
443 /* call mouse leave function on widget the mouse was over */
444 wibox_push(globalconf
.L
, wibox
);
445 luaA_dofunction(globalconf
.L
, wibox
->mouse_over
->mouse_leave
, 1, 0);
447 wibox
->mouse_over
= NULL
;
450 if(wibox
->mouse_leave
!= LUA_REFNIL
)
451 luaA_dofunction(globalconf
.L
, wibox
->mouse_leave
, 0, 0);
457 /** The enter notify event handler.
458 * \param data currently unused.
459 * \param connection The connection to the X server.
460 * \param ev The event.
463 event_handle_enternotify(void *data
__attribute__ ((unused
)),
464 xcb_connection_t
*connection
,
465 xcb_enter_notify_event_t
*ev
)
470 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
473 if((wibox
= wibox_getbywin(ev
->event
)))
475 widget_t
*w
= widget_getbycoords(wibox
->sw
.orientation
, &wibox
->widgets
,
476 wibox
->sw
.geometry
.width
,
477 wibox
->sw
.geometry
.height
,
478 &ev
->event_x
, &ev
->event_y
);
480 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
482 if(wibox
->mouse_enter
!= LUA_REFNIL
)
483 luaA_dofunction(globalconf
.L
, wibox
->mouse_enter
, 0, 0);
486 if((c
= client_getbytitlebarwin(ev
->event
))
487 || (c
= client_getbywin(ev
->event
)))
488 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
490 client_push(globalconf
.L
, c
);
491 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
497 /** The focus in event handler.
498 * \param data currently unused.
499 * \param connection The connection to the X server.
500 * \param ev The event.
503 event_handle_focusin(void *data
__attribute__ ((unused
)),
504 xcb_connection_t
*connection
,
505 xcb_focus_in_event_t
*ev
)
509 /* Events that we are interested in: */
512 /* These are events that jump between root windows.
514 case XCB_NOTIFY_DETAIL_ANCESTOR
:
515 case XCB_NOTIFY_DETAIL_INFERIOR
:
517 /* These are events that jump between clients.
518 * Virtual events ensure we always get an event on our top-level window.
520 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
521 case XCB_NOTIFY_DETAIL_NONLINEAR
:
522 if((c
= client_getbytitlebarwin(ev
->event
))
523 || (c
= client_getbywin(ev
->event
)))
524 client_focus_update(c
);
525 /* all other events are ignored */
532 /** The expose event handler.
533 * \param data currently unused.
534 * \param connection The connection to the X server.
535 * \param ev The event.
538 event_handle_expose(void *data
__attribute__ ((unused
)),
539 xcb_connection_t
*connection
__attribute__ ((unused
)),
540 xcb_expose_event_t
*ev
)
544 if((wibox
= wibox_getbywin(ev
->window
)))
545 simplewindow_refresh_pixmap_partial(&wibox
->sw
,
547 ev
->width
, ev
->height
);
552 /** The key press event handler.
553 * \param data currently unused.
554 * \param connection The connection to the X server.
555 * \param ev The event.
558 event_handle_key(void *data
__attribute__ ((unused
)),
559 xcb_connection_t
*connection
__attribute__ ((unused
)),
560 xcb_key_press_event_t
*ev
)
562 if(globalconf
.keygrabber
!= LUA_REFNIL
)
564 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
565 if(keygrabber_handlekpress(globalconf
.L
, ev
))
567 if(lua_pcall(globalconf
.L
, 3, 1, 0))
569 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
570 luaA_keygrabber_stop(globalconf
.L
);
572 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
573 luaA_keygrabber_stop(globalconf
.L
);
575 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
579 /* get keysym ignoring all modifiers */
580 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
582 if((c
= client_getbywin(ev
->event
)))
584 client_push(globalconf
.L
, c
);
585 event_key_callback(ev
, &c
->keys
, 1, &keysym
);
588 event_key_callback(ev
, &globalconf
.keys
, 0, &keysym
);
594 /** The map request event handler.
595 * \param data currently unused.
596 * \param connection The connection to the X server.
597 * \param ev The event.
600 event_handle_maprequest(void *data
__attribute__ ((unused
)),
601 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
603 int phys_screen
, ret
= 0;
605 xcb_get_window_attributes_cookie_t wa_c
;
606 xcb_get_window_attributes_reply_t
*wa_r
;
607 xcb_get_geometry_cookie_t geom_c
;
608 xcb_get_geometry_reply_t
*geom_r
;
610 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
612 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
615 if(wa_r
->override_redirect
)
618 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
620 xcb_map_window(connection
, ev
->window
);
621 xembed_window_activate(connection
, ev
->window
);
623 else if((c
= client_getbywin(ev
->window
)))
625 /* Check that it may be visible, but not asked to be hidden */
626 if(client_maybevisible(c
, c
->screen
) && !c
->ishidden
)
628 client_setminimized(c
, false);
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
->win
)) == 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 foreach(screen
, globalconf
.screens
)
679 widget_invalidate_bytype(screen
, widget_systray
);
685 /** The randr screen change notify event handler.
686 * \param data currently unused.
687 * \param connection The connection to the X server.
688 * \param ev The event.
691 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
692 xcb_connection_t
*connection
__attribute__ ((unused
)),
693 xcb_randr_screen_change_notify_event_t
*ev
)
695 if(!globalconf
.have_randr
)
698 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
699 * (only the code relevant to RRScreenChangeNotify) as the latter
700 * doesn't provide this kind of function */
701 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
702 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
703 ev
->mheight
, ev
->mwidth
);
705 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
706 ev
->mwidth
, ev
->mheight
);
708 /* XRRUpdateConfiguration also executes the following instruction
709 * but it's not useful because SubpixelOrder is not used at all at
712 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
720 /** The client message event handler.
721 * \param data currently unused.
722 * \param connection The connection to the X server.
723 * \param ev The event.
726 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
727 xcb_connection_t
*connection
,
728 xcb_client_message_event_t
*ev
)
730 /* check for startup notification messages */
731 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
734 if(ev
->type
== WM_CHANGE_STATE
)
737 if((c
= client_getbywin(ev
->window
))
739 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
740 client_setminimized(c
, true);
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
->win
, XCB_BUTTON_MASK_ANY
);
790 window_grabkeys(c
->win
, &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((globalconf
.have_randr
= 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