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>
37 #include "keygrabber.h"
38 #include "mousegrabber.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.
54 event_handle_mouse_button(client_t
*c
,
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
)
65 case XCB_BUTTON_PRESS
:
66 if(buttons
->tab
[i
]->press
!= LUA_REFNIL
)
70 luaA_client_userdata_new(globalconf
.L
, c
);
71 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->press
, 1, 0);
74 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->press
, 0, 0);
77 case XCB_BUTTON_RELEASE
:
78 if(buttons
->tab
[i
]->release
!= LUA_REFNIL
)
82 luaA_client_userdata_new(globalconf
.L
, c
);
83 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->release
, 1, 0);
86 luaA_dofunction(globalconf
.L
, buttons
->tab
[i
]->release
, 0, 0);
92 /** Handle an event with mouse grabber if needed
93 * \param x The x coordinate.
94 * \param y The y coordinate.
95 * \param mask The mask buttons.
98 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
100 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
102 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
103 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
104 if(lua_pcall(globalconf
.L
, 1, 1, 0))
106 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
107 luaA_mousegrabber_stop(globalconf
.L
);
109 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
110 luaA_mousegrabber_stop(globalconf
.L
);
111 lua_pop(globalconf
.L
, 1); /* pop returned value */
115 /** The button press event handler.
116 * \param data The type of mouse event.
117 * \param connection The connection to the X server.
118 * \param ev The event.
121 event_handle_button(void *data
, xcb_connection_t
*connection
, xcb_button_press_event_t
*ev
)
124 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(connection
));
130 * button status (8 bits) + modifiers status (8 bits)
131 * we don't care for button status that we get, especially on release, so
135 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
137 if((wibox
= wibox_getbywin(ev
->event
))
138 || (wibox
= wibox_getbywin(ev
->child
)))
140 /* If the wibox is child, then x,y are
141 * relative to root window */
142 if(wibox
->sw
.window
== ev
->child
)
144 ev
->event_x
-= wibox
->sw
.geometry
.x
;
145 ev
->event_y
-= wibox
->sw
.geometry
.y
;
148 /* check if we match a binding on the wibox */
149 button_array_t
*b
= &wibox
->buttons
;
151 for(int i
= 0; i
< b
->len
; i
++)
152 if(ev
->detail
== b
->tab
[i
]->button
153 && XUTIL_MASK_CLEAN(ev
->state
) == b
->tab
[i
]->mod
)
154 switch(ev
->response_type
)
156 case XCB_BUTTON_PRESS
:
157 if(b
->tab
[i
]->press
!= LUA_REFNIL
)
159 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
160 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->press
, 1, 0);
163 case XCB_BUTTON_RELEASE
:
164 if(b
->tab
[i
]->release
!= LUA_REFNIL
)
166 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
167 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->release
, 1, 0);
172 /* then try to match a widget binding */
173 if((w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
174 wibox
->sw
.geometry
.width
,
175 wibox
->sw
.geometry
.height
,
176 &ev
->event_x
, &ev
->event_y
)))
180 for(int i
= 0; i
< b
->len
; i
++)
181 if(ev
->detail
== b
->tab
[i
]->button
182 && XUTIL_MASK_CLEAN(ev
->state
) == b
->tab
[i
]->mod
)
183 switch(ev
->response_type
)
185 case XCB_BUTTON_PRESS
:
186 if(b
->tab
[i
]->press
!= LUA_REFNIL
)
188 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
189 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->press
, 1, 0);
192 case XCB_BUTTON_RELEASE
:
193 if(b
->tab
[i
]->release
!= LUA_REFNIL
)
195 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
196 luaA_dofunction(globalconf
.L
, b
->tab
[i
]->release
, 1, 0);
201 /* return even if no widget match */
205 if((c
= client_getbywin(ev
->event
)))
207 event_handle_mouse_button(c
, ev
->response_type
, ev
->detail
, ev
->state
, &c
->buttons
);
208 xcb_allow_events(globalconf
.connection
,
209 XCB_ALLOW_REPLAY_POINTER
,
213 for(screen
= 0; screen
< nb_screen
; screen
++)
214 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
216 event_handle_mouse_button(NULL
, ev
->response_type
, ev
->detail
, ev
->state
, &globalconf
.buttons
);
224 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
226 uint16_t config_win_mask
= 0;
227 uint32_t config_win_vals
[7];
228 unsigned short i
= 0;
230 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
232 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
233 config_win_vals
[i
++] = ev
->x
;
235 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
237 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
238 config_win_vals
[i
++] = ev
->y
;
240 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
242 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
243 config_win_vals
[i
++] = ev
->width
;
245 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
247 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
248 config_win_vals
[i
++] = ev
->height
;
250 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
252 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
253 config_win_vals
[i
++] = ev
->border_width
;
255 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
257 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
258 config_win_vals
[i
++] = ev
->sibling
;
260 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
262 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
263 config_win_vals
[i
++] = ev
->stack_mode
;
266 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
269 /** The configure event handler.
270 * \param data currently unused.
271 * \param connection The connection to the X server.
272 * \param ev The event.
275 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
276 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
281 if((c
= client_getbywin(ev
->window
)))
283 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
285 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
287 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
289 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
290 geometry
.width
= ev
->width
;
291 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
292 geometry
.height
= ev
->height
;
296 /* We'll be sending protocol geometry, so don't readd borders and titlebar. */
297 /* We do have to ensure the windows don't end up in the visible screen. */
298 geometry
.x
= - (geometry
.width
+ 2*c
->border
);
299 geometry
.y
= - (geometry
.height
+ 2*c
->border
);
303 /** Configure request are sent with size relative to real (internal)
304 * window size, i.e. without titlebars and borders. */
305 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry
);
308 if(geometry
.x
!= c
->geometry
.x
309 || geometry
.y
!= c
->geometry
.y
310 || geometry
.width
!= c
->geometry
.width
311 || geometry
.height
!= c
->geometry
.height
)
315 window_configure(c
->win
, geometry
, c
->border
);
316 event_handle_configurerequest_configure_window(ev
);
320 client_resize(c
, geometry
, false);
321 /* All the wiboxes (may) need to be repositioned. */
322 if(client_hasstrut(c
))
323 wibox_update_positions();
324 client_need_arrange(c
);
330 window_configure(c
->win
, geometry
, c
->border
);
333 event_handle_configurerequest_configure_window(ev
);
338 /** The configure notify event handler.
339 * \param data currently unused.
340 * \param connection The connection to the X server.
341 * \param ev The event.
344 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
345 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
348 const xcb_screen_t
*screen
;
350 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
351 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
352 && ev
->window
== screen
->root
353 && (ev
->width
!= screen
->width_in_pixels
354 || ev
->height
!= screen
->height_in_pixels
))
355 /* it's not that we panic, but restart */
361 /** The destroy notify event handler.
362 * \param data currently unused.
363 * \param connection The connection to the X server.
364 * \param ev The event.
367 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
368 xcb_connection_t
*connection
__attribute__ ((unused
)),
369 xcb_destroy_notify_event_t
*ev
)
373 if((c
= client_getbywin(ev
->window
)))
376 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
377 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
379 xembed_window_array_take(&globalconf
.embedded
, i
);
380 for(int j
= 0; j
< globalconf
.nscreen
; j
++)
381 widget_invalidate_bytype(j
, widget_systray
);
387 /** Handle a motion notify over widgets.
388 * \param object The object.
389 * \param mouse_over The pointer to the registered mouse over widget.
390 * \param widget The new widget the mouse is over.
393 event_handle_widget_motionnotify(void *object
,
394 widget_t
**mouse_over
,
397 if(widget
!= *mouse_over
)
401 if((*mouse_over
)->mouse_leave
!= LUA_REFNIL
)
403 /* call mouse leave function on old widget */
404 luaA_wibox_userdata_new(globalconf
.L
, object
);
405 luaA_dofunction(globalconf
.L
, (*mouse_over
)->mouse_leave
, 1, 0);
410 /* call mouse enter function on new widget and register it */
411 *mouse_over
= widget
;
412 if(widget
->mouse_enter
!= LUA_REFNIL
)
414 luaA_wibox_userdata_new(globalconf
.L
, object
);
415 luaA_dofunction(globalconf
.L
, widget
->mouse_enter
, 1, 0);
421 /** The motion notify event handler.
422 * \param data currently unused.
423 * \param connection The connection to the X server.
424 * \param ev The event.
427 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
428 xcb_connection_t
*connection
,
429 xcb_motion_notify_event_t
*ev
)
431 wibox_t
*wibox
= wibox_getbywin(ev
->event
);
434 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
437 && (w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
438 wibox
->sw
.geometry
.width
,
439 wibox
->sw
.geometry
.height
,
440 &ev
->event_x
, &ev
->event_y
)))
442 globalconf
.pointer_x
= ev
->root_x
;
443 globalconf
.pointer_y
= ev
->root_y
;
444 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
450 /** The leave notify event handler.
451 * \param data currently unused.
452 * \param connection The connection to the X server.
453 * \param ev The event.
456 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
457 xcb_connection_t
*connection
,
458 xcb_leave_notify_event_t
*ev
)
461 client_t
*c
= client_getbywin(ev
->event
);
465 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
467 luaA_client_userdata_new(globalconf
.L
, c
);
468 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
471 else if((wibox
= wibox_getbywin(ev
->event
)))
473 if(wibox
->mouse_over
)
475 if(wibox
->mouse_over
->mouse_leave
!= LUA_REFNIL
)
477 /* call mouse leave function on widget the mouse was over */
478 luaA_wibox_userdata_new(globalconf
.L
, wibox
);
479 luaA_dofunction(globalconf
.L
, wibox
->mouse_over
->mouse_leave
, 1, 0);
481 wibox
->mouse_over
= NULL
;
488 /** The enter notify event handler.
489 * \param data currently unused.
490 * \param connection The connection to the X server.
491 * \param ev The event.
494 event_handle_enternotify(void *data
__attribute__ ((unused
)),
495 xcb_connection_t
*connection
,
496 xcb_enter_notify_event_t
*ev
)
499 xembed_window_t
*emwin
;
503 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
504 || (ev
->root_x
== globalconf
.pointer_x
505 && ev
->root_y
== globalconf
.pointer_y
))
509 if((wibox
= wibox_getbywin(ev
->event
))
510 && (w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
511 wibox
->sw
.geometry
.width
,
512 wibox
->sw
.geometry
.height
,
513 &ev
->event_x
, &ev
->event_y
)))
515 globalconf
.pointer_x
= ev
->root_x
;
516 globalconf
.pointer_y
= ev
->root_y
;
517 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
519 else if((c
= client_getbytitlebarwin(ev
->event
))
520 || (c
= client_getbywin(ev
->event
)))
522 window_buttons_grab(c
->win
, ev
->root
, &c
->buttons
);
523 /* The idea behind saving pointer_x and pointer_y is Bob Marley powered.
524 * this will allow us top drop some EnterNotify events and thus not giving
525 * focus to windows appering under the cursor without a cursor move */
526 globalconf
.pointer_x
= ev
->root_x
;
527 globalconf
.pointer_y
= ev
->root_y
;
529 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
531 luaA_client_userdata_new(globalconf
.L
, c
);
532 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
535 else if((emwin
= xembed_getbywin(&globalconf
.embedded
, ev
->event
)))
536 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
,
537 xutil_screen_get(connection
, emwin
->phys_screen
)->root
,
538 XCB_BUTTON_MASK_ANY
);
539 else if(ev
->event
== ev
->root
)
540 window_root_buttons_grab(ev
->root
);
545 /** The expose event handler.
546 * \param data currently unused.
547 * \param connection The connection to the X server.
548 * \param ev The event.
551 event_handle_expose(void *data
__attribute__ ((unused
)),
552 xcb_connection_t
*connection
__attribute__ ((unused
)),
553 xcb_expose_event_t
*ev
)
555 wibox_t
*wibox
= wibox_getbywin(ev
->window
);
558 simplewindow_refresh_pixmap_partial(&wibox
->sw
,
560 ev
->width
, ev
->height
);
565 /** The key press event handler.
566 * \param data currently unused.
567 * \param connection The connection to the X server.
568 * \param ev The event.
571 event_handle_key(void *data
__attribute__ ((unused
)),
572 xcb_connection_t
*connection
__attribute__ ((unused
)),
573 xcb_key_press_event_t
*ev
)
577 if(globalconf
.keygrabber
!= LUA_REFNIL
)
579 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
580 if(keygrabber_handlekpress(globalconf
.L
, ev
))
582 if(lua_pcall(globalconf
.L
, 3, 1, 0))
584 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
585 luaA_keygrabber_stop(globalconf
.L
);
587 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
588 luaA_keygrabber_stop(globalconf
.L
);
590 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
592 else if((c
= client_getbywin(ev
->event
)))
594 keyb_t
*k
= key_find(&c
->keys
, ev
);
597 switch(ev
->response_type
)
600 if(k
->press
!= LUA_REFNIL
)
602 luaA_client_userdata_new(globalconf
.L
, c
);
603 luaA_dofunction(globalconf
.L
, k
->press
, 1, 0);
606 case XCB_KEY_RELEASE
:
607 if(k
->release
!= LUA_REFNIL
)
609 luaA_client_userdata_new(globalconf
.L
, c
);
610 luaA_dofunction(globalconf
.L
, k
->release
, 1, 0);
617 keyb_t
*k
= key_find(&globalconf
.keys
, ev
);
620 switch(ev
->response_type
)
623 if(k
->press
!= LUA_REFNIL
)
624 luaA_dofunction(globalconf
.L
, k
->press
, 0, 0);
626 case XCB_KEY_RELEASE
:
627 if(k
->release
!= LUA_REFNIL
)
628 luaA_dofunction(globalconf
.L
, k
->release
, 0, 0);
636 /** The map request event handler.
637 * \param data currently unused.
638 * \param connection The connection to the X server.
639 * \param ev The event.
642 event_handle_maprequest(void *data
__attribute__ ((unused
)),
643 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
645 int phys_screen
, ret
= 0;
647 xcb_get_window_attributes_cookie_t wa_c
;
648 xcb_get_window_attributes_reply_t
*wa_r
;
649 xcb_get_geometry_cookie_t geom_c
;
650 xcb_get_geometry_reply_t
*geom_r
;
652 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
654 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
657 if(wa_r
->override_redirect
)
660 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
662 xcb_map_window(connection
, ev
->window
);
663 xembed_window_activate(connection
, ev
->window
);
665 else if((c
= client_getbywin(ev
->window
)))
667 /* Check that it may be visible, but not asked to be hidden */
668 if(client_maybevisible(c
, c
->screen
) && !c
->ishidden
)
670 client_setminimized(c
, false);
671 /* it will be raised, so just update ourself */
677 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
679 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
685 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
687 client_manage(ev
->window
, geom_r
, phys_screen
, false);
697 /** The unmap 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_unmapnotify(void *data
__attribute__ ((unused
)),
704 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
708 if((c
= client_getbywin(ev
->window
)))
710 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
711 && XCB_EVENT_SENT(ev
)
712 && window_state_get_reply(window_state_get_unchecked(c
->win
)) == XCB_WM_STATE_NORMAL
)
716 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
717 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
719 xembed_window_array_take(&globalconf
.embedded
, i
);
720 for(int j
= 0; j
< globalconf
.nscreen
; j
++)
721 widget_invalidate_bytype(j
, widget_systray
);
727 /** The randr screen change notify event handler.
728 * \param data currently unused.
729 * \param connection The connection to the X server.
730 * \param ev The event.
733 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
734 xcb_connection_t
*connection
__attribute__ ((unused
)),
735 xcb_randr_screen_change_notify_event_t
*ev
)
737 if(!globalconf
.have_randr
)
740 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
741 * (only the code relevant to RRScreenChangeNotify) as the latter
742 * doesn't provide this kind of function */
743 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
744 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
745 ev
->mheight
, ev
->mwidth
);
747 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
748 ev
->mwidth
, ev
->mheight
);
750 /* XRRUpdateConfiguration also executes the following instruction
751 * but it's not useful because SubpixelOrder is not used at all at
754 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
762 /** The client message event handler.
763 * \param data currently unused.
764 * \param connection The connection to the X server.
765 * \param ev The event.
768 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
769 xcb_connection_t
*connection
,
770 xcb_client_message_event_t
*ev
)
774 if(ev
->type
== WM_CHANGE_STATE
)
776 if((c
= client_getbywin(ev
->window
))
778 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
779 client_setminimized(c
, true);
781 else if(ev
->type
== _XEMBED
)
782 return xembed_process_client_message(ev
);
783 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
784 return systray_process_client_message(ev
);
785 return ewmh_process_client_message(ev
);
788 /** The keymap change notify event handler.
789 * \param data Unused data.
790 * \param connection The connection to the X server.
791 * \param ev The event.
792 * \return Status code, 0 if everything's fine.
795 event_handle_mappingnotify(void *data
,
796 xcb_connection_t
*connection
,
797 xcb_mapping_notify_event_t
*ev
)
799 xcb_get_modifier_mapping_cookie_t xmapping_cookie
;
801 if(ev
->request
== XCB_MAPPING_MODIFIER
802 || ev
->request
== XCB_MAPPING_KEYBOARD
)
804 /* Send the request to get the NumLock, ShiftLock and CapsLock masks */
805 xmapping_cookie
= xcb_get_modifier_mapping_unchecked(globalconf
.connection
);
807 /* Free and then allocate the key symbols */
808 xcb_key_symbols_free(globalconf
.keysyms
);
809 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
811 /* Process the reply of previously sent mapping request */
812 xutil_lock_mask_get(globalconf
.connection
, xmapping_cookie
,
813 globalconf
.keysyms
, &globalconf
.numlockmask
,
814 &globalconf
.shiftlockmask
, &globalconf
.capslockmask
);
816 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
818 /* regrab everything */
819 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
821 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
822 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
823 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
824 window_grabkeys(s
->root
, &globalconf
.keys
);
827 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
829 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
830 window_grabkeys(c
->win
, &c
->keys
);
838 event_handle_reparentnotify(void *data
,
839 xcb_connection_t
*connection
,
840 xcb_reparent_notify_event_t
*ev
)
844 if((c
= client_getbywin(ev
->window
)))
850 void a_xcb_set_event_handlers(void)
852 const xcb_query_extension_reply_t
*randr_query
;
854 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
855 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
856 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
857 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
858 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
859 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
860 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
861 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
862 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
863 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
864 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
865 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
866 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
867 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
868 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
869 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
871 /* check for randr extension */
872 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
873 if((globalconf
.have_randr
= randr_query
->present
))
874 xcb_event_set_handler(&globalconf
.evenths
,
875 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
876 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
881 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80