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>
38 #include "keygrabber.h"
39 #include "mousegrabber.h"
43 #include "common/atoms.h"
44 #include "common/xutil.h"
46 #define DO_EVENT_HOOK_CALLBACK(type, xcbtype, xcbeventprefix, arraytype, match) \
48 event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
54 int abs_oud = oud < 0 ? ((lua_gettop(globalconf.L) + 1) + oud) : oud; \
55 int item_matching = 0; \
57 if(match(ev, *item, data)) \
60 luaA_object_push_item(globalconf.L, abs_oud, *item); \
62 luaA_object_push(globalconf.L, *item); \
65 for(; item_matching > 0; item_matching--) \
67 switch(ev->response_type) \
69 case xcbeventprefix##_PRESS: \
70 for(int i = 0; i < nargs; i++) \
71 lua_pushvalue(globalconf.L, - nargs - item_matching); \
72 luaA_object_emit_signal(globalconf.L, - nargs - 1, "press", nargs); \
74 case xcbeventprefix##_RELEASE: \
75 for(int i = 0; i < nargs; i++) \
76 lua_pushvalue(globalconf.L, - nargs - item_matching); \
77 luaA_object_emit_signal(globalconf.L, - nargs - 1, "release", nargs); \
80 lua_pop(globalconf.L, 1); \
82 lua_pop(globalconf.L, nargs); \
86 event_key_match(xcb_key_press_event_t
*ev
, keyb_t
*k
, void *data
)
89 xcb_keysym_t keysym
= *(xcb_keysym_t
*) data
;
90 return (((k
->keycode
&& ev
->detail
== k
->keycode
)
91 || (k
->keysym
&& keysym
== k
->keysym
))
92 && (k
->modifiers
== XCB_BUTTON_MASK_ANY
|| k
->modifiers
== ev
->state
));
96 event_button_match(xcb_button_press_event_t
*ev
, button_t
*b
, void *data
)
98 return ((!b
->button
|| ev
->detail
== b
->button
)
99 && (b
->modifiers
== XCB_BUTTON_MASK_ANY
|| b
->modifiers
== ev
->state
));
102 DO_EVENT_HOOK_CALLBACK(button_t
, button
, XCB_BUTTON
, button_array_t
, event_button_match
)
103 DO_EVENT_HOOK_CALLBACK(keyb_t
, key
, XCB_KEY
, key_array_t
, event_key_match
)
105 /** Handle an event with mouse grabber if needed
106 * \param x The x coordinate.
107 * \param y The y coordinate.
108 * \param mask The mask buttons.
109 * \return True if the event was handled.
112 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
114 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
116 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
117 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
118 if(lua_pcall(globalconf
.L
, 1, 1, 0))
120 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
121 luaA_mousegrabber_stop(globalconf
.L
);
123 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
124 luaA_mousegrabber_stop(globalconf
.L
);
125 lua_pop(globalconf
.L
, 1); /* pop returned value */
131 /** The button press event handler.
132 * \param ev The event.
135 event_handle_button(xcb_button_press_event_t
*ev
)
138 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
));
142 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, 1 << (ev
->detail
- 1 + 8)))
146 * button status (8 bits) + modifiers status (8 bits)
147 * we don't care for button status that we get, especially on release, so
151 if((wibox
= wibox_getbywin(ev
->event
))
152 || (wibox
= wibox_getbywin(ev
->child
)))
154 /* If the wibox is child, then x,y are
155 * relative to root window */
156 if(wibox
->window
== ev
->child
)
158 ev
->event_x
-= wibox
->geometry
.x
;
159 ev
->event_y
-= wibox
->geometry
.y
;
163 luaA_object_push(globalconf
.L
, wibox
);
164 /* Duplicate the wibox */
165 lua_pushvalue(globalconf
.L
, -1);
166 /* Handle the button event on it */
167 event_button_callback(ev
, &wibox
->buttons
, -1, 1, NULL
);
169 /* then try to match a widget binding */
170 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
171 wibox
->geometry
.width
,
172 wibox
->geometry
.height
,
173 &ev
->event_x
, &ev
->event_y
);
176 /* Push widget (the wibox is already on stack) */
177 luaA_object_push_item(globalconf
.L
, -1, w
);
178 /* Move widget before wibox */
179 lua_insert(globalconf
.L
, -2);
180 event_button_callback(ev
, &w
->buttons
, -2, 2, NULL
);
183 /* Remove the wibox, we did not use it */
184 lua_pop(globalconf
.L
, 1);
187 else if((c
= client_getbywin(ev
->event
)))
189 luaA_object_push(globalconf
.L
, c
);
190 event_button_callback(ev
, &c
->buttons
, -1, 1, NULL
);
191 xcb_allow_events(globalconf
.connection
,
192 XCB_ALLOW_REPLAY_POINTER
,
195 else if(ev
->child
== XCB_NONE
)
196 for(screen
= 0; screen
< nb_screen
; screen
++)
197 if(xutil_screen_get(globalconf
.connection
, screen
)->root
== ev
->event
)
199 event_button_callback(ev
, &globalconf
.buttons
, 0, 0, NULL
);
205 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
207 uint16_t config_win_mask
= 0;
208 uint32_t config_win_vals
[7];
209 unsigned short i
= 0;
211 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
213 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
214 config_win_vals
[i
++] = ev
->x
;
216 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
218 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
219 config_win_vals
[i
++] = ev
->y
;
221 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
223 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
224 config_win_vals
[i
++] = ev
->width
;
226 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
228 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
229 config_win_vals
[i
++] = ev
->height
;
231 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
233 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
234 config_win_vals
[i
++] = ev
->border_width
;
236 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
238 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
239 config_win_vals
[i
++] = ev
->sibling
;
241 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
243 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
244 config_win_vals
[i
++] = ev
->stack_mode
;
247 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
250 /** The configure event handler.
251 * \param ev The event.
254 event_handle_configurerequest(xcb_configure_request_event_t
*ev
)
259 if((c
= client_getbywin(ev
->window
)))
261 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border_width
, c
->geometry
);
263 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
265 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
267 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
268 geometry
.width
= ev
->width
;
269 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
270 geometry
.height
= ev
->height
;
272 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
274 luaA_object_push(globalconf
.L
, c
);
275 client_set_border_width(globalconf
.L
, -1, ev
->border_width
);
276 lua_pop(globalconf
.L
, 1);
279 /* Clients are not allowed to directly mess with stacking parameters. */
280 ev
->value_mask
&= ~(XCB_CONFIG_WINDOW_SIBLING
|
281 XCB_CONFIG_WINDOW_STACK_MODE
);
283 /** Configure request are sent with size relative to real (internal)
284 * window size, i.e. without titlebars and borders. */
285 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border_width
, geometry
);
287 if(!client_resize(c
, geometry
, false))
289 /* Resize wasn't officially needed, but we don't want to break expectations. */
290 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border_width
, c
->geometry
);
291 window_configure(c
->window
, geometry
, c
->border_width
);
295 event_handle_configurerequest_configure_window(ev
);
298 /** The configure notify event handler.
299 * \param ev The event.
302 event_handle_configurenotify(xcb_configure_notify_event_t
*ev
)
305 const xcb_screen_t
*screen
;
307 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
)); screen_nbr
++)
308 if((screen
= xutil_screen_get(globalconf
.connection
, screen_nbr
)) != NULL
309 && ev
->window
== screen
->root
310 && (ev
->width
!= screen
->width_in_pixels
311 || ev
->height
!= screen
->height_in_pixels
))
312 /* it's not that we panic, but restart */
316 /** The destroy notify event handler.
317 * \param ev The event.
320 event_handle_destroynotify(xcb_destroy_notify_event_t
*ev
)
324 if((c
= client_getbywin(ev
->window
)))
327 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
328 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
330 xembed_window_array_take(&globalconf
.embedded
, i
);
331 widget_invalidate_bytype(widget_systray
);
335 /** Handle a motion notify over widgets.
336 * \param wibox The wibox.
337 * \param mouse_over The pointer to the registered mouse over widget.
338 * \param widget The new widget the mouse is over.
341 event_handle_widget_motionnotify(wibox_t
*wibox
,
344 if(widget
!= wibox
->mouse_over
)
346 if(wibox
->mouse_over
)
348 /* Emit mouse leave signal on old widget:
350 luaA_object_push(globalconf
.L
, wibox
);
351 /* - Push the widget the mouse was on */
352 luaA_object_push_item(globalconf
.L
, -1, wibox
->mouse_over
);
353 /* - Invert wibox/widget */
354 lua_insert(globalconf
.L
, -2);
355 /* - Emit the signal mouse::leave with the wibox as argument */
356 luaA_object_emit_signal(globalconf
.L
, -2, "mouse::leave", 1);
357 /* - Remove the widget */
358 lua_pop(globalconf
.L
, 1);
361 luaA_object_push(globalconf
.L
, wibox
);
362 luaA_object_unref_item(globalconf
.L
, -1, wibox
->mouse_over
);
363 /* Remove the wibox */
364 lua_pop(globalconf
.L
, 1);
368 /* Get a ref on this widget so that it can't be unref'd from
369 * underneath us (-> invalid pointer dereference):
370 * - Push the wibox */
371 luaA_object_push(globalconf
.L
, wibox
);
372 /* - Push the widget */
373 luaA_object_push_item(globalconf
.L
, -1, widget
);
374 /* - Reference the widget into the wibox */
375 luaA_object_ref_item(globalconf
.L
, -2, -1);
377 /* Emit mouse::enter signal on new widget:
378 * - Push the widget */
379 luaA_object_push_item(globalconf
.L
, -1, widget
);
380 /* - Move the widget before the wibox we pushed just above */
381 lua_insert(globalconf
.L
, -2);
382 /* - Emit the signal with the wibox as argument */
384 luaA_object_emit_signal(globalconf
.L
, -2, "mouse::enter", 1);
385 /* - Remove the widget from the stack */
386 lua_pop(globalconf
.L
, 1);
389 /* Store that this widget was the one with the mouse over */
390 wibox
->mouse_over
= widget
;
395 /** The motion notify event handler.
396 * \param ev The event.
399 event_handle_motionnotify(xcb_motion_notify_event_t
*ev
)
403 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
406 if((wibox
= wibox_getbywin(ev
->event
)))
408 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
409 wibox
->geometry
.width
,
410 wibox
->geometry
.height
,
411 &ev
->event_x
, &ev
->event_y
);
413 event_handle_widget_motionnotify(wibox
, w
);
417 /** The leave notify event handler.
418 * \param ev The event.
421 event_handle_leavenotify(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
)))
431 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
433 luaA_object_push(globalconf
.L
, c
);
434 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
436 luaA_object_push(globalconf
.L
, c
);
437 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
438 lua_pop(globalconf
.L
, 1);
441 if((wibox
= wibox_getbywin(ev
->event
)))
443 if(wibox
->mouse_over
)
446 luaA_object_push(globalconf
.L
, wibox
);
447 /* Push the widget the mouse is over in this wibox */
448 luaA_object_push_item(globalconf
.L
, -1, wibox
->mouse_over
);
449 /* Move the widget before the wibox */
450 lua_insert(globalconf
.L
, -2);
451 /* Emit mouse::leave signal on widget the mouse was over with
452 * its wibox as argument */
453 luaA_object_emit_signal(globalconf
.L
, -2, "mouse::leave", 1);
454 /* Remove the widget from the stack */
455 lua_pop(globalconf
.L
, 1);
456 wibox_clear_mouse_over(wibox
);
459 luaA_object_push(globalconf
.L
, wibox
);
460 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
461 lua_pop(globalconf
.L
, 1);
465 /** The enter notify event handler.
466 * \param ev The event.
469 event_handle_enternotify(xcb_enter_notify_event_t
*ev
)
474 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
477 if((wibox
= wibox_getbywin(ev
->event
)))
479 widget_t
*w
= widget_getbycoords(wibox
->orientation
, &wibox
->widgets
,
480 wibox
->geometry
.width
,
481 wibox
->geometry
.height
,
482 &ev
->event_x
, &ev
->event_y
);
484 event_handle_widget_motionnotify(wibox
, w
);
486 luaA_object_push(globalconf
.L
, wibox
);
487 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
488 lua_pop(globalconf
.L
, 1);
491 if((c
= client_getbytitlebarwin(ev
->event
))
492 || (c
= client_getbywin(ev
->event
)))
494 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
496 luaA_object_push(globalconf
.L
, c
);
497 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
499 luaA_object_push(globalconf
.L
, c
);
500 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
501 lua_pop(globalconf
.L
, 1);
505 /** The focus in event handler.
506 * \param ev The event.
509 event_handle_focusin(xcb_focus_in_event_t
*ev
)
513 /* Events that we are interested in: */
516 /* These are events that jump between root windows.
518 case XCB_NOTIFY_DETAIL_ANCESTOR
:
519 case XCB_NOTIFY_DETAIL_INFERIOR
:
521 /* These are events that jump between clients.
522 * Virtual events ensure we always get an event on our top-level window.
524 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
525 case XCB_NOTIFY_DETAIL_NONLINEAR
:
526 if((c
= client_getbytitlebarwin(ev
->event
))
527 || (c
= client_getbywin(ev
->event
)))
528 client_focus_update(c
);
529 /* all other events are ignored */
535 /** The expose event handler.
536 * \param ev The event.
539 event_handle_expose(xcb_expose_event_t
*ev
)
543 /* If the wibox got need_update set, skip this because it will be repainted
544 * soon anyway. Without this we could be painting garbage to the screen!
546 if((wibox
= wibox_getbywin(ev
->window
)) && !wibox
->need_update
)
547 wibox_refresh_pixmap_partial(wibox
,
549 ev
->width
, ev
->height
);
552 /** The key press event handler.
553 * \param ev The event.
556 event_handle_key(xcb_key_press_event_t
*ev
)
558 if(globalconf
.keygrabber
!= LUA_REFNIL
)
560 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
561 if(keygrabber_handlekpress(globalconf
.L
, ev
))
563 if(lua_pcall(globalconf
.L
, 3, 1, 0))
565 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
566 luaA_keygrabber_stop(globalconf
.L
);
568 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
569 luaA_keygrabber_stop(globalconf
.L
);
571 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
575 /* get keysym ignoring all modifiers */
576 xcb_keysym_t keysym
= key_getkeysym(ev
->detail
, 0);
578 if((c
= client_getbywin(ev
->event
)))
580 luaA_object_push(globalconf
.L
, c
);
581 event_key_callback(ev
, &c
->keys
, -1, 1, &keysym
);
584 event_key_callback(ev
, &globalconf
.keys
, 0, 0, &keysym
);
588 /** The map request event handler.
589 * \param ev The event.
592 event_handle_maprequest(xcb_map_request_event_t
*ev
)
596 xcb_get_window_attributes_cookie_t wa_c
;
597 xcb_get_window_attributes_reply_t
*wa_r
;
598 xcb_get_geometry_cookie_t geom_c
;
599 xcb_get_geometry_reply_t
*geom_r
;
601 wa_c
= xcb_get_window_attributes_unchecked(globalconf
.connection
, ev
->window
);
603 if(!(wa_r
= xcb_get_window_attributes_reply(globalconf
.connection
, wa_c
, NULL
)))
606 if(wa_r
->override_redirect
)
609 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
611 xcb_map_window(globalconf
.connection
, ev
->window
);
612 xembed_window_activate(globalconf
.connection
, ev
->window
);
614 else if((c
= client_getbywin(ev
->window
)))
616 /* Check that it may be visible, but not asked to be hidden */
617 if(client_maybevisible(c
, c
->screen
) && !c
->hidden
)
619 luaA_object_push(globalconf
.L
, c
);
620 client_set_minimized(globalconf
.L
, -1, false);
621 lua_pop(globalconf
.L
, 1);
622 /* it will be raised, so just update ourself */
628 geom_c
= xcb_get_geometry_unchecked(globalconf
.connection
, ev
->window
);
630 if(!(geom_r
= xcb_get_geometry_reply(globalconf
.connection
, geom_c
, NULL
)))
635 phys_screen
= xutil_root2screen(globalconf
.connection
, geom_r
->root
);
637 client_manage(ev
->window
, geom_r
, phys_screen
, false);
646 /** The unmap notify event handler.
647 * \param ev The event.
650 event_handle_unmapnotify(xcb_unmap_notify_event_t
*ev
)
654 if((c
= client_getbywin(ev
->window
)))
656 if(ev
->event
== xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
657 && XCB_EVENT_SENT(ev
))
660 xcb_unmap_window(globalconf
.connection
, ev
->window
);
664 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
665 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
667 xembed_window_array_take(&globalconf
.embedded
, i
);
668 widget_invalidate_bytype(widget_systray
);
669 xcb_change_save_set(globalconf
.connection
, XCB_SET_MODE_DELETE
, ev
->window
);
673 /** The randr screen change notify event handler.
674 * \param ev The event.
677 event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t
*ev
)
679 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
680 * (only the code relevant to RRScreenChangeNotify) as the latter
681 * doesn't provide this kind of function */
682 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
683 xcb_randr_set_screen_size(globalconf
.connection
, ev
->root
, ev
->height
, ev
->width
,
684 ev
->mheight
, ev
->mwidth
);
686 xcb_randr_set_screen_size(globalconf
.connection
, ev
->root
, ev
->width
, ev
->height
,
687 ev
->mwidth
, ev
->mheight
);
689 /* XRRUpdateConfiguration also executes the following instruction
690 * but it's not useful because SubpixelOrder is not used at all at
693 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
699 /** The client message event handler.
700 * \param ev The event.
703 event_handle_clientmessage(xcb_client_message_event_t
*ev
)
705 /* check for startup notification messages */
706 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
709 if(ev
->type
== WM_CHANGE_STATE
)
712 if((c
= client_getbywin(ev
->window
))
714 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
716 luaA_object_push(globalconf
.L
, c
);
717 client_set_minimized(globalconf
.L
, -1, true);
718 lua_pop(globalconf
.L
, 1);
721 else if(ev
->type
== _XEMBED
)
722 xembed_process_client_message(ev
);
723 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
724 systray_process_client_message(ev
);
726 ewmh_process_client_message(ev
);
729 /** The keymap change notify event handler.
730 * \param ev The event.
733 event_handle_mappingnotify(xcb_mapping_notify_event_t
*ev
)
735 if(ev
->request
== XCB_MAPPING_MODIFIER
736 || ev
->request
== XCB_MAPPING_KEYBOARD
)
738 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
739 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
741 /* Free and then allocate the key symbols */
742 xcb_key_symbols_free(globalconf
.keysyms
);
743 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
745 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
746 globalconf
.keysyms
, &globalconf
.numlockmask
,
747 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
748 &globalconf
.modeswitchmask
);
750 int nscreen
= xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
));
752 /* regrab everything */
753 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
755 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
756 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
757 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
758 window_grabkeys(s
->root
, &globalconf
.keys
);
761 foreach(_c
, globalconf
.clients
)
764 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->window
, XCB_BUTTON_MASK_ANY
);
765 window_grabkeys(c
->window
, &c
->keys
);
771 event_handle_reparentnotify(xcb_reparent_notify_event_t
*ev
)
775 if((c
= client_getbywin(ev
->window
)))
779 /** \brief awesome xerror function.
780 * There's no way to check accesses to destroyed windows, thus those cases are
781 * ignored (especially on UnmapNotify's).
782 * \param e The error event.
785 xerror(xcb_generic_error_t
*e
)
788 if(e
->error_code
== XCB_EVENT_ERROR_BAD_WINDOW
789 || (e
->error_code
== XCB_EVENT_ERROR_BAD_MATCH
790 && e
->major_code
== XCB_SET_INPUT_FOCUS
)
791 || (e
->error_code
== XCB_EVENT_ERROR_BAD_VALUE
792 && e
->major_code
== XCB_KILL_CLIENT
)
793 || (e
->major_code
== XCB_CONFIGURE_WINDOW
794 && e
->error_code
== XCB_EVENT_ERROR_BAD_MATCH
))
797 warn("X error: request=%s, error=%s",
798 xcb_event_get_request_label(e
->major_code
),
799 xcb_event_get_error_label(e
->error_code
));
804 void event_handle(xcb_generic_event_t
*event
)
806 uint8_t response_type
= XCB_EVENT_RESPONSE_TYPE(event
);
808 if(response_type
== 0)
810 /* This is an error, not a event */
811 xerror((xcb_generic_error_t
*) event
);
815 switch(response_type
)
817 #define EVENT(type, callback) case type: callback((void *) event); return
818 EVENT(XCB_BUTTON_PRESS
, event_handle_button
);
819 EVENT(XCB_BUTTON_RELEASE
, event_handle_button
);
820 EVENT(XCB_CONFIGURE_REQUEST
, event_handle_configurerequest
);
821 EVENT(XCB_CONFIGURE_NOTIFY
, event_handle_configurenotify
);
822 EVENT(XCB_DESTROY_NOTIFY
, event_handle_destroynotify
);
823 EVENT(XCB_ENTER_NOTIFY
, event_handle_enternotify
);
824 EVENT(XCB_CLIENT_MESSAGE
, event_handle_clientmessage
);
825 EVENT(XCB_EXPOSE
, event_handle_expose
);
826 EVENT(XCB_FOCUS_IN
, event_handle_focusin
);
827 EVENT(XCB_KEY_PRESS
, event_handle_key
);
828 EVENT(XCB_KEY_RELEASE
, event_handle_key
);
829 EVENT(XCB_LEAVE_NOTIFY
, event_handle_leavenotify
);
830 EVENT(XCB_MAPPING_NOTIFY
, event_handle_mappingnotify
);
831 EVENT(XCB_MAP_REQUEST
, event_handle_maprequest
);
832 EVENT(XCB_MOTION_NOTIFY
, event_handle_motionnotify
);
833 EVENT(XCB_PROPERTY_NOTIFY
, property_handle_propertynotify
);
834 EVENT(XCB_REPARENT_NOTIFY
, event_handle_reparentnotify
);
835 EVENT(XCB_UNMAP_NOTIFY
, event_handle_unmapnotify
);
839 static uint8_t randr_screen_change_notify
= 0;
841 if(randr_screen_change_notify
== 0)
843 /* check for randr extension */
844 const xcb_query_extension_reply_t
*randr_query
;
845 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
846 if(randr_query
->present
)
847 randr_screen_change_notify
= randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
;
850 if (response_type
== randr_screen_change_notify
)
851 event_handle_randr_screen_change_notify((void *) event
);
854 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80