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);
363 luaA_object_unref(globalconf
.L
, *mouse_over
);
368 /* Get a ref on this widget so that it can't be unref'd from
369 * underneath us (-> invalid pointer dereference). */
370 luaA_object_push(globalconf
.L
, widget
);
371 luaA_object_ref(globalconf
.L
, -1);
372 *mouse_over
= widget
;
374 /* emit mouse::enter signal on new widget */
375 luaA_object_push(globalconf
.L
, widget
);
376 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
377 lua_pop(globalconf
.L
, 1);
382 /** The motion notify event handler.
383 * \param data currently unused.
384 * \param connection The connection to the X server.
385 * \param ev The event.
388 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
389 xcb_connection_t
*connection
,
390 xcb_motion_notify_event_t
*ev
)
394 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
397 if((wibox
= wibox_getbywin(ev
->event
)))
399 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
400 wibox
->geometry
.width
,
401 wibox
->geometry
.height
,
402 &ev
->event_x
, &ev
->event_y
);
404 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
410 /** The leave notify event handler.
411 * \param data currently unused.
412 * \param connection The connection to the X server.
413 * \param ev The event.
416 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
417 xcb_connection_t
*connection
,
418 xcb_leave_notify_event_t
*ev
)
423 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
426 if((c
= client_getbytitlebarwin(ev
->event
)) || (c
= client_getbywin(ev
->event
)))
428 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
430 luaA_object_push(globalconf
.L
, c
);
431 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
433 luaA_object_push(globalconf
.L
, c
);
434 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
435 lua_pop(globalconf
.L
, 1);
438 if((wibox
= wibox_getbywin(ev
->event
)))
440 if(wibox
->mouse_over
)
442 luaA_object_push(globalconf
.L
, wibox
->mouse_over
);
443 /* emit mouse::leave signal on widget the mouse was over */
444 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
445 lua_pop(globalconf
.L
, 1);
446 wibox_clear_mouse_over(wibox
);
449 luaA_object_push(globalconf
.L
, wibox
);
450 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
451 lua_pop(globalconf
.L
, 1);
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
->orientation
, &wibox
->widgets
,
476 wibox
->geometry
.width
,
477 wibox
->geometry
.height
,
478 &ev
->event_x
, &ev
->event_y
);
480 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
482 luaA_object_push(globalconf
.L
, wibox
);
483 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
484 lua_pop(globalconf
.L
, 1);
487 if((c
= client_getbytitlebarwin(ev
->event
))
488 || (c
= client_getbywin(ev
->event
)))
490 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
492 luaA_object_push(globalconf
.L
, c
);
493 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
495 luaA_object_push(globalconf
.L
, c
);
496 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
497 lua_pop(globalconf
.L
, 1);
503 /** The focus in event handler.
504 * \param data currently unused.
505 * \param connection The connection to the X server.
506 * \param ev The event.
509 event_handle_focusin(void *data
__attribute__ ((unused
)),
510 xcb_connection_t
*connection
,
511 xcb_focus_in_event_t
*ev
)
515 /* Events that we are interested in: */
518 /* These are events that jump between root windows.
520 case XCB_NOTIFY_DETAIL_ANCESTOR
:
521 case XCB_NOTIFY_DETAIL_INFERIOR
:
523 /* These are events that jump between clients.
524 * Virtual events ensure we always get an event on our top-level window.
526 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
527 case XCB_NOTIFY_DETAIL_NONLINEAR
:
528 if((c
= client_getbytitlebarwin(ev
->event
))
529 || (c
= client_getbywin(ev
->event
)))
530 client_focus_update(c
);
531 /* all other events are ignored */
538 /** The expose event handler.
539 * \param data currently unused.
540 * \param connection The connection to the X server.
541 * \param ev The event.
544 event_handle_expose(void *data
__attribute__ ((unused
)),
545 xcb_connection_t
*connection
__attribute__ ((unused
)),
546 xcb_expose_event_t
*ev
)
550 /* If the wibox got need_update set, skip this because it will be repainted
551 * soon anyway. Without this we could be painting garbage to the screen!
553 if((wibox
= wibox_getbywin(ev
->window
)) && !wibox
->need_update
)
554 wibox_refresh_pixmap_partial(wibox
,
556 ev
->width
, ev
->height
);
561 /** The key press event handler.
562 * \param data currently unused.
563 * \param connection The connection to the X server.
564 * \param ev The event.
567 event_handle_key(void *data
__attribute__ ((unused
)),
568 xcb_connection_t
*connection
__attribute__ ((unused
)),
569 xcb_key_press_event_t
*ev
)
571 if(globalconf
.keygrabber
!= LUA_REFNIL
)
573 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
574 if(keygrabber_handlekpress(globalconf
.L
, ev
))
576 if(lua_pcall(globalconf
.L
, 3, 1, 0))
578 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
579 luaA_keygrabber_stop(globalconf
.L
);
581 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
582 luaA_keygrabber_stop(globalconf
.L
);
584 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
588 /* get keysym ignoring all modifiers */
589 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
591 if((c
= client_getbywin(ev
->event
)))
593 luaA_object_push(globalconf
.L
, c
);
594 event_key_callback(ev
, &c
->keys
, -1, 1, &keysym
);
597 event_key_callback(ev
, &globalconf
.keys
, 0, 0, &keysym
);
603 /** The map request event handler.
604 * \param data currently unused.
605 * \param connection The connection to the X server.
606 * \param ev The event.
609 event_handle_maprequest(void *data
__attribute__ ((unused
)),
610 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
612 int phys_screen
, ret
= 0;
614 xcb_get_window_attributes_cookie_t wa_c
;
615 xcb_get_window_attributes_reply_t
*wa_r
;
616 xcb_get_geometry_cookie_t geom_c
;
617 xcb_get_geometry_reply_t
*geom_r
;
619 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
621 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
624 if(wa_r
->override_redirect
)
627 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
629 xcb_map_window(connection
, ev
->window
);
630 xembed_window_activate(connection
, ev
->window
);
632 else if((c
= client_getbywin(ev
->window
)))
634 /* Check that it may be visible, but not asked to be hidden */
635 if(client_maybevisible(c
, c
->screen
) && !c
->hidden
)
637 luaA_object_push(globalconf
.L
, c
);
638 client_set_minimized(globalconf
.L
, -1, false);
639 lua_pop(globalconf
.L
, 1);
640 /* it will be raised, so just update ourself */
646 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
648 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
654 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
656 client_manage(ev
->window
, geom_r
, phys_screen
, false);
666 /** The unmap notify event handler.
667 * \param data currently unused.
668 * \param connection The connection to the X server.
669 * \param ev The event.
672 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
673 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
677 if((c
= client_getbywin(ev
->window
)))
679 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
)
681 if(!XCB_EVENT_SENT(ev
))
683 /* A regular UnmapNotify, remove that client from our lists */
688 /* According to ICCCM 4.1.4 a client sends a synthetic
689 * UnmapNotify when it wants to switch to Widthdrawn state.
690 * We handle these by unmapping the client and waiting for the
691 * "real" UnmapNotify.
693 xcb_unmap_window(connection
, ev
->window
);
698 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
699 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
701 xembed_window_array_take(&globalconf
.embedded
, i
);
702 widget_invalidate_bytype(widget_systray
);
708 /** The randr screen change notify event handler.
709 * \param data currently unused.
710 * \param connection The connection to the X server.
711 * \param ev The event.
714 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
715 xcb_connection_t
*connection
__attribute__ ((unused
)),
716 xcb_randr_screen_change_notify_event_t
*ev
)
718 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
719 * (only the code relevant to RRScreenChangeNotify) as the latter
720 * doesn't provide this kind of function */
721 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
722 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
723 ev
->mheight
, ev
->mwidth
);
725 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
726 ev
->mwidth
, ev
->mheight
);
728 /* XRRUpdateConfiguration also executes the following instruction
729 * but it's not useful because SubpixelOrder is not used at all at
732 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
740 /** The client message event handler.
741 * \param data currently unused.
742 * \param connection The connection to the X server.
743 * \param ev The event.
746 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
747 xcb_connection_t
*connection
,
748 xcb_client_message_event_t
*ev
)
750 /* check for startup notification messages */
751 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
754 if(ev
->type
== WM_CHANGE_STATE
)
757 if((c
= client_getbywin(ev
->window
))
759 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
761 luaA_object_push(globalconf
.L
, c
);
762 client_set_minimized(globalconf
.L
, -1, true);
763 lua_pop(globalconf
.L
, 1);
766 else if(ev
->type
== _XEMBED
)
767 return xembed_process_client_message(ev
);
768 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
769 return systray_process_client_message(ev
);
770 return ewmh_process_client_message(ev
);
773 /** The keymap change notify event handler.
774 * \param data Unused data.
775 * \param connection The connection to the X server.
776 * \param ev The event.
777 * \return Status code, 0 if everything's fine.
780 event_handle_mappingnotify(void *data
,
781 xcb_connection_t
*connection
,
782 xcb_mapping_notify_event_t
*ev
)
784 if(ev
->request
== XCB_MAPPING_MODIFIER
785 || ev
->request
== XCB_MAPPING_KEYBOARD
)
787 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
788 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
790 /* Free and then allocate the key symbols */
791 xcb_key_symbols_free(globalconf
.keysyms
);
792 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
794 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
795 globalconf
.keysyms
, &globalconf
.numlockmask
,
796 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
797 &globalconf
.modeswitchmask
);
799 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
801 /* regrab everything */
802 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
804 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
805 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
806 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
807 window_grabkeys(s
->root
, &globalconf
.keys
);
810 foreach(_c
, globalconf
.clients
)
813 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->window
, XCB_BUTTON_MASK_ANY
);
814 window_grabkeys(c
->window
, &c
->keys
);
822 event_handle_reparentnotify(void *data
,
823 xcb_connection_t
*connection
,
824 xcb_reparent_notify_event_t
*ev
)
828 if((c
= client_getbywin(ev
->window
)))
834 void a_xcb_set_event_handlers(void)
836 const xcb_query_extension_reply_t
*randr_query
;
838 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
839 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
840 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
841 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
842 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
843 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
844 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
845 xcb_event_set_focus_in_handler(&globalconf
.evenths
, event_handle_focusin
, NULL
);
846 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
847 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
848 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
849 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
850 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
851 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
852 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
853 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
854 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
856 /* check for randr extension */
857 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
858 if(randr_query
->present
)
859 xcb_event_set_handler(&globalconf
.evenths
,
860 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
861 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
866 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80