xcursor: add new cursor infra
[awesome.git] / event.c
blobc29b9fdd8feb46b9a1621c9e3487cdea84fdd99e
1 /*
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.
22 #include <xcb/xcb.h>
23 #include <xcb/randr.h>
24 #include <xcb/xcb_atom.h>
25 #include <xcb/xcb_icccm.h>
26 #include <xcb/xcb_event.h>
28 #include "awesome.h"
29 #include "event.h"
30 #include "tag.h"
31 #include "window.h"
32 #include "ewmh.h"
33 #include "client.h"
34 #include "widget.h"
35 #include "titlebar.h"
36 #include "keybinding.h"
37 #include "keygrabber.h"
38 #include "luaa.h"
39 #include "systray.h"
40 #include "screen.h"
41 #include "layouts/floating.h"
42 #include "common/atoms.h"
44 extern awesome_t globalconf;
46 /** Handle mouse button events.
47 * \param c The client on which the event happened or NULL.
48 * \param type Event type, press or release.
49 * \param button Button number.
50 * \param state Modkeys state.
51 * \param buttons Buttons array to check for.
53 static void
54 event_handle_mouse_button(client_t *c,
55 uint8_t type,
56 xcb_button_t button,
57 uint16_t state,
58 button_array_t *buttons)
60 for(int i = 0; i < buttons->len; i++)
61 if(button == buttons->tab[i]->button
62 && XUTIL_MASK_CLEAN(state) == buttons->tab[i]->mod)
63 switch(type)
65 case XCB_BUTTON_PRESS:
66 if(buttons->tab[i]->press != LUA_REFNIL)
68 if(c)
70 luaA_client_userdata_new(globalconf.L, c);
71 luaA_dofunction(globalconf.L, buttons->tab[i]->press, 1, 0);
73 else
74 luaA_dofunction(globalconf.L, buttons->tab[i]->press, 0, 0);
76 break;
77 case XCB_BUTTON_RELEASE:
78 if(buttons->tab[i]->release != LUA_REFNIL)
80 if(c)
82 luaA_client_userdata_new(globalconf.L, c);
83 luaA_dofunction(globalconf.L, buttons->tab[i]->release, 1, 0);
85 else
86 luaA_dofunction(globalconf.L, buttons->tab[i]->release, 0, 0);
88 break;
92 /** Get a widget node from a wibox by coords.
93 * \param Container position.
94 * \param widgets The widget list.
95 * \param width The container width.
96 * \param height The container height.
97 * \param x X coordinate of the widget.
98 * \param y Y coordinate of the widget.
99 * \return A widget.
101 static widget_t *
102 widget_getbycoords(position_t position, widget_node_array_t *widgets,
103 int width, int height, int16_t *x, int16_t *y)
105 int tmp;
107 /* Need to transform coordinates like it was top/bottom */
108 switch(position)
110 case Right:
111 tmp = *y;
112 *y = width - *x;
113 *x = tmp;
114 break;
115 case Left:
116 tmp = *y;
117 *y = *x;
118 *x = height - tmp;
119 break;
120 default:
121 break;
124 for(int i = 0; i < widgets->len; i++)
126 widget_node_t *w = &widgets->tab[i];
127 if(w->widget->isvisible &&
128 *x >= w->geometry.x && *x < w->geometry.x + w->geometry.width
129 && *y >= w->geometry.y && *y < w->geometry.y + w->geometry.height)
130 return w->widget;
133 return NULL;
136 /** The button press event handler.
137 * \param data The type of mouse event.
138 * \param connection The connection to the X server.
139 * \param ev The event.
141 static int
142 event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_event_t *ev)
144 int screen;
145 const int nb_screen = xcb_setup_roots_length(xcb_get_setup(connection));
146 client_t *c;
147 widget_t *w;
148 wibox_t *wibox;
150 /* ev->state is
151 * button status (8 bits) + modifiers status (8 bits)
152 * we don't care for button status that we get, especially on release, so
153 * drop them */
154 ev->state &= 0x00ff;
156 if((wibox = wibox_getbywin(ev->event))
157 || (wibox = wibox_getbywin(ev->child)))
159 /* If the wibox is child, then x,y are
160 * relative to root window */
161 if(wibox->sw.window == ev->child)
163 ev->event_x -= wibox->sw.geometry.x;
164 ev->event_y -= wibox->sw.geometry.y;
166 if((w = widget_getbycoords(wibox->position, &wibox->widgets,
167 wibox->sw.geometry.width,
168 wibox->sw.geometry.height,
169 &ev->event_x, &ev->event_y)))
171 button_array_t *b = &w->buttons;
173 for(int i = 0; i < b->len; i++)
174 if(ev->detail == b->tab[i]->button
175 && XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod)
176 switch(ev->response_type)
178 case XCB_BUTTON_PRESS:
179 if(b->tab[i]->press != LUA_REFNIL)
181 luaA_wibox_userdata_new(globalconf.L, wibox);
182 luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0);
184 break;
185 case XCB_BUTTON_RELEASE:
186 if(b->tab[i]->release != LUA_REFNIL)
188 luaA_wibox_userdata_new(globalconf.L, wibox);
189 luaA_dofunction(globalconf.L, b->tab[i]->release, 1, 0);
191 break;
194 /* return even if no widget match */
195 return 0;
198 if((c = client_getbywin(ev->event)))
200 event_handle_mouse_button(c, ev->response_type, ev->detail, ev->state, &c->buttons);
201 xcb_allow_events(globalconf.connection,
202 XCB_ALLOW_REPLAY_POINTER,
203 XCB_CURRENT_TIME);
205 else
206 for(screen = 0; screen < nb_screen; screen++)
207 if(xutil_screen_get(connection, screen)->root == ev->event)
209 event_handle_mouse_button(NULL, ev->response_type, ev->detail, ev->state, &globalconf.buttons);
210 return 0;
213 return 0;
216 /** The configure event handler.
217 * \param data currently unused.
218 * \param connection The connection to the X server.
219 * \param ev The event.
221 static int
222 event_handle_configurerequest(void *data __attribute__ ((unused)),
223 xcb_connection_t *connection, xcb_configure_request_event_t *ev)
225 client_t *c;
226 area_t geometry;
228 if((c = client_getbywin(ev->window)))
230 geometry = c->geometry;
232 if(ev->value_mask & XCB_CONFIG_WINDOW_X)
233 geometry.x = ev->x;
234 if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
235 geometry.y = ev->y;
236 if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
237 geometry.width = ev->width;
238 if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
239 geometry.height = ev->height;
241 if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
242 || geometry.width != c->geometry.width || geometry.height != c->geometry.height)
244 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
246 client_resize(c, geometry, false);
247 if(client_hasstrut(c))
248 /* All the wiboxes (may) need to be repositioned */
249 for(int screen = 0; screen < globalconf.nscreen; screen++)
250 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
252 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
253 wibox_position_update(s);
256 else
258 client_need_arrange(c);
259 /* If we do not resize the client, at least tell it that it
260 * has its new configuration. That fixes at least
261 * gnome-terminal */
262 window_configure(c->win, c->geometry, c->border);
265 else
266 window_configure(c->win, geometry, c->border);
268 else
270 uint16_t config_win_mask = 0;
271 uint32_t config_win_vals[7];
272 unsigned short i = 0;
274 if(ev->value_mask & XCB_CONFIG_WINDOW_X)
276 config_win_mask |= XCB_CONFIG_WINDOW_X;
277 config_win_vals[i++] = ev->x;
279 if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
281 config_win_mask |= XCB_CONFIG_WINDOW_Y;
282 config_win_vals[i++] = ev->y;
284 if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
286 config_win_mask |= XCB_CONFIG_WINDOW_WIDTH;
287 config_win_vals[i++] = ev->width;
289 if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
291 config_win_mask |= XCB_CONFIG_WINDOW_HEIGHT;
292 config_win_vals[i++] = ev->height;
294 if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
296 config_win_mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
297 config_win_vals[i++] = ev->border_width;
299 if(ev->value_mask & XCB_CONFIG_WINDOW_SIBLING)
301 config_win_mask |= XCB_CONFIG_WINDOW_SIBLING;
302 config_win_vals[i++] = ev->sibling;
304 if(ev->value_mask & XCB_CONFIG_WINDOW_STACK_MODE)
306 config_win_mask |= XCB_CONFIG_WINDOW_STACK_MODE;
307 config_win_vals[i++] = ev->stack_mode;
310 xcb_configure_window(connection, ev->window, config_win_mask, config_win_vals);
313 return 0;
316 /** The configure notify event handler.
317 * \param data currently unused.
318 * \param connection The connection to the X server.
319 * \param ev The event.
321 static int
322 event_handle_configurenotify(void *data __attribute__ ((unused)),
323 xcb_connection_t *connection, xcb_configure_notify_event_t *ev)
325 int screen_nbr;
326 const xcb_screen_t *screen;
328 for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup (connection)); screen_nbr++)
329 if((screen = xutil_screen_get(connection, screen_nbr)) != NULL
330 && ev->window == screen->root
331 && (ev->width != screen->width_in_pixels
332 || ev->height != screen->height_in_pixels))
333 /* it's not that we panic, but restart */
334 awesome_restart();
336 return 0;
339 /** The destroy notify event handler.
340 * \param data currently unused.
341 * \param connection The connection to the X server.
342 * \param ev The event.
344 static int
345 event_handle_destroynotify(void *data __attribute__ ((unused)),
346 xcb_connection_t *connection __attribute__ ((unused)),
347 xcb_destroy_notify_event_t *ev)
349 client_t *c;
350 xembed_window_t *emwin;
352 if((c = client_getbywin(ev->window)))
353 client_unmanage(c);
354 else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
356 xembed_window_list_detach(&globalconf.embedded, emwin);
357 for(int i = 0; i < globalconf.nscreen; i++)
358 widget_invalidate_bytype(i, widget_systray);
361 return 0;
364 /** Handle a motion notify over widgets.
365 * \param object The object.
366 * \param mouse_over The pointer to the registered mouse over widget.
367 * \param widget The new widget the mouse is over.
369 static void
370 event_handle_widget_motionnotify(void *object,
371 widget_t **mouse_over,
372 widget_t *widget)
374 if(widget != *mouse_over)
376 if(*mouse_over)
378 if((*mouse_over)->mouse_leave != LUA_REFNIL)
380 /* call mouse leave function on old widget */
381 luaA_wibox_userdata_new(globalconf.L, object);
382 luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
385 if(widget)
387 /* call mouse enter function on new widget and register it */
388 *mouse_over = widget;
389 if(widget->mouse_enter != LUA_REFNIL)
391 luaA_wibox_userdata_new(globalconf.L, object);
392 luaA_dofunction(globalconf.L, widget->mouse_enter, 1, 0);
398 /** The motion notify event handler.
399 * \param data currently unused.
400 * \param connection The connection to the X server.
401 * \param ev The event.
403 static int
404 event_handle_motionnotify(void *data __attribute__ ((unused)),
405 xcb_connection_t *connection,
406 xcb_motion_notify_event_t *ev)
408 wibox_t *wibox = wibox_getbywin(ev->event);
409 widget_t *w;
411 if(wibox
412 && (w = widget_getbycoords(wibox->position, &wibox->widgets,
413 wibox->sw.geometry.width,
414 wibox->sw.geometry.height,
415 &ev->event_x, &ev->event_y)))
417 globalconf.pointer_x = ev->root_x;
418 globalconf.pointer_y = ev->root_y;
419 event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
422 return 0;
425 /** The leave notify event handler.
426 * \param data currently unused.
427 * \param connection The connection to the X server.
428 * \param ev The event.
430 static int
431 event_handle_leavenotify(void *data __attribute__ ((unused)),
432 xcb_connection_t *connection,
433 xcb_leave_notify_event_t *ev)
435 wibox_t *wibox = wibox_getbywin(ev->event);
437 if(wibox && wibox->mouse_over)
439 if(wibox->mouse_over->mouse_leave != LUA_REFNIL)
441 /* call mouse leave function on widget the mouse was over */
442 luaA_wibox_userdata_new(globalconf.L, wibox);
443 luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
445 wibox->mouse_over = NULL;
448 return 0;
451 /** The enter notify event handler.
452 * \param data currently unused.
453 * \param connection The connection to the X server.
454 * \param ev The event.
456 static int
457 event_handle_enternotify(void *data __attribute__ ((unused)),
458 xcb_connection_t *connection,
459 xcb_enter_notify_event_t *ev)
461 client_t *c;
462 xembed_window_t *emwin;
463 wibox_t *wibox;
464 widget_t *w;
466 if(ev->mode != XCB_NOTIFY_MODE_NORMAL
467 || (ev->root_x == globalconf.pointer_x
468 && ev->root_y == globalconf.pointer_y))
469 return 0;
472 if((wibox = wibox_getbywin(ev->event))
473 && (w = widget_getbycoords(wibox->position, &wibox->widgets,
474 wibox->sw.geometry.width,
475 wibox->sw.geometry.height,
476 &ev->event_x, &ev->event_y)))
478 globalconf.pointer_x = ev->root_x;
479 globalconf.pointer_y = ev->root_y;
480 event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
482 else if((c = client_getbytitlebarwin(ev->event))
483 || (c = client_getbywin(ev->event)))
485 window_buttons_grab(c->win, ev->root, &c->buttons);
486 /* The idea behind saving pointer_x and pointer_y is Bob Marley powered.
487 * this will allow us top drop some EnterNotify events and thus not giving
488 * focus to windows appering under the cursor without a cursor move */
489 globalconf.pointer_x = ev->root_x;
490 globalconf.pointer_y = ev->root_y;
492 if(globalconf.hooks.mouse_enter != LUA_REFNIL)
494 luaA_client_userdata_new(globalconf.L, c);
495 luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
498 else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
499 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
500 xutil_screen_get(connection, emwin->phys_screen)->root,
501 XCB_BUTTON_MASK_ANY);
502 else if(ev->event == ev->root)
503 window_root_buttons_grab(ev->root);
505 return 0;
508 /** The expose event handler.
509 * \param data currently unused.
510 * \param connection The connection to the X server.
511 * \param ev The event.
513 static int
514 event_handle_expose(void *data __attribute__ ((unused)),
515 xcb_connection_t *connection __attribute__ ((unused)),
516 xcb_expose_event_t *ev)
518 wibox_t *wibox = wibox_getbywin(ev->window);
520 if(wibox)
521 simplewindow_refresh_pixmap_partial(&wibox->sw,
522 ev->x, ev->y,
523 ev->width, ev->height);
525 return 0;
528 /** The key press event handler.
529 * \param data currently unused.
530 * \param connection The connection to the X server.
531 * \param ev The event.
533 static int
534 event_handle_keypress(void *data __attribute__ ((unused)),
535 xcb_connection_t *connection __attribute__ ((unused)),
536 xcb_key_press_event_t *ev)
538 if(globalconf.keygrabber != LUA_REFNIL)
540 lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber);
541 if(keygrabber_handlekpress(globalconf.L, ev))
543 if(lua_pcall(globalconf.L, 2, 1, 0))
545 warn("error running function: %s", lua_tostring(globalconf.L, -1));
546 luaA_keygrabber_stop(globalconf.L);
548 else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
549 luaA_keygrabber_stop(globalconf.L);
551 lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
553 else
555 keybinding_t *k = keybinding_find(ev);
556 if (k && k->fct != LUA_REFNIL)
557 luaA_dofunction(globalconf.L, k->fct, 0, 0);
560 return 0;
563 /** The map request event handler.
564 * \param data currently unused.
565 * \param connection The connection to the X server.
566 * \param ev The event.
568 static int
569 event_handle_maprequest(void *data __attribute__ ((unused)),
570 xcb_connection_t *connection, xcb_map_request_event_t *ev)
572 int phys_screen, screen = 0, ret = 0;
573 client_t *c;
574 xcb_get_window_attributes_cookie_t wa_c;
575 xcb_get_window_attributes_reply_t *wa_r;
576 xcb_query_pointer_cookie_t qp_c = { 0 };
577 xcb_query_pointer_reply_t *qp_r = NULL;
578 xcb_get_geometry_cookie_t geom_c;
579 xcb_get_geometry_reply_t *geom_r;
581 wa_c = xcb_get_window_attributes_unchecked(connection, ev->window);
583 if(!(wa_r = xcb_get_window_attributes_reply(connection, wa_c, NULL)))
584 return -1;
586 if(wa_r->override_redirect)
587 goto bailout;
589 if(xembed_getbywin(globalconf.embedded, ev->window))
591 xcb_map_window(connection, ev->window);
592 xembed_window_activate(connection, ev->window);
594 else if((c = client_getbywin(ev->window)))
596 /* Check that it may be visible, but not asked to be hidden */
597 if(client_maybevisible(c, c->screen) && !c->ishidden)
599 client_setminimized(c, false);
600 /* it will be raised, so just update ourself */
601 client_raise(c);
604 else
606 geom_c = xcb_get_geometry_unchecked(connection, ev->window);
608 if(globalconf.xinerama_is_active)
609 qp_c = xcb_query_pointer_unchecked(connection,
610 xutil_screen_get(globalconf.connection,
611 globalconf.default_screen)->root);
613 if(!(geom_r = xcb_get_geometry_reply(connection, geom_c, NULL)))
615 if(globalconf.xinerama_is_active)
616 qp_r = xcb_query_pointer_reply(connection, qp_c, NULL);
617 ret = -1;
618 goto bailout;
622 phys_screen = xutil_root2screen(connection, geom_r->root);
624 if(globalconf.xinerama_is_active
625 && (qp_r = xcb_query_pointer_reply(connection, qp_c, NULL)))
626 screen = screen_getbycoord(screen, qp_r->root_x, qp_r->root_y);
627 else
628 screen = phys_screen;
630 client_manage(ev->window, geom_r, phys_screen, screen);
631 p_delete(&geom_r);
634 bailout:
635 p_delete(&qp_r);
636 p_delete(&wa_r);
637 return ret;
640 /** The unmap notify event handler.
641 * \param data currently unused.
642 * \param connection The connection to the X server.
643 * \param ev The event.
645 static int
646 event_handle_unmapnotify(void *data __attribute__ ((unused)),
647 xcb_connection_t *connection, xcb_unmap_notify_event_t *ev)
649 client_t *c;
650 xembed_window_t *em;
652 if((c = client_getbywin(ev->window)))
654 if(ev->event == xutil_screen_get(connection, c->phys_screen)->root
655 && XCB_EVENT_SENT(ev)
656 && window_state_get_reply(window_state_get_unchecked(c->win)) == XCB_WM_STATE_NORMAL)
657 client_unmanage(c);
659 else if((em = xembed_getbywin(globalconf.embedded, ev->window)))
661 xembed_window_list_detach(&globalconf.embedded, em);
662 for(int i = 0; i < globalconf.nscreen; i++)
663 widget_invalidate_bytype(i, widget_systray);
666 return 0;
669 /** The randr screen change notify event handler.
670 * \param data currently unused.
671 * \param connection The connection to the X server.
672 * \param ev The event.
674 static int
675 event_handle_randr_screen_change_notify(void *data __attribute__ ((unused)),
676 xcb_connection_t *connection __attribute__ ((unused)),
677 xcb_randr_screen_change_notify_event_t *ev)
679 if(!globalconf.have_randr)
680 return -1;
682 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
683 * (only the code relevant to RRScreenChangeNotify) as the latter
684 * doesn't provide this kind of function */
685 if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270))
686 xcb_randr_set_screen_size(connection, ev->root, ev->height, ev->width,
687 ev->mheight, ev->mwidth);
688 else
689 xcb_randr_set_screen_size(connection, ev->root, ev->width, ev->height,
690 ev->mwidth, ev->mheight);
692 /* XRRUpdateConfiguration also executes the following instruction
693 * but it's not useful because SubpixelOrder is not used at all at
694 * the moment
696 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
699 awesome_restart();
701 return 0;
704 /** The client message event handler.
705 * \param data currently unused.
706 * \param connection The connection to the X server.
707 * \param ev The event.
709 static int
710 event_handle_clientmessage(void *data __attribute__ ((unused)),
711 xcb_connection_t *connection,
712 xcb_client_message_event_t *ev)
714 client_t *c;
716 if(ev->type == WM_CHANGE_STATE)
718 if((c = client_getbywin(ev->window))
719 && ev->format == 32
720 && ev->data.data32[0] == XCB_WM_STATE_ICONIC)
721 client_setminimized(c, true);
723 else if(ev->type == _XEMBED)
724 return xembed_process_client_message(ev);
725 else if(ev->type == _NET_SYSTEM_TRAY_OPCODE)
726 return systray_process_client_message(ev);
727 return ewmh_process_client_message(ev);
730 /** The keymap change notify event handler.
731 * \param data Unused data.
732 * \param connection The connection to the X server.
733 * \param ev The event.
734 * \return Status code, 0 if everything's fine.
736 static int
737 event_handle_mappingnotify(void *data,
738 xcb_connection_t *connection,
739 xcb_mapping_notify_event_t *ev)
741 xcb_get_modifier_mapping_cookie_t xmapping_cookie;
743 if(ev->request == XCB_MAPPING_MODIFIER
744 || ev->request == XCB_MAPPING_KEYBOARD)
746 int nscreen = xcb_setup_roots_length(xcb_get_setup(connection));
747 int phys_screen = 0;
749 /* Send the request to get the NumLock, ShiftLock and CapsLock masks */
750 xmapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection);
752 /* Free and then allocate the key symbols */
753 xcb_key_symbols_free(globalconf.keysyms);
754 globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection);
756 /* Process the reply of previously sent mapping request */
757 xutil_lock_mask_get(globalconf.connection, xmapping_cookie,
758 globalconf.keysyms, &globalconf.numlockmask,
759 &globalconf.shiftlockmask, &globalconf.capslockmask);
763 xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
764 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look
765 * weird */
766 xcb_ungrab_key(connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY);
767 phys_screen++;
768 } while(phys_screen < nscreen);
770 /* regrab everything */
771 keybinding_array_t *arr = &globalconf.keys.by_sym;
772 for(int i = 0; i < arr->len; i++)
773 window_root_grabkey(arr->tab[i]);
775 arr = &globalconf.keys.by_code;
776 for(int i = 0; i < arr->len; i++)
777 window_root_grabkey(arr->tab[i]);
780 return 0;
783 static int
784 event_handle_reparentnotify(void *data,
785 xcb_connection_t *connection,
786 xcb_reparent_notify_event_t *ev)
788 client_t *c;
790 if((c = client_getbywin(ev->window)))
791 client_unmanage(c);
793 return 0;
796 void a_xcb_set_event_handlers(void)
798 const xcb_query_extension_reply_t *randr_query;
800 xcb_event_set_button_press_handler(&globalconf.evenths, event_handle_button, NULL);
801 xcb_event_set_button_release_handler(&globalconf.evenths, event_handle_button, NULL);
802 xcb_event_set_configure_request_handler(&globalconf.evenths, event_handle_configurerequest, NULL);
803 xcb_event_set_configure_notify_handler(&globalconf.evenths, event_handle_configurenotify, NULL);
804 xcb_event_set_destroy_notify_handler(&globalconf.evenths, event_handle_destroynotify, NULL);
805 xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL);
806 xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL);
807 xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL);
808 xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL);
809 xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_keypress, NULL);
810 xcb_event_set_map_request_handler(&globalconf.evenths, event_handle_maprequest, NULL);
811 xcb_event_set_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL);
812 xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL);
813 xcb_event_set_mapping_notify_handler(&globalconf.evenths, event_handle_mappingnotify, NULL);
814 xcb_event_set_reparent_notify_handler(&globalconf.evenths, event_handle_reparentnotify, NULL);
816 /* check for randr extension */
817 randr_query = xcb_get_extension_data(globalconf.connection, &xcb_randr_id);
818 if((globalconf.have_randr = randr_query->present))
819 xcb_event_set_handler(&globalconf.evenths,
820 randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
821 (xcb_generic_event_handler_t) event_handle_randr_screen_change_notify,
822 NULL);
826 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80