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.
25 #include "objects/tag.h"
26 #include "objects/drawin.h"
29 #include "objects/client.h"
30 #include "keyresolv.h"
31 #include "keygrabber.h"
32 #include "mousegrabber.h"
35 #include "objects/screen.h"
36 #include "common/atoms.h"
37 #include "common/xutil.h"
40 #include <xcb/randr.h>
41 #include <xcb/shape.h>
42 #include <xcb/xcb_atom.h>
43 #include <xcb/xcb_icccm.h>
44 #include <xcb/xcb_event.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 /** Emit a button signal.
132 * The top of the lua stack has to be the object on which to emit the event.
133 * \param ev The event to handle.
136 event_emit_button(xcb_button_press_event_t
*ev
)
139 switch(XCB_EVENT_RESPONSE_TYPE(ev
))
141 case XCB_BUTTON_PRESS
:
142 name
= "button::press";
144 case XCB_BUTTON_RELEASE
:
145 name
= "button::release";
148 fatal("Invalid event type");
151 /* Push the event's info */
152 lua_pushnumber(globalconf
.L
, ev
->event_x
);
153 lua_pushnumber(globalconf
.L
, ev
->event_y
);
154 lua_pushnumber(globalconf
.L
, ev
->detail
);
155 luaA_pushmodifiers(globalconf
.L
, ev
->state
);
156 /* And emit the signal */
157 luaA_object_emit_signal(globalconf
.L
, -5, name
, 4);
160 /** The button press event handler.
161 * \param ev The event.
164 event_handle_button(xcb_button_press_event_t
*ev
)
169 globalconf
.timestamp
= ev
->time
;
171 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, 1 << (ev
->detail
- 1 + 8)))
175 * button status (8 bits) + modifiers status (8 bits)
176 * we don't care for button status that we get, especially on release, so
180 if((drawin
= drawin_getbywin(ev
->event
))
181 || (drawin
= drawin_getbywin(ev
->child
)))
183 /* If the drawin is child, then x,y are
184 * relative to root window */
185 if(drawin
->window
== ev
->child
)
187 ev
->event_x
-= drawin
->geometry
.x
+ drawin
->border_width
;
188 ev
->event_y
-= drawin
->geometry
.y
+ drawin
->border_width
;
191 /* Push the drawable */
192 luaA_object_push(globalconf
.L
, drawin
);
193 luaA_object_push_item(globalconf
.L
, -1, drawin
->drawable
);
194 /* and handle the button raw button event */
195 event_emit_button(ev
);
196 lua_pop(globalconf
.L
, 1);
197 /* check if any button object matches */
198 event_button_callback(ev
, &drawin
->buttons
, -1, 1, NULL
);
199 /* Either we are receiving this due to ButtonPress/Release on the root
200 * window or because we grabbed the button on the window. In the later
201 * case we have to call AllowEvents.
202 * Use AsyncPointer instead of ReplayPointer so that the event is
203 * "eaten" instead of being handled again on the root window.
205 if(ev
->child
== XCB_NONE
)
206 xcb_allow_events(globalconf
.connection
,
207 XCB_ALLOW_ASYNC_POINTER
,
210 else if((c
= client_getbyframewin(ev
->event
)))
212 luaA_object_push(globalconf
.L
, c
);
213 /* And handle the button raw button event */
214 event_emit_button(ev
);
215 /* then check if a titlebar was "hit" */
216 int x
= ev
->event_x
, y
= ev
->event_y
;
217 drawable_t
*d
= client_get_drawable_offset(c
, &x
, &y
);
220 /* Copy the event so that we can fake x/y */
221 xcb_button_press_event_t event
= *ev
;
224 luaA_object_push_item(globalconf
.L
, -1, d
);
225 event_emit_button(&event
);
226 lua_pop(globalconf
.L
, 1);
228 /* then check if any button objects match */
229 event_button_callback(ev
, &c
->buttons
, -1, 1, NULL
);
230 xcb_allow_events(globalconf
.connection
,
231 XCB_ALLOW_REPLAY_POINTER
,
234 else if(ev
->child
== XCB_NONE
)
235 if(globalconf
.screen
->root
== ev
->event
)
237 event_button_callback(ev
, &globalconf
.buttons
, 0, 0, NULL
);
243 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
245 uint16_t config_win_mask
= 0;
246 uint32_t config_win_vals
[7];
247 unsigned short i
= 0;
249 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
251 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
252 config_win_vals
[i
++] = ev
->x
;
254 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
256 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
257 config_win_vals
[i
++] = ev
->y
;
259 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
261 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
262 config_win_vals
[i
++] = ev
->width
;
264 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
266 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
267 config_win_vals
[i
++] = ev
->height
;
269 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
271 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
272 config_win_vals
[i
++] = ev
->border_width
;
274 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
276 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
277 config_win_vals
[i
++] = ev
->sibling
;
279 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
281 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
282 config_win_vals
[i
++] = ev
->stack_mode
;
285 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
288 /** The configure event handler.
289 * \param ev The event.
292 event_handle_configurerequest(xcb_configure_request_event_t
*ev
)
296 if((c
= client_getbywin(ev
->window
)))
298 area_t geometry
= c
->geometry
;
299 int16_t diff_w
= 0, diff_h
= 0, diff_border
= 0;
301 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
303 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
305 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
307 uint16_t old_w
= geometry
.width
;
308 geometry
.width
= ev
->width
;
309 /* The ConfigureRequest specifies the size of the client window, we want the frame */
310 geometry
.width
+= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
311 geometry
.width
+= c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
;
312 diff_w
= geometry
.width
- old_w
;
314 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
316 uint16_t old_h
= geometry
.height
;
317 geometry
.height
= ev
->height
;
318 /* The ConfigureRequest specifies the size of the client window, we want the frame */
319 geometry
.height
+= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
320 geometry
.height
+= c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
321 diff_h
= geometry
.height
- old_h
;
323 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
325 diff_border
= ev
->border_width
- c
->border_width
;
326 diff_h
+= diff_border
;
327 diff_w
+= diff_border
;
329 luaA_object_push(globalconf
.L
, c
);
330 window_set_border_width(globalconf
.L
, -1, ev
->border_width
);
331 lua_pop(globalconf
.L
, 1);
334 /* If the client resizes without moving itself, apply window gravity */
335 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY
)
337 int16_t diff_x
= 0, diff_y
= 0;
338 xwindow_translate_for_gravity(c
->size_hints
.win_gravity
, diff_border
, diff_border
, diff_w
, diff_h
, &diff_x
, &diff_y
);
339 if(!(ev
->value_mask
& XCB_CONFIG_WINDOW_X
))
340 geometry
.x
+= diff_x
;
341 if(!(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
))
342 geometry
.y
+= diff_y
;
345 if(!client_resize(c
, geometry
, false))
346 /* ICCCM 4.1.5 / 4.2.3, if nothing was changed, send an event saying so */
347 client_send_configure(c
);
350 event_handle_configurerequest_configure_window(ev
);
353 /** The configure notify event handler.
354 * \param ev The event.
357 event_handle_configurenotify(xcb_configure_notify_event_t
*ev
)
359 const xcb_screen_t
*screen
= globalconf
.screen
;
361 if(ev
->window
== screen
->root
362 && (ev
->width
!= screen
->width_in_pixels
363 || ev
->height
!= screen
->height_in_pixels
))
364 /* it's not that we panic, but restart */
368 /** The destroy notify event handler.
369 * \param ev The event.
372 event_handle_destroynotify(xcb_destroy_notify_event_t
*ev
)
376 if((c
= client_getbywin(ev
->window
)))
377 client_unmanage(c
, false);
379 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
380 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
382 xembed_window_array_take(&globalconf
.embedded
, i
);
383 luaA_systray_invalidate();
387 /** The motion notify event handler.
388 * \param ev The event.
391 event_handle_motionnotify(xcb_motion_notify_event_t
*ev
)
396 globalconf
.timestamp
= ev
->time
;
398 if(event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
))
401 if((c
= client_getbyframewin(ev
->event
)))
403 luaA_object_push(globalconf
.L
, c
);
404 lua_pushnumber(globalconf
.L
, ev
->event_x
);
405 lua_pushnumber(globalconf
.L
, ev
->event_y
);
406 luaA_object_emit_signal(globalconf
.L
, -3, "mouse::move", 2);
408 /* now check if a titlebar was "hit" */
409 int x
= ev
->event_x
, y
= ev
->event_y
;
410 drawable_t
*d
= client_get_drawable_offset(c
, &x
, &y
);
413 luaA_object_push_item(globalconf
.L
, -1, d
);
414 lua_pushnumber(globalconf
.L
, x
);
415 lua_pushnumber(globalconf
.L
, y
);
416 luaA_object_emit_signal(globalconf
.L
, -3, "mouse::move", 2);
417 lua_pop(globalconf
.L
, 1);
419 lua_pop(globalconf
.L
, 1);
422 if((w
= drawin_getbywin(ev
->event
)))
424 luaA_object_push(globalconf
.L
, w
);
425 luaA_object_push_item(globalconf
.L
, -1, w
->drawable
);
426 lua_pushnumber(globalconf
.L
, ev
->event_x
);
427 lua_pushnumber(globalconf
.L
, ev
->event_y
);
428 luaA_object_emit_signal(globalconf
.L
, -3, "mouse::move", 2);
429 lua_pop(globalconf
.L
, 2);
433 /** The leave notify event handler.
434 * \param ev The event.
437 event_handle_leavenotify(xcb_leave_notify_event_t
*ev
)
442 globalconf
.timestamp
= ev
->time
;
444 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
447 if((c
= client_getbyframewin(ev
->event
)))
449 luaA_object_push(globalconf
.L
, c
);
450 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
451 drawable_t
*d
= client_get_drawable(c
, ev
->event_x
, ev
->event_y
);
454 luaA_object_push_item(globalconf
.L
, -1, d
);
455 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
456 lua_pop(globalconf
.L
, 1);
458 lua_pop(globalconf
.L
, 1);
461 if((drawin
= drawin_getbywin(ev
->event
)))
463 luaA_object_push(globalconf
.L
, drawin
);
464 luaA_object_push_item(globalconf
.L
, -1, drawin
->drawable
);
465 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::leave", 0);
466 lua_pop(globalconf
.L
, 2);
470 /** The enter notify event handler.
471 * \param ev The event.
474 event_handle_enternotify(xcb_enter_notify_event_t
*ev
)
479 globalconf
.timestamp
= ev
->time
;
481 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
484 if((drawin
= drawin_getbywin(ev
->event
)))
486 luaA_object_push(globalconf
.L
, drawin
);
487 luaA_object_push_item(globalconf
.L
, -1, drawin
->drawable
);
488 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
489 lua_pop(globalconf
.L
, 2);
492 if((c
= client_getbyframewin(ev
->event
)))
494 luaA_object_push(globalconf
.L
, c
);
495 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
496 drawable_t
*d
= client_get_drawable(c
, ev
->event_x
, ev
->event_y
);
499 luaA_object_push_item(globalconf
.L
, -1, d
);
500 luaA_object_emit_signal(globalconf
.L
, -1, "mouse::enter", 0);
501 lua_pop(globalconf
.L
, 1);
503 lua_pop(globalconf
.L
, 1);
507 /** The focus in event handler.
508 * \param ev The event.
511 event_handle_focusin(xcb_focus_in_event_t
*ev
)
513 if (ev
->mode
== XCB_NOTIFY_MODE_GRAB
514 || ev
->mode
== XCB_NOTIFY_MODE_UNGRAB
)
515 /* Ignore focus changes due to keyboard grabs */
518 /* Events that we are interested in: */
521 /* These are events that jump between root windows.
523 case XCB_NOTIFY_DETAIL_ANCESTOR
:
524 case XCB_NOTIFY_DETAIL_INFERIOR
:
526 /* These are events that jump between clients.
527 * Virtual events ensure we always get an event on our top-level window.
529 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
530 case XCB_NOTIFY_DETAIL_NONLINEAR
:
534 if((c
= client_getbywin(ev
->event
))) {
535 /* If there is still a pending focus change, do it now. */
536 client_focus_refresh();
537 client_focus_update(c
);
540 /* all other events are ignored */
546 /** The expose event handler.
547 * \param ev The event.
550 event_handle_expose(xcb_expose_event_t
*ev
)
555 if((drawin
= drawin_getbywin(ev
->window
)))
556 drawin_refresh_pixmap_partial(drawin
,
558 ev
->width
, ev
->height
);
559 if ((client
= client_getbyframewin(ev
->window
)))
560 client_refresh_partial(client
, ev
->x
, ev
->y
, ev
->width
, ev
->height
);
563 /** The key press event handler.
564 * \param ev The event.
567 event_handle_key(xcb_key_press_event_t
*ev
)
569 globalconf
.timestamp
= ev
->time
;
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
);
582 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
586 /* get keysym ignoring all modifiers */
587 xcb_keysym_t keysym
= keyresolv_get_keysym(ev
->detail
, 0);
589 if((c
= client_getbyframewin(ev
->event
)))
591 luaA_object_push(globalconf
.L
, c
);
592 event_key_callback(ev
, &c
->keys
, -1, 1, &keysym
);
595 event_key_callback(ev
, &globalconf
.keys
, 0, 0, &keysym
);
599 /** The map request event handler.
600 * \param ev The event.
603 event_handle_maprequest(xcb_map_request_event_t
*ev
)
606 xcb_get_window_attributes_cookie_t wa_c
;
607 xcb_get_window_attributes_reply_t
*wa_r
;
608 xcb_get_geometry_cookie_t geom_c
;
609 xcb_get_geometry_reply_t
*geom_r
;
611 wa_c
= xcb_get_window_attributes_unchecked(globalconf
.connection
, ev
->window
);
613 if(!(wa_r
= xcb_get_window_attributes_reply(globalconf
.connection
, wa_c
, NULL
)))
616 if(wa_r
->override_redirect
)
619 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
621 xcb_map_window(globalconf
.connection
, ev
->window
);
622 xembed_window_activate(globalconf
.connection
, ev
->window
);
624 else if((c
= client_getbywin(ev
->window
)))
626 /* Check that it may be visible, but not asked to be hidden */
627 if(client_maybevisible(c
) && !c
->hidden
)
629 luaA_object_push(globalconf
.L
, c
);
630 client_set_minimized(globalconf
.L
, -1, false);
631 lua_pop(globalconf
.L
, 1);
632 /* it will be raised, so just update ourself */
638 geom_c
= xcb_get_geometry_unchecked(globalconf
.connection
, ev
->window
);
640 if(!(geom_r
= xcb_get_geometry_reply(globalconf
.connection
, geom_c
, NULL
)))
645 client_manage(ev
->window
, geom_r
, wa_r
);
654 /** The unmap notify event handler.
655 * \param ev The event.
658 event_handle_unmapnotify(xcb_unmap_notify_event_t
*ev
)
662 if((c
= client_getbywin(ev
->window
)))
663 client_unmanage(c
, true);
665 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
666 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
668 xembed_window_array_take(&globalconf
.embedded
, i
);
669 xcb_change_save_set(globalconf
.connection
, XCB_SET_MODE_DELETE
, ev
->window
);
670 luaA_systray_invalidate();
674 /** The randr screen change notify event handler.
675 * \param ev The event.
678 event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t
*ev
)
680 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
681 * (only the code relevant to RRScreenChangeNotify) as the latter
682 * doesn't provide this kind of function */
683 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
684 xcb_randr_set_screen_size(globalconf
.connection
, ev
->root
, ev
->height
, ev
->width
,
685 ev
->mheight
, ev
->mwidth
);
687 xcb_randr_set_screen_size(globalconf
.connection
, ev
->root
, ev
->width
, ev
->height
,
688 ev
->mwidth
, ev
->mheight
);
690 /* XRRUpdateConfiguration also executes the following instruction
691 * but it's not useful because SubpixelOrder is not used at all at
694 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
700 /** The shape notify event handler.
701 * \param ev The event.
704 event_handle_shape_notify(xcb_shape_notify_event_t
*ev
)
706 client_t
*c
= client_getbywin(ev
->affected_window
);
709 luaA_object_push(globalconf
.L
, c
);
710 if (ev
->shape_kind
== XCB_SHAPE_SK_BOUNDING
)
711 luaA_object_emit_signal(globalconf
.L
, -1, "property::shape_client_bounding", 0);
712 if (ev
->shape_kind
== XCB_SHAPE_SK_CLIP
)
713 luaA_object_emit_signal(globalconf
.L
, -1, "property::shape_client_clip", 0);
714 lua_pop(globalconf
.L
, 1);
718 /** The client message event handler.
719 * \param ev The event.
722 event_handle_clientmessage(xcb_client_message_event_t
*ev
)
724 /* check for startup notification messages */
725 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
728 if(ev
->type
== WM_CHANGE_STATE
)
731 if((c
= client_getbywin(ev
->window
))
733 && ev
->data
.data32
[0] == XCB_ICCCM_WM_STATE_ICONIC
)
735 luaA_object_push(globalconf
.L
, c
);
736 client_set_minimized(globalconf
.L
, -1, true);
737 lua_pop(globalconf
.L
, 1);
740 else if(ev
->type
== _XEMBED
)
741 xembed_process_client_message(ev
);
742 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
743 systray_process_client_message(ev
);
745 ewmh_process_client_message(ev
);
748 /** The keymap change notify event handler.
749 * \param ev The event.
752 event_handle_mappingnotify(xcb_mapping_notify_event_t
*ev
)
754 if(ev
->request
== XCB_MAPPING_MODIFIER
755 || ev
->request
== XCB_MAPPING_KEYBOARD
)
757 xcb_get_modifier_mapping_cookie_t xmapping_cookie
=
758 xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
760 /* Free and then allocate the key symbols */
761 xcb_key_symbols_free(globalconf
.keysyms
);
762 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
764 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
765 globalconf
.keysyms
, &globalconf
.numlockmask
,
766 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
,
767 &globalconf
.modeswitchmask
);
769 /* regrab everything */
770 xcb_screen_t
*s
= globalconf
.screen
;
771 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
772 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
773 xwindow_grabkeys(s
->root
, &globalconf
.keys
);
775 foreach(_c
, globalconf
.clients
)
778 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->frame_window
, XCB_BUTTON_MASK_ANY
);
779 xwindow_grabkeys(c
->frame_window
, &c
->keys
);
785 event_handle_reparentnotify(xcb_reparent_notify_event_t
*ev
)
789 if((c
= client_getbywin(ev
->window
)) && c
->frame_window
!= ev
->parent
)
791 /* Ignore reparents to the root window, they *might* be caused by
792 * ourselves if a client quickly unmaps and maps itself again. */
793 if (ev
->parent
!= globalconf
.screen
->root
)
794 client_unmanage(c
, true);
798 /** \brief awesome xerror function.
799 * There's no way to check accesses to destroyed windows, thus those cases are
800 * ignored (especially on UnmapNotify's).
801 * \param e The error event.
804 xerror(xcb_generic_error_t
*e
)
807 if(e
->error_code
== XCB_WINDOW
808 || (e
->error_code
== XCB_MATCH
809 && e
->major_code
== XCB_SET_INPUT_FOCUS
)
810 || (e
->error_code
== XCB_VALUE
811 && e
->major_code
== XCB_KILL_CLIENT
)
812 || (e
->error_code
== XCB_MATCH
813 && e
->major_code
== XCB_CONFIGURE_WINDOW
))
816 warn("X error: request=%s (major %d, minor %d), error=%s (%d)",
817 xcb_event_get_request_label(e
->major_code
),
818 e
->major_code
, e
->minor_code
,
819 xcb_event_get_error_label(e
->error_code
),
825 void event_handle(xcb_generic_event_t
*event
)
827 uint8_t response_type
= XCB_EVENT_RESPONSE_TYPE(event
);
829 if(response_type
== 0)
831 /* This is an error, not a event */
832 xerror((xcb_generic_error_t
*) event
);
836 switch(response_type
)
838 #define EVENT(type, callback) case type: callback((void *) event); return
839 EVENT(XCB_BUTTON_PRESS
, event_handle_button
);
840 EVENT(XCB_BUTTON_RELEASE
, event_handle_button
);
841 EVENT(XCB_CONFIGURE_REQUEST
, event_handle_configurerequest
);
842 EVENT(XCB_CONFIGURE_NOTIFY
, event_handle_configurenotify
);
843 EVENT(XCB_DESTROY_NOTIFY
, event_handle_destroynotify
);
844 EVENT(XCB_ENTER_NOTIFY
, event_handle_enternotify
);
845 EVENT(XCB_CLIENT_MESSAGE
, event_handle_clientmessage
);
846 EVENT(XCB_EXPOSE
, event_handle_expose
);
847 EVENT(XCB_FOCUS_IN
, event_handle_focusin
);
848 EVENT(XCB_KEY_PRESS
, event_handle_key
);
849 EVENT(XCB_KEY_RELEASE
, event_handle_key
);
850 EVENT(XCB_LEAVE_NOTIFY
, event_handle_leavenotify
);
851 EVENT(XCB_MAPPING_NOTIFY
, event_handle_mappingnotify
);
852 EVENT(XCB_MAP_REQUEST
, event_handle_maprequest
);
853 EVENT(XCB_MOTION_NOTIFY
, event_handle_motionnotify
);
854 EVENT(XCB_PROPERTY_NOTIFY
, property_handle_propertynotify
);
855 EVENT(XCB_REPARENT_NOTIFY
, event_handle_reparentnotify
);
856 EVENT(XCB_UNMAP_NOTIFY
, event_handle_unmapnotify
);
860 static uint8_t randr_screen_change_notify
= 0;
861 static uint8_t shape_notify
= 0;
863 if(randr_screen_change_notify
== 0)
865 /* check for randr extension */
866 const xcb_query_extension_reply_t
*randr_query
;
867 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
868 if(randr_query
->present
)
869 randr_screen_change_notify
= randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
;
871 if(shape_notify
== 0)
873 /* check for shape extension */
874 const xcb_query_extension_reply_t
*shape_query
;
875 shape_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_shape_id
);
876 if(shape_query
->present
)
877 shape_notify
= shape_query
->first_event
+ XCB_SHAPE_NOTIFY
;
880 if (response_type
== randr_screen_change_notify
)
881 event_handle_randr_screen_change_notify((void *) event
);
882 if (response_type
== shape_notify
)
883 event_handle_shape_notify((void *) event
);
886 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80