draw: fix text alignment on small width
[awesome.git] / event.c
blob96b88d525c6629abe8d54c21807e9170eea5174c
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 node.
101 static widget_node_t *
102 widget_getbycoords(position_t position, widget_node_array_t *widgets, int width, int height, int16_t *x, int16_t *y)
104 int tmp;
106 /* Need to transform coordinates like it was top/bottom */
107 switch(position)
109 case Right:
110 tmp = *y;
111 *y = width - *x;
112 *x = tmp;
113 break;
114 case Left:
115 tmp = *y;
116 *y = *x;
117 *x = height - tmp;
118 break;
119 default:
120 break;
123 for(int i = 0; i < widgets->len; i++)
125 widget_node_t *w = &widgets->tab[i];
126 if(w->widget->isvisible &&
127 *x >= w->geometry.x && *x < w->geometry.x + w->geometry.width
128 && *y >= w->geometry.y && *y < w->geometry.y + w->geometry.height)
129 return w;
132 return NULL;
135 /** The button press event handler.
136 * \param data The type of mouse event.
137 * \param connection The connection to the X server.
138 * \param ev The event.
140 static int
141 event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_event_t *ev)
143 int screen;
144 const int nb_screen = xcb_setup_roots_length(xcb_get_setup(connection));
145 client_t *c;
146 widget_node_t *w;
147 wibox_t *wibox;
149 /* ev->state is
150 * button status (8 bits) + modifiers status (8 bits)
151 * we don't care for button status that we get, especially on release, so
152 * drop them */
153 ev->state &= 0x00ff;
155 if((wibox = wibox_getbywin(ev->event))
156 || (wibox = wibox_getbywin(ev->child)))
158 /* If the wibox is child, then x,y are
159 * relative to root window */
160 if(wibox->sw.window == ev->child)
162 ev->event_x -= wibox->sw.geometry.x;
163 ev->event_y -= wibox->sw.geometry.y;
165 if((w = widget_getbycoords(wibox->position, &wibox->widgets,
166 wibox->sw.geometry.width,
167 wibox->sw.geometry.height,
168 &ev->event_x, &ev->event_y)))
169 w->widget->button(w, ev, wibox->screen, wibox);
170 /* return even if no widget match */
171 return 0;
174 if((c = client_getbywin(ev->event)))
176 event_handle_mouse_button(c, ev->response_type, ev->detail, ev->state, &c->buttons);
177 xcb_allow_events(globalconf.connection,
178 XCB_ALLOW_REPLAY_POINTER,
179 XCB_CURRENT_TIME);
181 else
182 for(screen = 0; screen < nb_screen; screen++)
183 if(xutil_screen_get(connection, screen)->root == ev->event)
185 event_handle_mouse_button(NULL, ev->response_type, ev->detail, ev->state, &globalconf.buttons);
186 return 0;
189 return 0;
192 /** The configure event handler.
193 * \param data currently unused.
194 * \param connection The connection to the X server.
195 * \param ev The event.
197 static int
198 event_handle_configurerequest(void *data __attribute__ ((unused)),
199 xcb_connection_t *connection, xcb_configure_request_event_t *ev)
201 client_t *c;
202 area_t geometry;
204 if((c = client_getbywin(ev->window)))
206 geometry = c->geometry;
208 if(ev->value_mask & XCB_CONFIG_WINDOW_X)
209 geometry.x = ev->x;
210 if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
211 geometry.y = ev->y;
212 if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
213 geometry.width = ev->width;
214 if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
215 geometry.height = ev->height;
217 if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
218 || geometry.width != c->geometry.width || geometry.height != c->geometry.height)
220 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
222 client_resize(c, geometry, false);
223 if(client_hasstrut(c))
224 /* All the wiboxes (may) need to be repositioned */
225 for(int screen = 0; screen < globalconf.nscreen; screen++)
226 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
228 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
229 wibox_position_update(s);
232 else
234 client_need_arrange(c);
235 /* If we do not resize the client, at least tell it that it
236 * has its new configuration. That fixes at least
237 * gnome-terminal */
238 window_configure(c->win, c->geometry, c->border);
241 else
242 window_configure(c->win, geometry, c->border);
244 else
246 uint16_t config_win_mask = 0;
247 uint32_t config_win_vals[7];
248 unsigned short i = 0;
250 if(ev->value_mask & XCB_CONFIG_WINDOW_X)
252 config_win_mask |= XCB_CONFIG_WINDOW_X;
253 config_win_vals[i++] = ev->x;
255 if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
257 config_win_mask |= XCB_CONFIG_WINDOW_Y;
258 config_win_vals[i++] = ev->y;
260 if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
262 config_win_mask |= XCB_CONFIG_WINDOW_WIDTH;
263 config_win_vals[i++] = ev->width;
265 if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
267 config_win_mask |= XCB_CONFIG_WINDOW_HEIGHT;
268 config_win_vals[i++] = ev->height;
270 if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
272 config_win_mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
273 config_win_vals[i++] = ev->border_width;
275 if(ev->value_mask & XCB_CONFIG_WINDOW_SIBLING)
277 config_win_mask |= XCB_CONFIG_WINDOW_SIBLING;
278 config_win_vals[i++] = ev->sibling;
280 if(ev->value_mask & XCB_CONFIG_WINDOW_STACK_MODE)
282 config_win_mask |= XCB_CONFIG_WINDOW_STACK_MODE;
283 config_win_vals[i++] = ev->stack_mode;
286 xcb_configure_window(connection, ev->window, config_win_mask, config_win_vals);
289 return 0;
292 /** The configure notify event handler.
293 * \param data currently unused.
294 * \param connection The connection to the X server.
295 * \param ev The event.
297 static int
298 event_handle_configurenotify(void *data __attribute__ ((unused)),
299 xcb_connection_t *connection, xcb_configure_notify_event_t *ev)
301 int screen_nbr;
302 const xcb_screen_t *screen;
304 for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup (connection)); screen_nbr++)
305 if((screen = xutil_screen_get(connection, screen_nbr)) != NULL
306 && ev->window == screen->root
307 && (ev->width != screen->width_in_pixels
308 || ev->height != screen->height_in_pixels))
309 /* it's not that we panic, but restart */
310 awesome_restart();
312 return 0;
315 /** The destroy notify event handler.
316 * \param data currently unused.
317 * \param connection The connection to the X server.
318 * \param ev The event.
320 static int
321 event_handle_destroynotify(void *data __attribute__ ((unused)),
322 xcb_connection_t *connection __attribute__ ((unused)),
323 xcb_destroy_notify_event_t *ev)
325 client_t *c;
326 xembed_window_t *emwin;
327 int i;
329 if((c = client_getbywin(ev->window)))
330 client_unmanage(c);
331 else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
333 xembed_window_list_detach(&globalconf.embedded, emwin);
334 for(i = 0; i < globalconf.nscreen; i++)
335 widget_invalidate_cache(i, WIDGET_CACHE_EMBEDDED);
338 return 0;
341 /** Handle a motion notify over widgets.
342 * \param object The object.
343 * \param mouse_over The pointer to the registered mouse over widget.
344 * \param w The new widget the mouse is over.
346 static void
347 event_handle_widget_motionnotify(void *object,
348 widget_t **mouse_over,
349 widget_node_t *w)
351 if(w->widget != *mouse_over)
353 if(*mouse_over)
355 if((*mouse_over)->mouse_leave != LUA_REFNIL)
357 /* call mouse leave function on old widget */
358 luaA_wibox_userdata_new(globalconf.L, object);
359 luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
362 if(w)
364 /* call mouse enter function on new widget and register it */
365 *mouse_over = w->widget;
366 if(w->widget->mouse_enter != LUA_REFNIL)
368 luaA_wibox_userdata_new(globalconf.L, object);
369 luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0);
375 /** The motion notify event handler.
376 * \param data currently unused.
377 * \param connection The connection to the X server.
378 * \param ev The event.
380 static int
381 event_handle_motionnotify(void *data __attribute__ ((unused)),
382 xcb_connection_t *connection,
383 xcb_motion_notify_event_t *ev)
385 wibox_t *wibox = wibox_getbywin(ev->event);
386 widget_node_t *w;
388 if(wibox
389 && (w = widget_getbycoords(wibox->position, &wibox->widgets,
390 wibox->sw.geometry.width,
391 wibox->sw.geometry.height,
392 &ev->event_x, &ev->event_y)))
394 globalconf.pointer_x = ev->root_x;
395 globalconf.pointer_y = ev->root_y;
396 event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
399 return 0;
402 /** The leave notify event handler.
403 * \param data currently unused.
404 * \param connection The connection to the X server.
405 * \param ev The event.
407 static int
408 event_handle_leavenotify(void *data __attribute__ ((unused)),
409 xcb_connection_t *connection,
410 xcb_leave_notify_event_t *ev)
412 wibox_t *wibox = wibox_getbywin(ev->event);
414 if(wibox && wibox->mouse_over)
416 if(wibox->mouse_over->mouse_leave != LUA_REFNIL)
418 /* call mouse leave function on widget the mouse was over */
419 luaA_wibox_userdata_new(globalconf.L, wibox);
420 luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
422 wibox->mouse_over = NULL;
425 return 0;
428 /** The enter notify event handler.
429 * \param data currently unused.
430 * \param connection The connection to the X server.
431 * \param ev The event.
433 static int
434 event_handle_enternotify(void *data __attribute__ ((unused)),
435 xcb_connection_t *connection,
436 xcb_enter_notify_event_t *ev)
438 client_t *c;
439 xembed_window_t *emwin;
440 wibox_t *wibox;
441 widget_node_t *w;
443 if(ev->mode != XCB_NOTIFY_MODE_NORMAL
444 || (ev->root_x == globalconf.pointer_x
445 && ev->root_y == globalconf.pointer_y))
446 return 0;
449 if((wibox = wibox_getbywin(ev->event))
450 && (w = widget_getbycoords(wibox->position, &wibox->widgets,
451 wibox->sw.geometry.width,
452 wibox->sw.geometry.height,
453 &ev->event_x, &ev->event_y)))
455 globalconf.pointer_x = ev->root_x;
456 globalconf.pointer_y = ev->root_y;
457 event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
459 else if((c = client_getbytitlebarwin(ev->event))
460 || (c = client_getbywin(ev->event)))
462 window_buttons_grab(c->win, ev->root, &c->buttons);
463 /* The idea behind saving pointer_x and pointer_y is Bob Marley powered.
464 * this will allow us top drop some EnterNotify events and thus not giving
465 * focus to windows appering under the cursor without a cursor move */
466 globalconf.pointer_x = ev->root_x;
467 globalconf.pointer_y = ev->root_y;
469 if(globalconf.hooks.mouse_enter != LUA_REFNIL)
471 luaA_client_userdata_new(globalconf.L, c);
472 luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
475 else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
476 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
477 xutil_screen_get(connection, emwin->phys_screen)->root,
478 XCB_BUTTON_MASK_ANY);
479 else if(ev->event == ev->root)
480 window_root_buttons_grab(ev->root);
482 return 0;
485 /** The expose event handler.
486 * \param data currently unused.
487 * \param connection The connection to the X server.
488 * \param ev The event.
490 static int
491 event_handle_expose(void *data __attribute__ ((unused)),
492 xcb_connection_t *connection __attribute__ ((unused)),
493 xcb_expose_event_t *ev)
495 wibox_t *wibox = wibox_getbywin(ev->window);
497 if(wibox)
498 simplewindow_refresh_pixmap_partial(&wibox->sw,
499 ev->x, ev->y,
500 ev->width, ev->height);
502 return 0;
505 /** The key press event handler.
506 * \param data currently unused.
507 * \param connection The connection to the X server.
508 * \param ev The event.
510 static int
511 event_handle_keypress(void *data __attribute__ ((unused)),
512 xcb_connection_t *connection __attribute__ ((unused)),
513 xcb_key_press_event_t *ev)
515 if(globalconf.keygrabber != LUA_REFNIL)
517 lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber);
518 if(keygrabber_handlekpress(globalconf.L, ev))
520 if(lua_pcall(globalconf.L, 2, 1, 0))
522 warn("error running function: %s", lua_tostring(globalconf.L, -1));
523 luaA_keygrabber_stop(globalconf.L);
525 else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
526 luaA_keygrabber_stop(globalconf.L);
528 lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
530 else
532 keybinding_t *k = keybinding_find(ev);
533 if (k && k->fct != LUA_REFNIL)
534 luaA_dofunction(globalconf.L, k->fct, 0, 0);
537 return 0;
540 /** The map request event handler.
541 * \param data currently unused.
542 * \param connection The connection to the X server.
543 * \param ev The event.
545 static int
546 event_handle_maprequest(void *data __attribute__ ((unused)),
547 xcb_connection_t *connection, xcb_map_request_event_t *ev)
549 int phys_screen, screen = 0, ret = 0;
550 client_t *c;
551 xcb_get_window_attributes_cookie_t wa_c;
552 xcb_get_window_attributes_reply_t *wa_r;
553 xcb_query_pointer_cookie_t qp_c = { 0 };
554 xcb_query_pointer_reply_t *qp_r = NULL;
555 xcb_get_geometry_cookie_t geom_c;
556 xcb_get_geometry_reply_t *geom_r;
558 wa_c = xcb_get_window_attributes_unchecked(connection, ev->window);
560 if(!(wa_r = xcb_get_window_attributes_reply(connection, wa_c, NULL)))
561 return -1;
563 if(wa_r->override_redirect)
564 goto bailout;
566 if(xembed_getbywin(globalconf.embedded, ev->window))
568 xcb_map_window(connection, ev->window);
569 xembed_window_activate(connection, ev->window);
571 else if((c = client_getbywin(ev->window)))
573 /* Check that it may be visible, but not asked to be hidden */
574 if(client_maybevisible(c, c->screen) && !c->ishidden)
576 client_setminimized(c, false);
577 /* it will be raised, so just update ourself */
578 client_raise(c);
581 else
583 geom_c = xcb_get_geometry_unchecked(connection, ev->window);
585 if(globalconf.xinerama_is_active)
586 qp_c = xcb_query_pointer_unchecked(connection,
587 xutil_screen_get(globalconf.connection,
588 globalconf.default_screen)->root);
590 if(!(geom_r = xcb_get_geometry_reply(connection, geom_c, NULL)))
592 if(globalconf.xinerama_is_active)
593 qp_r = xcb_query_pointer_reply(connection, qp_c, NULL);
594 ret = -1;
595 goto bailout;
599 phys_screen = xutil_root2screen(connection, geom_r->root);
601 if(globalconf.xinerama_is_active
602 && (qp_r = xcb_query_pointer_reply(connection, qp_c, NULL)))
603 screen = screen_getbycoord(screen, qp_r->root_x, qp_r->root_y);
604 else
605 screen = phys_screen;
607 client_manage(ev->window, geom_r, phys_screen, screen);
608 p_delete(&geom_r);
611 bailout:
612 p_delete(&qp_r);
613 p_delete(&wa_r);
614 return ret;
617 /** The unmap notify event handler.
618 * \param data currently unused.
619 * \param connection The connection to the X server.
620 * \param ev The event.
622 static int
623 event_handle_unmapnotify(void *data __attribute__ ((unused)),
624 xcb_connection_t *connection, xcb_unmap_notify_event_t *ev)
626 client_t *c;
627 xembed_window_t *em;
628 int i;
630 if((c = client_getbywin(ev->window)))
632 if(ev->event == xutil_screen_get(connection, c->phys_screen)->root
633 && XCB_EVENT_SENT(ev)
634 && window_state_get_reply(window_state_get_unchecked(c->win)) == XCB_WM_STATE_NORMAL)
635 client_unmanage(c);
637 else if((em = xembed_getbywin(globalconf.embedded, ev->window)))
639 xembed_window_list_detach(&globalconf.embedded, em);
640 for(i = 0; i < globalconf.nscreen; i++)
641 widget_invalidate_cache(i, WIDGET_CACHE_EMBEDDED);
644 return 0;
647 /** The randr screen change notify event handler.
648 * \param data currently unused.
649 * \param connection The connection to the X server.
650 * \param ev The event.
652 static int
653 event_handle_randr_screen_change_notify(void *data __attribute__ ((unused)),
654 xcb_connection_t *connection __attribute__ ((unused)),
655 xcb_randr_screen_change_notify_event_t *ev)
657 if(!globalconf.have_randr)
658 return -1;
660 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
661 * (only the code relevant to RRScreenChangeNotify) as the latter
662 * doesn't provide this kind of function */
663 if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270))
664 xcb_randr_set_screen_size(connection, ev->root, ev->height, ev->width,
665 ev->mheight, ev->mwidth);
666 else
667 xcb_randr_set_screen_size(connection, ev->root, ev->width, ev->height,
668 ev->mwidth, ev->mheight);
670 /* XRRUpdateConfiguration also executes the following instruction
671 * but it's not useful because SubpixelOrder is not used at all at
672 * the moment
674 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
677 awesome_restart();
679 return 0;
682 /** The client message event handler.
683 * \param data currently unused.
684 * \param connection The connection to the X server.
685 * \param ev The event.
687 static int
688 event_handle_clientmessage(void *data __attribute__ ((unused)),
689 xcb_connection_t *connection,
690 xcb_client_message_event_t *ev)
692 client_t *c;
694 if(ev->type == WM_CHANGE_STATE)
696 if((c = client_getbywin(ev->window))
697 && ev->format == 32
698 && ev->data.data32[0] == XCB_WM_STATE_ICONIC)
699 client_setminimized(c, true);
701 else if(ev->type == _XEMBED)
702 return xembed_process_client_message(ev);
703 else if(ev->type == _NET_SYSTEM_TRAY_OPCODE)
704 return systray_process_client_message(ev);
705 return ewmh_process_client_message(ev);
708 /** The keymap change notify event handler.
709 * \param data Unused data.
710 * \param connection The connection to the X server.
711 * \param ev The event.
712 * \return Status code, 0 if everything's fine.
714 static int
715 event_handle_mappingnotify(void *data,
716 xcb_connection_t *connection,
717 xcb_mapping_notify_event_t *ev)
719 xcb_get_modifier_mapping_cookie_t xmapping_cookie;
721 if(ev->request == XCB_MAPPING_MODIFIER
722 || ev->request == XCB_MAPPING_KEYBOARD)
724 int nscreen = xcb_setup_roots_length(xcb_get_setup(connection));
725 int phys_screen = 0;
727 /* Send the request to get the NumLock, ShiftLock and CapsLock masks */
728 xmapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection);
730 /* Free and then allocate the key symbols */
731 xcb_key_symbols_free(globalconf.keysyms);
732 globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection);
734 /* Process the reply of previously sent mapping request */
735 xutil_lock_mask_get(globalconf.connection, xmapping_cookie,
736 globalconf.keysyms, &globalconf.numlockmask,
737 &globalconf.shiftlockmask, &globalconf.capslockmask);
741 xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
742 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look
743 * weird */
744 xcb_ungrab_key(connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY);
745 phys_screen++;
746 } while(phys_screen < nscreen);
748 /* regrab everything */
749 keybinding_array_t *arr = &globalconf.keys.by_sym;
750 for(int i = 0; i < arr->len; i++)
751 window_root_grabkey(arr->tab[i]);
753 arr = &globalconf.keys.by_code;
754 for(int i = 0; i < arr->len; i++)
755 window_root_grabkey(arr->tab[i]);
758 return 0;
761 static int
762 event_handle_reparentnotify(void *data,
763 xcb_connection_t *connection,
764 xcb_reparent_notify_event_t *ev)
766 client_t *c;
768 if((c = client_getbywin(ev->window)))
769 client_unmanage(c);
771 return 0;
774 void a_xcb_set_event_handlers(void)
776 const xcb_query_extension_reply_t *randr_query;
778 xcb_event_set_button_press_handler(&globalconf.evenths, event_handle_button, NULL);
779 xcb_event_set_button_release_handler(&globalconf.evenths, event_handle_button, NULL);
780 xcb_event_set_configure_request_handler(&globalconf.evenths, event_handle_configurerequest, NULL);
781 xcb_event_set_configure_notify_handler(&globalconf.evenths, event_handle_configurenotify, NULL);
782 xcb_event_set_destroy_notify_handler(&globalconf.evenths, event_handle_destroynotify, NULL);
783 xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL);
784 xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL);
785 xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL);
786 xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL);
787 xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_keypress, NULL);
788 xcb_event_set_map_request_handler(&globalconf.evenths, event_handle_maprequest, NULL);
789 xcb_event_set_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL);
790 xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL);
791 xcb_event_set_mapping_notify_handler(&globalconf.evenths, event_handle_mappingnotify, NULL);
792 xcb_event_set_reparent_notify_handler(&globalconf.evenths, event_handle_reparentnotify, NULL);
794 /* check for randr extension */
795 randr_query = xcb_get_extension_data(globalconf.connection, &xcb_randr_id);
796 if((globalconf.have_randr = randr_query->present))
797 xcb_event_set_handler(&globalconf.evenths,
798 randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
799 (xcb_generic_event_handler_t) event_handle_randr_screen_change_notify,
800 NULL);
804 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80