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>
36 #include "keybinding.h"
37 #include "keygrabber.h"
38 #include "mousegrabber.h"
42 #include "layouts/floating.h"
43 #include "common/atoms.h"
45 extern awesome_t globalconf
;
47 /** Handle mouse button events.
48 * \param c The client on which the event happened or NULL.
49 * \param type Event type, press or release.
50 * \param button Button number.
51 * \param state Modkeys state.
52 * \param buttons Buttons array to check for.
55 event_handle_mouse_button(client_t
*c
,
59 button_array_t
*buttons
)
61 for(int i
= 0; i
< buttons
->len
; i
++)
62 if(button
== buttons
->tab
[i
]->button
63 && XUTIL_MASK_CLEAN(state
) == buttons
->tab
[i
]->mod
)
66 case XCB_BUTTON_PRESS
:
67 if(buttons
->tab
[i
]->press
!= LUA_REFNIL
)
71 luaA_client_userdata_new(globalconf
.L
, c
);
72 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->press
, 1, 0);
75 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->press
, 0, 0);
78 case XCB_BUTTON_RELEASE
:
79 if(buttons
->tab
[i
]->release
!= LUA_REFNIL
)
83 luaA_client_userdata_new(globalconf
.L
, c
);
84 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->release
, 1, 0);
87 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->release
, 0, 0);
93 /** Get a widget node from a wibox by coords.
94 * \param Container position.
95 * \param widgets The widget list.
96 * \param width The container width.
97 * \param height The container height.
98 * \param x X coordinate of the widget.
99 * \param y Y coordinate of the widget.
103 widget_getbycoords(position_t position
, widget_node_array_t
*widgets
,
104 int width
, int height
, int16_t *x
, int16_t *y
)
108 /* Need to transform coordinates like it was top/bottom */
125 for(int i
= 0; i
< widgets
->len
; i
++)
127 widget_node_t
*w
= &widgets
->tab
[i
];
128 if(w
->widget
->isvisible
&&
129 *x
>= w
->geometry
.x
&& *x
< w
->geometry
.x
+ w
->geometry
.width
130 && *y
>= w
->geometry
.y
&& *y
< w
->geometry
.y
+ w
->geometry
.height
)
137 /** Handle an event with mouse grabber if needed
138 * \param x The x coordinate.
139 * \param y The y coordinate.
140 * \param mask The mask buttons.
143 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
145 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
147 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
148 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
149 if(lua_pcall(globalconf
.L
, 1, 1, 0))
151 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
152 luaA_mousegrabber_stop(globalconf
.L
);
154 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
155 luaA_mousegrabber_stop(globalconf
.L
);
156 lua_pop(globalconf
.L
, 1); /* pop returned value */
160 /** The button press event handler.
161 * \param data The type of mouse event.
162 * \param connection The connection to the X server.
163 * \param ev The event.
166 event_handle_button(void *data
, xcb_connection_t
*connection
, xcb_button_press_event_t
*ev
)
169 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(connection
));
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 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
182 if((wibox
= wibox_getbywin(ev
->event
))
183 || (wibox
= wibox_getbywin(ev
->child
)))
185 /* If the wibox is child, then x,y are
186 * relative to root window */
187 if(wibox
->sw
.window
== ev
->child
)
189 ev
->event_x
-= wibox
->sw
.geometry
.x
;
190 ev
->event_y
-= wibox
->sw
.geometry
.y
;
192 if((w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
193 wibox
->sw
.geometry
.width
,
194 wibox
->sw
.geometry
.height
,
195 &ev
->event_x
, &ev
->event_y
)))
197 button_array_t
*b
= &w
->buttons
;
199 for(int i
= 0; i
< b
->len
; i
++)
200 if(ev
->detail
== b
->tab
[i
]->button
201 && XUTIL_MASK_CLEAN(ev
->state
) == b
->tab
[i
]->mod
)
202 switch(ev
->response_type
)
204 case XCB_BUTTON_PRESS
:
205 if(b
->tab
[i
]->press
!= LUA_REFNIL
)
207 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
208 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->press
, 1, 0);
211 case XCB_BUTTON_RELEASE
:
212 if(b
->tab
[i
]->release
!= LUA_REFNIL
)
214 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
215 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->release
, 1, 0);
220 /* return even if no widget match */
224 if((c
= client_getbywin(ev
->event
)))
226 event_handle_mouse_button(c
, ev
->response_type
, ev
->detail
, ev
->state
, &c
->buttons
);
227 xcb_allow_events(globalconf
.connection
,
228 XCB_ALLOW_REPLAY_POINTER
,
232 for(screen
= 0; screen
< nb_screen
; screen
++)
233 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
235 event_handle_mouse_button(NULL
, ev
->response_type
, ev
->detail
, ev
->state
, &globalconf
.buttons
);
242 /** The configure event handler.
243 * \param data currently unused.
244 * \param connection The connection to the X server.
245 * \param ev The event.
248 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
249 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
254 if((c
= client_getbywin(ev
->window
)))
256 geometry
= c
->geometry
;
258 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
260 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
262 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
263 geometry
.width
= ev
->width
;
264 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
265 geometry
.height
= ev
->height
;
267 if(geometry
.x
!= c
->geometry
.x
|| geometry
.y
!= c
->geometry
.y
268 || geometry
.width
!= c
->geometry
.width
|| geometry
.height
!= c
->geometry
.height
)
270 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
272 client_resize(c
, geometry
, false);
273 if(client_hasstrut(c
))
274 /* All the wiboxes (may) need to be repositioned */
275 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
276 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
278 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
279 wibox_position_update(s
);
284 client_need_arrange(c
);
285 /* If we do not resize the client, at least tell it that it
286 * has its new configuration. That fixes at least
288 window_configure(c
->win
, c
->geometry
, c
->border
);
292 window_configure(c
->win
, geometry
, c
->border
);
296 uint16_t config_win_mask
= 0;
297 uint32_t config_win_vals
[7];
298 unsigned short i
= 0;
300 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
302 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
303 config_win_vals
[i
++] = ev
->x
;
305 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
307 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
308 config_win_vals
[i
++] = ev
->y
;
310 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
312 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
313 config_win_vals
[i
++] = ev
->width
;
315 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
317 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
318 config_win_vals
[i
++] = ev
->height
;
320 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
322 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
323 config_win_vals
[i
++] = ev
->border_width
;
325 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
327 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
328 config_win_vals
[i
++] = ev
->sibling
;
330 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
332 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
333 config_win_vals
[i
++] = ev
->stack_mode
;
336 xcb_configure_window(connection
, ev
->window
, config_win_mask
, config_win_vals
);
342 /** The configure notify event handler.
343 * \param data currently unused.
344 * \param connection The connection to the X server.
345 * \param ev The event.
348 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
349 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
352 const xcb_screen_t
*screen
;
354 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
355 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
356 && ev
->window
== screen
->root
357 && (ev
->width
!= screen
->width_in_pixels
358 || ev
->height
!= screen
->height_in_pixels
))
359 /* it's not that we panic, but restart */
365 /** The destroy notify event handler.
366 * \param data currently unused.
367 * \param connection The connection to the X server.
368 * \param ev The event.
371 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
372 xcb_connection_t
*connection
__attribute__ ((unused
)),
373 xcb_destroy_notify_event_t
*ev
)
376 xembed_window_t
*emwin
;
378 if((c
= client_getbywin(ev
->window
)))
380 else if((emwin
= xembed_getbywin(globalconf
.embedded
, ev
->event
)))
382 xembed_window_list_detach(&globalconf
.embedded
, emwin
);
383 for(int i
= 0; i
< globalconf
.nscreen
; i
++)
384 widget_invalidate_bytype(i
, widget_systray
);
390 /** Handle a motion notify over widgets.
391 * \param object The object.
392 * \param mouse_over The pointer to the registered mouse over widget.
393 * \param widget The new widget the mouse is over.
396 event_handle_widget_motionnotify(void *object
,
397 widget_t
**mouse_over
,
400 if(widget
!= *mouse_over
)
404 if((*mouse_over
)->mouse_leave
!= LUA_REFNIL
)
406 /* call mouse leave function on old widget */
407 luaA_wibox_userdata_new(globalconf
.L
, object
);
408 luaA_dofunction(globalconf
.L
, (*mouse_over
)->mouse_leave
, 1, 0);
413 /* call mouse enter function on new widget and register it */
414 *mouse_over
= widget
;
415 if(widget
->mouse_enter
!= LUA_REFNIL
)
417 luaA_wibox_userdata_new(globalconf
.L
, object
);
418 luaA_dofunction(globalconf
.L
, widget
->mouse_enter
, 1, 0);
424 /** The motion notify event handler.
425 * \param data currently unused.
426 * \param connection The connection to the X server.
427 * \param ev The event.
430 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
431 xcb_connection_t
*connection
,
432 xcb_motion_notify_event_t
*ev
)
434 wibox_t
*wibox
= wibox_getbywin(ev
->event
);
437 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
440 && (w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
441 wibox
->sw
.geometry
.width
,
442 wibox
->sw
.geometry
.height
,
443 &ev
->event_x
, &ev
->event_y
)))
445 globalconf
.pointer_x
= ev
->root_x
;
446 globalconf
.pointer_y
= ev
->root_y
;
447 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
453 /** The leave notify event handler.
454 * \param data currently unused.
455 * \param connection The connection to the X server.
456 * \param ev The event.
459 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
460 xcb_connection_t
*connection
,
461 xcb_leave_notify_event_t
*ev
)
463 wibox_t
*wibox
= wibox_getbywin(ev
->event
);
465 if(wibox
&& wibox
->mouse_over
)
467 if(wibox
->mouse_over
->mouse_leave
!= LUA_REFNIL
)
469 /* call mouse leave function on widget the mouse was over */
470 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
471 luaA_dofunction(globalconf
.L
, wibox
->mouse_over
->mouse_leave
, 1, 0);
473 wibox
->mouse_over
= NULL
;
479 /** The enter notify event handler.
480 * \param data currently unused.
481 * \param connection The connection to the X server.
482 * \param ev The event.
485 event_handle_enternotify(void *data
__attribute__ ((unused
)),
486 xcb_connection_t
*connection
,
487 xcb_enter_notify_event_t
*ev
)
490 xembed_window_t
*emwin
;
494 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
495 || (ev
->root_x
== globalconf
.pointer_x
496 && ev
->root_y
== globalconf
.pointer_y
))
500 if((wibox
= wibox_getbywin(ev
->event
))
501 && (w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
502 wibox
->sw
.geometry
.width
,
503 wibox
->sw
.geometry
.height
,
504 &ev
->event_x
, &ev
->event_y
)))
506 globalconf
.pointer_x
= ev
->root_x
;
507 globalconf
.pointer_y
= ev
->root_y
;
508 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
510 else if((c
= client_getbytitlebarwin(ev
->event
))
511 || (c
= client_getbywin(ev
->event
)))
513 window_buttons_grab(c
->win
, ev
->root
, &c
->buttons
);
514 /* The idea behind saving pointer_x and pointer_y is Bob Marley powered.
515 * this will allow us top drop some EnterNotify events and thus not giving
516 * focus to windows appering under the cursor without a cursor move */
517 globalconf
.pointer_x
= ev
->root_x
;
518 globalconf
.pointer_y
= ev
->root_y
;
520 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
522 luaA_client_userdata_new(globalconf
.L
, c
);
523 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
526 else if((emwin
= xembed_getbywin(globalconf
.embedded
, ev
->event
)))
527 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
,
528 xutil_screen_get(connection
, emwin
->phys_screen
)->root
,
529 XCB_BUTTON_MASK_ANY
);
530 else if(ev
->event
== ev
->root
)
531 window_root_buttons_grab(ev
->root
);
536 /** The expose event handler.
537 * \param data currently unused.
538 * \param connection The connection to the X server.
539 * \param ev The event.
542 event_handle_expose(void *data
__attribute__ ((unused
)),
543 xcb_connection_t
*connection
__attribute__ ((unused
)),
544 xcb_expose_event_t
*ev
)
546 wibox_t
*wibox
= wibox_getbywin(ev
->window
);
549 simplewindow_refresh_pixmap_partial(&wibox
->sw
,
551 ev
->width
, ev
->height
);
556 /** The key press event handler.
557 * \param data currently unused.
558 * \param connection The connection to the X server.
559 * \param ev The event.
562 event_handle_keypress(void *data
__attribute__ ((unused
)),
563 xcb_connection_t
*connection
__attribute__ ((unused
)),
564 xcb_key_press_event_t
*ev
)
566 if(globalconf
.keygrabber
!= LUA_REFNIL
)
568 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
569 if(keygrabber_handlekpress(globalconf
.L
, ev
))
571 if(lua_pcall(globalconf
.L
, 2, 1, 0))
573 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
574 luaA_keygrabber_stop(globalconf
.L
);
576 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
577 luaA_keygrabber_stop(globalconf
.L
);
579 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
583 keybinding_t
*k
= keybinding_find(ev
);
584 if (k
&& k
->fct
!= LUA_REFNIL
)
585 luaA_dofunction(globalconf
.L
, k
->fct
, 0, 0);
591 /** The map request event handler.
592 * \param data currently unused.
593 * \param connection The connection to the X server.
594 * \param ev The event.
597 event_handle_maprequest(void *data
__attribute__ ((unused
)),
598 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
600 int phys_screen
, screen
= 0, ret
= 0;
602 xcb_get_window_attributes_cookie_t wa_c
;
603 xcb_get_window_attributes_reply_t
*wa_r
;
604 xcb_query_pointer_cookie_t qp_c
= { 0 };
605 xcb_query_pointer_reply_t
*qp_r
= NULL
;
606 xcb_get_geometry_cookie_t geom_c
;
607 xcb_get_geometry_reply_t
*geom_r
;
609 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
611 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
614 if(wa_r
->override_redirect
)
617 if(xembed_getbywin(globalconf
.embedded
, ev
->window
))
619 xcb_map_window(connection
, ev
->window
);
620 xembed_window_activate(connection
, ev
->window
);
622 else if((c
= client_getbywin(ev
->window
)))
624 /* Check that it may be visible, but not asked to be hidden */
625 if(client_maybevisible(c
, c
->screen
) && !c
->ishidden
)
627 client_setminimized(c
, false);
628 /* it will be raised, so just update ourself */
634 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
636 if(globalconf
.xinerama_is_active
)
637 qp_c
= xcb_query_pointer_unchecked(connection
,
638 xutil_screen_get(globalconf
.connection
,
639 globalconf
.default_screen
)->root
);
641 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
643 if(globalconf
.xinerama_is_active
)
644 qp_r
= xcb_query_pointer_reply(connection
, qp_c
, NULL
);
650 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
652 if(globalconf
.xinerama_is_active
653 && (qp_r
= xcb_query_pointer_reply(connection
, qp_c
, NULL
)))
654 screen
= screen_getbycoord(screen
, qp_r
->root_x
, qp_r
->root_y
);
656 screen
= phys_screen
;
658 client_manage(ev
->window
, geom_r
, phys_screen
, screen
);
668 /** The unmap notify event handler.
669 * \param data currently unused.
670 * \param connection The connection to the X server.
671 * \param ev The event.
674 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
675 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
680 if((c
= client_getbywin(ev
->window
)))
682 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
683 && XCB_EVENT_SENT(ev
)
684 && window_state_get_reply(window_state_get_unchecked(c
->win
)) == XCB_WM_STATE_NORMAL
)
687 else if((em
= xembed_getbywin(globalconf
.embedded
, ev
->window
)))
689 xembed_window_list_detach(&globalconf
.embedded
, em
);
690 for(int i
= 0; i
< globalconf
.nscreen
; i
++)
691 widget_invalidate_bytype(i
, widget_systray
);
697 /** The randr screen change notify event handler.
698 * \param data currently unused.
699 * \param connection The connection to the X server.
700 * \param ev The event.
703 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
704 xcb_connection_t
*connection
__attribute__ ((unused
)),
705 xcb_randr_screen_change_notify_event_t
*ev
)
707 if(!globalconf
.have_randr
)
710 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
711 * (only the code relevant to RRScreenChangeNotify) as the latter
712 * doesn't provide this kind of function */
713 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
714 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
715 ev
->mheight
, ev
->mwidth
);
717 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
718 ev
->mwidth
, ev
->mheight
);
720 /* XRRUpdateConfiguration also executes the following instruction
721 * but it's not useful because SubpixelOrder is not used at all at
724 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
732 /** The client message event handler.
733 * \param data currently unused.
734 * \param connection The connection to the X server.
735 * \param ev The event.
738 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
739 xcb_connection_t
*connection
,
740 xcb_client_message_event_t
*ev
)
744 if(ev
->type
== WM_CHANGE_STATE
)
746 if((c
= client_getbywin(ev
->window
))
748 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
749 client_setminimized(c
, true);
751 else if(ev
->type
== _XEMBED
)
752 return xembed_process_client_message(ev
);
753 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
754 return systray_process_client_message(ev
);
755 return ewmh_process_client_message(ev
);
758 /** The keymap change notify event handler.
759 * \param data Unused data.
760 * \param connection The connection to the X server.
761 * \param ev The event.
762 * \return Status code, 0 if everything's fine.
765 event_handle_mappingnotify(void *data
,
766 xcb_connection_t
*connection
,
767 xcb_mapping_notify_event_t
*ev
)
769 xcb_get_modifier_mapping_cookie_t xmapping_cookie
;
771 if(ev
->request
== XCB_MAPPING_MODIFIER
772 || ev
->request
== XCB_MAPPING_KEYBOARD
)
774 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
777 /* Send the request to get the NumLock, ShiftLock and CapsLock masks */
778 xmapping_cookie
= xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
780 /* Free and then allocate the key symbols */
781 xcb_key_symbols_free(globalconf
.keysyms
);
782 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
784 /* Process the reply of previously sent mapping request */
785 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
786 globalconf
.keysyms
, &globalconf
.numlockmask
,
787 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
);
791 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
792 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look
794 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
796 } while(phys_screen
< nscreen
);
798 /* regrab everything */
799 keybinding_array_t
*arr
= &globalconf
.keys
.by_sym
;
800 for(int i
= 0; i
< arr
->len
; i
++)
801 window_root_grabkey(arr
->tab
[i
]);
803 arr
= &globalconf
.keys
.by_code
;
804 for(int i
= 0; i
< arr
->len
; i
++)
805 window_root_grabkey(arr
->tab
[i
]);
812 event_handle_reparentnotify(void *data
,
813 xcb_connection_t
*connection
,
814 xcb_reparent_notify_event_t
*ev
)
818 if((c
= client_getbywin(ev
->window
)))
824 void a_xcb_set_event_handlers(void)
826 const xcb_query_extension_reply_t
*randr_query
;
828 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
829 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
830 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
831 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
832 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
833 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
834 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
835 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
836 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
837 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_keypress
, NULL
);
838 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
839 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
840 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
841 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
842 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
844 /* check for randr extension */
845 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
846 if((globalconf
.have_randr
= randr_query
->present
))
847 xcb_event_set_handler(&globalconf
.evenths
,
848 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
849 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
854 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80