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
));
136 * button status (8 bits) + modifiers status (8 bits)
137 * we don't care for button status that we get, especially on release, so
141 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
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
->position
, &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 event_button_callback(ev
, &w
->buttons
, 1, NULL
);
169 else if((c
= client_getbywin(ev
->event
)))
171 client_push(globalconf
.L
, c
);
172 event_button_callback(ev
, &c
->buttons
, 1, NULL
);
173 xcb_allow_events(globalconf
.connection
,
174 XCB_ALLOW_REPLAY_POINTER
,
177 else if(ev
->child
== XCB_NONE
)
178 for(screen
= 0; screen
< nb_screen
; screen
++)
179 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
181 event_button_callback(ev
, &globalconf
.buttons
, 0, NULL
);
189 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
191 uint16_t config_win_mask
= 0;
192 uint32_t config_win_vals
[7];
193 unsigned short i
= 0;
195 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
197 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
198 config_win_vals
[i
++] = ev
->x
;
200 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
202 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
203 config_win_vals
[i
++] = ev
->y
;
205 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
207 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
208 config_win_vals
[i
++] = ev
->width
;
210 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
212 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
213 config_win_vals
[i
++] = ev
->height
;
215 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
217 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
218 config_win_vals
[i
++] = ev
->border_width
;
220 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
222 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
223 config_win_vals
[i
++] = ev
->sibling
;
225 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
227 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
228 config_win_vals
[i
++] = ev
->stack_mode
;
231 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
234 /** The configure event handler.
235 * \param data currently unused.
236 * \param connection The connection to the X server.
237 * \param ev The event.
240 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
241 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
246 if((c
= client_getbywin(ev
->window
)))
248 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
250 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
252 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
254 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
255 geometry
.width
= ev
->width
;
256 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
257 geometry
.height
= ev
->height
;
259 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
260 client_setborder(c
, ev
->border_width
);
262 /* Clients are not allowed to directly mess with stacking parameters. */
263 ev
->value_mask
&= ~(XCB_CONFIG_WINDOW_SIBLING
|
264 XCB_CONFIG_WINDOW_STACK_MODE
);
268 /* We'll be sending protocol geometry, so don't readd borders and titlebar. */
269 /* We do have to ensure the windows don't end up in the visible screen. */
270 ev
->x
= geometry
.x
= - (geometry
.width
+ 2*c
->border
);
271 ev
->y
= geometry
.y
= - (geometry
.height
+ 2*c
->border
);
272 window_configure(c
->win
, geometry
, c
->border
);
273 event_handle_configurerequest_configure_window(ev
);
277 /** Configure request are sent with size relative to real (internal)
278 * window size, i.e. without titlebars and borders. */
279 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry
);
281 if(client_resize(c
, geometry
, false))
283 /* All the wiboxes (may) need to be repositioned. */
284 if(client_hasstrut(c
))
285 wibox_update_positions();
286 client_need_arrange(c
);
290 /* Resize wasn't officially needed, but we don't want to break expectations. */
291 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
292 window_configure(c
->win
, geometry
, c
->border
);
297 event_handle_configurerequest_configure_window(ev
);
302 /** The configure notify event handler.
303 * \param data currently unused.
304 * \param connection The connection to the X server.
305 * \param ev The event.
308 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
309 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
312 const xcb_screen_t
*screen
;
314 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
315 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
316 && ev
->window
== screen
->root
317 && (ev
->width
!= screen
->width_in_pixels
318 || ev
->height
!= screen
->height_in_pixels
))
319 /* it's not that we panic, but restart */
325 /** The destroy notify event handler.
326 * \param data currently unused.
327 * \param connection The connection to the X server.
328 * \param ev The event.
331 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
332 xcb_connection_t
*connection
__attribute__ ((unused
)),
333 xcb_destroy_notify_event_t
*ev
)
337 if((c
= client_getbywin(ev
->window
)))
340 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
341 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
343 xembed_window_array_take(&globalconf
.embedded
, i
);
344 foreach(screen
, globalconf
.screens
)
345 widget_invalidate_bytype(screen
, widget_systray
);
351 /** Handle a motion notify over widgets.
352 * \param object The object.
353 * \param mouse_over The pointer to the registered mouse over widget.
354 * \param widget The new widget the mouse is over.
357 event_handle_widget_motionnotify(void *object
,
358 widget_t
**mouse_over
,
361 if(widget
!= *mouse_over
)
365 if((*mouse_over
)->mouse_leave
!= LUA_REFNIL
)
367 /* call mouse leave function on old widget */
368 widget_push(globalconf
.L
, *mouse_over
);
369 luaA_dofunction(globalconf
.L
, (*mouse_over
)->mouse_leave
, 1, 0);
374 /* call mouse enter function on new widget and register it */
375 *mouse_over
= widget
;
376 if(widget
->mouse_enter
!= LUA_REFNIL
)
378 widget_push(globalconf
.L
, widget
);
379 luaA_dofunction(globalconf
.L
, widget
->mouse_enter
, 1, 0);
385 /** The motion notify event handler.
386 * \param data currently unused.
387 * \param connection The connection to the X server.
388 * \param ev The event.
391 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
392 xcb_connection_t
*connection
,
393 xcb_motion_notify_event_t
*ev
)
397 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
400 if((wibox
= wibox_getbywin(ev
->event
)))
402 widget_t
*w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
403 wibox
->sw
.geometry
.width
,
404 wibox
->sw
.geometry
.height
,
405 &ev
->event_x
, &ev
->event_y
);
407 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
413 /** The leave notify event handler.
414 * \param data currently unused.
415 * \param connection The connection to the X server.
416 * \param ev The event.
419 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
420 xcb_connection_t
*connection
,
421 xcb_leave_notify_event_t
*ev
)
426 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
429 if((c
= client_getbytitlebarwin(ev
->event
)) || (c
= client_getbywin(ev
->event
)))
430 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
432 client_push(globalconf
.L
, c
);
433 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
436 if((wibox
= wibox_getbywin(ev
->event
)))
438 if(wibox
->mouse_over
)
440 if(wibox
->mouse_over
->mouse_leave
!= LUA_REFNIL
)
442 /* call mouse leave function on widget the mouse was over */
443 wibox_push(globalconf
.L
, wibox
);
444 luaA_dofunction(globalconf
.L
, wibox
->mouse_over
->mouse_leave
, 1, 0);
446 wibox
->mouse_over
= NULL
;
449 if(wibox
->mouse_leave
!= LUA_REFNIL
)
450 luaA_dofunction(globalconf
.L
, wibox
->mouse_leave
, 0, 0);
456 /** The enter notify event handler.
457 * \param data currently unused.
458 * \param connection The connection to the X server.
459 * \param ev The event.
462 event_handle_enternotify(void *data
__attribute__ ((unused
)),
463 xcb_connection_t
*connection
,
464 xcb_enter_notify_event_t
*ev
)
469 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
472 if((wibox
= wibox_getbywin(ev
->event
)))
474 widget_t
*w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
475 wibox
->sw
.geometry
.width
,
476 wibox
->sw
.geometry
.height
,
477 &ev
->event_x
, &ev
->event_y
);
479 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
481 if(wibox
->mouse_enter
!= LUA_REFNIL
)
482 luaA_dofunction(globalconf
.L
, wibox
->mouse_enter
, 0, 0);
485 if((c
= client_getbytitlebarwin(ev
->event
))
486 || (c
= client_getbywin(ev
->event
)))
487 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
489 client_push(globalconf
.L
, c
);
490 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
496 /** The focus in event handler.
497 * \param data currently unused.
498 * \param connection The connection to the X server.
499 * \param ev The event.
502 event_handle_focusin(void *data
__attribute__ ((unused
)),
503 xcb_connection_t
*connection
,
504 xcb_focus_in_event_t
*ev
)
508 /* Events that we are interested in: */
511 /* These are events that jump between root windows.
513 case XCB_NOTIFY_DETAIL_ANCESTOR
:
514 case XCB_NOTIFY_DETAIL_INFERIOR
:
516 /* These are events that jump between clients.
517 * Virtual events ensure we always get an event on our top-level window.
519 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
520 case XCB_NOTIFY_DETAIL_NONLINEAR
:
521 if((c
= client_getbytitlebarwin(ev
->event
))
522 || (c
= client_getbywin(ev
->event
)))
523 client_focus_update(c
);
524 /* all other events are ignored */
531 /** The expose event handler.
532 * \param data currently unused.
533 * \param connection The connection to the X server.
534 * \param ev The event.
537 event_handle_expose(void *data
__attribute__ ((unused
)),
538 xcb_connection_t
*connection
__attribute__ ((unused
)),
539 xcb_expose_event_t
*ev
)
543 if((wibox
= wibox_getbywin(ev
->window
)))
544 simplewindow_refresh_pixmap_partial(&wibox
->sw
,
546 ev
->width
, ev
->height
);
551 /** The key press event handler.
552 * \param data currently unused.
553 * \param connection The connection to the X server.
554 * \param ev The event.
557 event_handle_key(void *data
__attribute__ ((unused
)),
558 xcb_connection_t
*connection
__attribute__ ((unused
)),
559 xcb_key_press_event_t
*ev
)
561 if(globalconf
.keygrabber
!= LUA_REFNIL
)
563 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
564 if(keygrabber_handlekpress(globalconf
.L
, ev
))
566 if(lua_pcall(globalconf
.L
, 3, 1, 0))
568 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
569 luaA_keygrabber_stop(globalconf
.L
);
571 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
572 luaA_keygrabber_stop(globalconf
.L
);
574 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
578 /* get keysym ignoring all modifiers */
579 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
581 if((c
= client_getbywin(ev
->event
)))
583 client_push(globalconf
.L
, c
);
584 event_key_callback(ev
, &c
->keys
, 1, &keysym
);
587 event_key_callback(ev
, &globalconf
.keys
, 0, &keysym
);
593 /** The map request event handler.
594 * \param data currently unused.
595 * \param connection The connection to the X server.
596 * \param ev The event.
599 event_handle_maprequest(void *data
__attribute__ ((unused
)),
600 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
602 int phys_screen
, ret
= 0;
604 xcb_get_window_attributes_cookie_t wa_c
;
605 xcb_get_window_attributes_reply_t
*wa_r
;
606 xcb_get_geometry_cookie_t geom_c
;
607 xcb_get_geometry_reply_t
*geom_r
;
609 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
611 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
614 if(wa_r
->override_redirect
)
617 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
619 xcb_map_window(connection
, ev
->window
);
620 xembed_window_activate(connection
, ev
->window
);
622 else if((c
= client_getbywin(ev
->window
)))
624 /* Check that it may be visible, but not asked to be hidden */
625 if(client_maybevisible(c
, c
->screen
) && !c
->ishidden
)
627 client_setminimized(c
, false);
628 /* it will be raised, so just update ourself */
634 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
636 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
642 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
644 client_manage(ev
->window
, geom_r
, phys_screen
, false);
654 /** The unmap notify event handler.
655 * \param data currently unused.
656 * \param connection The connection to the X server.
657 * \param ev The event.
660 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
661 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
665 if((c
= client_getbywin(ev
->window
)))
667 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
668 && XCB_EVENT_SENT(ev
)
669 && window_state_get_reply(window_state_get_unchecked(c
->win
)) == XCB_WM_STATE_NORMAL
)
673 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
674 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
676 xembed_window_array_take(&globalconf
.embedded
, i
);
677 foreach(screen
, globalconf
.screens
)
678 widget_invalidate_bytype(screen
, 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 if(!globalconf
.have_randr
)
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
)
739 client_setminimized(c
, true);
741 else if(ev
->type
== _XEMBED
)
742 return xembed_process_client_message(ev
);
743 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
744 return systray_process_client_message(ev
);
745 return ewmh_process_client_message(ev
);
748 /** The keymap change notify event handler.
749 * \param data Unused data.
750 * \param connection The connection to the X server.
751 * \param ev The event.
752 * \return Status code, 0 if everything's fine.
755 event_handle_mappingnotify(void *data
,
756 xcb_connection_t
*connection
,
757 xcb_mapping_notify_event_t
*ev
)
759 if(ev
->request
== XCB_MAPPING_MODIFIER
760 || ev
->request
== XCB_MAPPING_KEYBOARD
)
762 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
763 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
765 /* Free and then allocate the key symbols */
766 xcb_key_symbols_free(globalconf
.keysyms
);
767 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
769 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
770 globalconf
.keysyms
, &globalconf
.numlockmask
,
771 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
772 &globalconf
.modeswitchmask
);
774 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
776 /* regrab everything */
777 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
779 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
780 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
781 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
782 window_grabkeys(s
->root
, &globalconf
.keys
);
785 foreach(_c
, globalconf
.clients
)
788 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
789 window_grabkeys(c
->win
, &c
->keys
);
797 event_handle_reparentnotify(void *data
,
798 xcb_connection_t
*connection
,
799 xcb_reparent_notify_event_t
*ev
)
803 if((c
= client_getbywin(ev
->window
)))
809 void a_xcb_set_event_handlers(void)
811 const xcb_query_extension_reply_t
*randr_query
;
813 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
814 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
815 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
816 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
817 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
818 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
819 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
820 xcb_event_set_focus_in_handler(&globalconf
.evenths
, event_handle_focusin
, NULL
);
821 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
822 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
823 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
824 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
825 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
826 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
827 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
828 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
829 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
831 /* check for randr extension */
832 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
833 if((globalconf
.have_randr
= randr_query
->present
))
834 xcb_event_set_handler(&globalconf
.evenths
,
835 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
836 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
841 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80