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"
43 #include "common/xutil.h"
45 #define EVENT_BUTTON_MATCH(b, state, xbutton) \
46 ((!(b)->button || (xbutton) == (b)->button) \
47 && ((b)->mod == XCB_BUTTON_MASK_ANY || (b)->mod == (state)))
49 /** Handle mouse button events.
50 * \param c The client on which the event happened or NULL.
51 * \param type Event type, press or release.
52 * \param button Button number.
53 * \param state Modkeys state.
54 * \param buttons Buttons array to check for.
57 event_handle_mouse_button(client_t
*c
,
61 button_array_t
*buttons
)
64 if(EVENT_BUTTON_MATCH(*b
, state
, button
))
67 case XCB_BUTTON_PRESS
:
68 if((*b
)->press
!= LUA_REFNIL
)
72 client_push(globalconf
.L
, c
);
73 luaA_dofunction(globalconf
.L
, (*b
)->press
, 1, 0);
76 luaA_dofunction(globalconf
.L
, (*b
)->press
, 0, 0);
79 case XCB_BUTTON_RELEASE
:
80 if((*b
)->release
!= LUA_REFNIL
)
84 client_push(globalconf
.L
, c
);
85 luaA_dofunction(globalconf
.L
, (*b
)->release
, 1, 0);
88 luaA_dofunction(globalconf
.L
, (*b
)->release
, 0, 0);
94 /** Handle an event with mouse grabber if needed
95 * \param x The x coordinate.
96 * \param y The y coordinate.
97 * \param mask The mask buttons.
100 event_handle_mousegrabber(int x
, int y
, uint16_t mask
)
102 if(globalconf
.mousegrabber
!= LUA_REFNIL
)
104 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.mousegrabber
);
105 mousegrabber_handleevent(globalconf
.L
, x
, y
, mask
);
106 if(lua_pcall(globalconf
.L
, 1, 1, 0))
108 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
109 luaA_mousegrabber_stop(globalconf
.L
);
111 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
112 luaA_mousegrabber_stop(globalconf
.L
);
113 lua_pop(globalconf
.L
, 1); /* pop returned value */
117 /** The button press event handler.
118 * \param data The type of mouse event.
119 * \param connection The connection to the X server.
120 * \param ev The event.
123 event_handle_button(void *data
, xcb_connection_t
*connection
, xcb_button_press_event_t
*ev
)
126 const int nb_screen
= xcb_setup_roots_length(xcb_get_setup(connection
));
131 * button status (8 bits) + modifiers status (8 bits)
132 * we don't care for button status that we get, especially on release, so
136 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
138 if((wibox
= wibox_getbywin(ev
->event
))
139 || (wibox
= wibox_getbywin(ev
->child
)))
141 /* If the wibox is child, then x,y are
142 * relative to root window */
143 if(wibox
->sw
.window
== ev
->child
)
145 ev
->event_x
-= wibox
->sw
.geometry
.x
;
146 ev
->event_y
-= wibox
->sw
.geometry
.y
;
149 /* check if we match a binding on the wibox */
150 foreach(b
, wibox
->buttons
)
151 if(EVENT_BUTTON_MATCH(*b
, ev
->state
, ev
->detail
))
152 switch(ev
->response_type
)
154 case XCB_BUTTON_PRESS
:
155 if((*b
)->press
!= LUA_REFNIL
)
157 wibox_push(globalconf
.L
, wibox
);
158 luaA_dofunction(globalconf
.L
, (*b
)->press
, 1, 0);
161 case XCB_BUTTON_RELEASE
:
162 if((*b
)->release
!= LUA_REFNIL
)
164 wibox_push(globalconf
.L
, wibox
);
165 luaA_dofunction(globalconf
.L
, (*b
)->release
, 1, 0);
170 /* then try to match a widget binding */
171 widget_t
*w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
172 wibox
->sw
.geometry
.width
,
173 wibox
->sw
.geometry
.height
,
174 &ev
->event_x
, &ev
->event_y
);
176 foreach(b
, w
->buttons
)
177 if(EVENT_BUTTON_MATCH(*b
, ev
->state
, ev
->detail
))
178 switch(ev
->response_type
)
180 case XCB_BUTTON_PRESS
:
181 if((*b
)->press
!= LUA_REFNIL
)
183 wibox_push(globalconf
.L
, wibox
);
184 luaA_dofunction(globalconf
.L
, (*b
)->press
, 1, 0);
187 case XCB_BUTTON_RELEASE
:
188 if((*b
)->release
!= LUA_REFNIL
)
190 wibox_push(globalconf
.L
, wibox
);
191 luaA_dofunction(globalconf
.L
, (*b
)->release
, 1, 0);
196 /* return even if no widget match */
199 else if((c
= client_getbywin(ev
->event
)))
201 event_handle_mouse_button(c
, ev
->response_type
, ev
->detail
, ev
->state
, &c
->buttons
);
202 xcb_allow_events(globalconf
.connection
,
203 XCB_ALLOW_REPLAY_POINTER
,
206 else if(ev
->child
== XCB_NONE
)
207 for(screen
= 0; screen
< nb_screen
; screen
++)
208 if(xutil_screen_get(connection
, screen
)->root
== ev
->event
)
210 event_handle_mouse_button(NULL
, ev
->response_type
, ev
->detail
, ev
->state
, &globalconf
.buttons
);
218 event_handle_configurerequest_configure_window(xcb_configure_request_event_t
*ev
)
220 uint16_t config_win_mask
= 0;
221 uint32_t config_win_vals
[7];
222 unsigned short i
= 0;
224 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
226 config_win_mask
|= XCB_CONFIG_WINDOW_X
;
227 config_win_vals
[i
++] = ev
->x
;
229 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
231 config_win_mask
|= XCB_CONFIG_WINDOW_Y
;
232 config_win_vals
[i
++] = ev
->y
;
234 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
236 config_win_mask
|= XCB_CONFIG_WINDOW_WIDTH
;
237 config_win_vals
[i
++] = ev
->width
;
239 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
241 config_win_mask
|= XCB_CONFIG_WINDOW_HEIGHT
;
242 config_win_vals
[i
++] = ev
->height
;
244 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
246 config_win_mask
|= XCB_CONFIG_WINDOW_BORDER_WIDTH
;
247 config_win_vals
[i
++] = ev
->border_width
;
249 if(ev
->value_mask
& XCB_CONFIG_WINDOW_SIBLING
)
251 config_win_mask
|= XCB_CONFIG_WINDOW_SIBLING
;
252 config_win_vals
[i
++] = ev
->sibling
;
254 if(ev
->value_mask
& XCB_CONFIG_WINDOW_STACK_MODE
)
256 config_win_mask
|= XCB_CONFIG_WINDOW_STACK_MODE
;
257 config_win_vals
[i
++] = ev
->stack_mode
;
260 xcb_configure_window(globalconf
.connection
, ev
->window
, config_win_mask
, config_win_vals
);
263 /** The configure event handler.
264 * \param data currently unused.
265 * \param connection The connection to the X server.
266 * \param ev The event.
269 event_handle_configurerequest(void *data
__attribute__ ((unused
)),
270 xcb_connection_t
*connection
, xcb_configure_request_event_t
*ev
)
275 if((c
= client_getbywin(ev
->window
)))
277 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
279 if(ev
->value_mask
& XCB_CONFIG_WINDOW_X
)
281 if(ev
->value_mask
& XCB_CONFIG_WINDOW_Y
)
283 if(ev
->value_mask
& XCB_CONFIG_WINDOW_WIDTH
)
284 geometry
.width
= ev
->width
;
285 if(ev
->value_mask
& XCB_CONFIG_WINDOW_HEIGHT
)
286 geometry
.height
= ev
->height
;
288 if(ev
->value_mask
& XCB_CONFIG_WINDOW_BORDER_WIDTH
)
289 client_setborder(c
, ev
->border_width
);
291 /* Clients are not allowed to directly mess with stacking parameters. */
292 ev
->value_mask
&= ~(XCB_CONFIG_WINDOW_SIBLING
|
293 XCB_CONFIG_WINDOW_STACK_MODE
);
297 /* We'll be sending protocol geometry, so don't readd borders and titlebar. */
298 /* We do have to ensure the windows don't end up in the visible screen. */
299 ev
->x
= geometry
.x
= - (geometry
.width
+ 2*c
->border
);
300 ev
->y
= geometry
.y
= - (geometry
.height
+ 2*c
->border
);
301 window_configure(c
->win
, geometry
, c
->border
);
302 event_handle_configurerequest_configure_window(ev
);
306 /** Configure request are sent with size relative to real (internal)
307 * window size, i.e. without titlebars and borders. */
308 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry
);
310 if(client_resize(c
, geometry
, false))
312 /* All the wiboxes (may) need to be repositioned. */
313 if(client_hasstrut(c
))
314 wibox_update_positions();
315 client_need_arrange(c
);
319 /* Resize wasn't officially needed, but we don't want to break expectations. */
320 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, c
->geometry
);
321 window_configure(c
->win
, geometry
, c
->border
);
326 event_handle_configurerequest_configure_window(ev
);
331 /** The configure notify event handler.
332 * \param data currently unused.
333 * \param connection The connection to the X server.
334 * \param ev The event.
337 event_handle_configurenotify(void *data
__attribute__ ((unused
)),
338 xcb_connection_t
*connection
, xcb_configure_notify_event_t
*ev
)
341 const xcb_screen_t
*screen
;
343 for(screen_nbr
= 0; screen_nbr
< xcb_setup_roots_length(xcb_get_setup (connection
)); screen_nbr
++)
344 if((screen
= xutil_screen_get(connection
, screen_nbr
)) != NULL
345 && ev
->window
== screen
->root
346 && (ev
->width
!= screen
->width_in_pixels
347 || ev
->height
!= screen
->height_in_pixels
))
348 /* it's not that we panic, but restart */
354 /** The destroy notify event handler.
355 * \param data currently unused.
356 * \param connection The connection to the X server.
357 * \param ev The event.
360 event_handle_destroynotify(void *data
__attribute__ ((unused
)),
361 xcb_connection_t
*connection
__attribute__ ((unused
)),
362 xcb_destroy_notify_event_t
*ev
)
366 if((c
= client_getbywin(ev
->window
)))
369 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
370 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
372 xembed_window_array_take(&globalconf
.embedded
, i
);
373 foreach(screen
, globalconf
.screens
)
374 widget_invalidate_bytype(screen
, widget_systray
);
380 /** Handle a motion notify over widgets.
381 * \param object The object.
382 * \param mouse_over The pointer to the registered mouse over widget.
383 * \param widget The new widget the mouse is over.
386 event_handle_widget_motionnotify(void *object
,
387 widget_t
**mouse_over
,
390 if(widget
!= *mouse_over
)
394 if((*mouse_over
)->mouse_leave
!= LUA_REFNIL
)
396 /* call mouse leave function on old widget */
397 widget_push(globalconf
.L
, *mouse_over
);
398 luaA_dofunction(globalconf
.L
, (*mouse_over
)->mouse_leave
, 1, 0);
403 /* call mouse enter function on new widget and register it */
404 *mouse_over
= widget
;
405 if(widget
->mouse_enter
!= LUA_REFNIL
)
407 widget_push(globalconf
.L
, widget
);
408 luaA_dofunction(globalconf
.L
, widget
->mouse_enter
, 1, 0);
414 /** The motion notify event handler.
415 * \param data currently unused.
416 * \param connection The connection to the X server.
417 * \param ev The event.
420 event_handle_motionnotify(void *data
__attribute__ ((unused
)),
421 xcb_connection_t
*connection
,
422 xcb_motion_notify_event_t
*ev
)
426 event_handle_mousegrabber(ev
->root_x
, ev
->root_y
, ev
->state
);
428 if((wibox
= wibox_getbywin(ev
->event
)))
430 widget_t
*w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
431 wibox
->sw
.geometry
.width
,
432 wibox
->sw
.geometry
.height
,
433 &ev
->event_x
, &ev
->event_y
);
435 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
441 /** The leave notify event handler.
442 * \param data currently unused.
443 * \param connection The connection to the X server.
444 * \param ev The event.
447 event_handle_leavenotify(void *data
__attribute__ ((unused
)),
448 xcb_connection_t
*connection
,
449 xcb_leave_notify_event_t
*ev
)
454 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
457 if((c
= client_getbytitlebarwin(ev
->event
)) || (c
= client_getbywin(ev
->event
)))
458 if(globalconf
.hooks
.mouse_leave
!= LUA_REFNIL
)
460 client_push(globalconf
.L
, c
);
461 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_leave
, 1, 0);
464 if((wibox
= wibox_getbywin(ev
->event
)))
466 if(wibox
->mouse_over
)
468 if(wibox
->mouse_over
->mouse_leave
!= LUA_REFNIL
)
470 /* call mouse leave function on widget the mouse was over */
471 wibox_push(globalconf
.L
, wibox
);
472 luaA_dofunction(globalconf
.L
, wibox
->mouse_over
->mouse_leave
, 1, 0);
474 wibox
->mouse_over
= NULL
;
477 if(wibox
->mouse_leave
!= LUA_REFNIL
)
478 luaA_dofunction(globalconf
.L
, wibox
->mouse_leave
, 0, 0);
484 /** The enter notify event handler.
485 * \param data currently unused.
486 * \param connection The connection to the X server.
487 * \param ev The event.
490 event_handle_enternotify(void *data
__attribute__ ((unused
)),
491 xcb_connection_t
*connection
,
492 xcb_enter_notify_event_t
*ev
)
497 if(ev
->mode
!= XCB_NOTIFY_MODE_NORMAL
)
500 if((wibox
= wibox_getbywin(ev
->event
)))
502 widget_t
*w
= widget_getbycoords(wibox
->position
, &wibox
->widgets
,
503 wibox
->sw
.geometry
.width
,
504 wibox
->sw
.geometry
.height
,
505 &ev
->event_x
, &ev
->event_y
);
507 event_handle_widget_motionnotify(wibox
, &wibox
->mouse_over
, w
);
509 if(wibox
->mouse_enter
!= LUA_REFNIL
)
510 luaA_dofunction(globalconf
.L
, wibox
->mouse_enter
, 0, 0);
513 if((c
= client_getbytitlebarwin(ev
->event
))
514 || (c
= client_getbywin(ev
->event
)))
515 if(globalconf
.hooks
.mouse_enter
!= LUA_REFNIL
)
517 client_push(globalconf
.L
, c
);
518 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.mouse_enter
, 1, 0);
524 /** The focus in event handler.
525 * \param data currently unused.
526 * \param connection The connection to the X server.
527 * \param ev The event.
530 event_handle_focusin(void *data
__attribute__ ((unused
)),
531 xcb_connection_t
*connection
,
532 xcb_focus_in_event_t
*ev
)
536 /* Events that we are interested in: */
539 /* These are events that jump between windows of a toplevel client.
541 * NotifyVirtual event is handled in case where NotifyAncestor or
542 * NotifyInferior event is not generated on window that is managed by
543 * awesome ( client_* returns NULL )
545 * Can someone explain exactly why they are needed ?
547 case XCB_NOTIFY_DETAIL_VIRTUAL
:
548 case XCB_NOTIFY_DETAIL_ANCESTOR
:
549 case XCB_NOTIFY_DETAIL_INFERIOR
:
551 /* These are events that jump between clients.
552 * Virtual events ensure we always get an event on our top-level window.
554 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
555 case XCB_NOTIFY_DETAIL_NONLINEAR
:
556 if((c
= client_getbytitlebarwin(ev
->event
))
557 || (c
= client_getbywin(ev
->event
)))
558 client_focus_update(c
);
559 /* all other events are ignored */
565 /** The focus out event handler.
566 * \param data currently unused.
567 * \param connection The connection to the X server.
568 * \param ev The event.
571 event_handle_focusout(void *data
__attribute__ ((unused
)),
572 xcb_connection_t
*connection
,
573 xcb_focus_out_event_t
*ev
)
577 /* Events that we are interested in: */
580 /* These are events that jump between clients.
581 * Virtual events ensure we always get an event on our top-level window.
583 case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL
:
584 case XCB_NOTIFY_DETAIL_NONLINEAR
:
585 if((c
= client_getbytitlebarwin(ev
->event
))
586 || (c
= client_getbywin(ev
->event
)))
587 client_unfocus_update(c
);
588 /* all other events are ignored */
594 /** The expose event handler.
595 * \param data currently unused.
596 * \param connection The connection to the X server.
597 * \param ev The event.
600 event_handle_expose(void *data
__attribute__ ((unused
)),
601 xcb_connection_t
*connection
__attribute__ ((unused
)),
602 xcb_expose_event_t
*ev
)
606 if((wibox
= wibox_getbywin(ev
->window
)))
607 simplewindow_refresh_pixmap_partial(&wibox
->sw
,
609 ev
->width
, ev
->height
);
614 /** The key press event handler.
615 * \param data currently unused.
616 * \param connection The connection to the X server.
617 * \param ev The event.
620 event_handle_key(void *data
__attribute__ ((unused
)),
621 xcb_connection_t
*connection
__attribute__ ((unused
)),
622 xcb_key_press_event_t
*ev
)
626 if(globalconf
.keygrabber
!= LUA_REFNIL
)
628 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, globalconf
.keygrabber
);
629 if(keygrabber_handlekpress(globalconf
.L
, ev
))
631 if(lua_pcall(globalconf
.L
, 3, 1, 0))
633 warn("error running function: %s", lua_tostring(globalconf
.L
, -1));
634 luaA_keygrabber_stop(globalconf
.L
);
636 else if(!lua_isboolean(globalconf
.L
, -1) || !lua_toboolean(globalconf
.L
, -1))
637 luaA_keygrabber_stop(globalconf
.L
);
639 lua_pop(globalconf
.L
, 1); /* pop returned value or function if not called */
641 else if((c
= client_getbywin(ev
->event
)))
643 keyb_t
*k
= key_find(&c
->keys
, ev
);
646 switch(ev
->response_type
)
649 if(k
->press
!= LUA_REFNIL
)
651 client_push(globalconf
.L
, c
);
652 luaA_dofunction(globalconf
.L
, k
->press
, 1, 0);
655 case XCB_KEY_RELEASE
:
656 if(k
->release
!= LUA_REFNIL
)
658 client_push(globalconf
.L
, c
);
659 luaA_dofunction(globalconf
.L
, k
->release
, 1, 0);
666 keyb_t
*k
= key_find(&globalconf
.keys
, ev
);
669 switch(ev
->response_type
)
672 if(k
->press
!= LUA_REFNIL
)
673 luaA_dofunction(globalconf
.L
, k
->press
, 0, 0);
675 case XCB_KEY_RELEASE
:
676 if(k
->release
!= LUA_REFNIL
)
677 luaA_dofunction(globalconf
.L
, k
->release
, 0, 0);
685 /** The map request event handler.
686 * \param data currently unused.
687 * \param connection The connection to the X server.
688 * \param ev The event.
691 event_handle_maprequest(void *data
__attribute__ ((unused
)),
692 xcb_connection_t
*connection
, xcb_map_request_event_t
*ev
)
694 int phys_screen
, ret
= 0;
696 xcb_get_window_attributes_cookie_t wa_c
;
697 xcb_get_window_attributes_reply_t
*wa_r
;
698 xcb_get_geometry_cookie_t geom_c
;
699 xcb_get_geometry_reply_t
*geom_r
;
701 wa_c
= xcb_get_window_attributes_unchecked(connection
, ev
->window
);
703 if(!(wa_r
= xcb_get_window_attributes_reply(connection
, wa_c
, NULL
)))
706 if(wa_r
->override_redirect
)
709 if(xembed_getbywin(&globalconf
.embedded
, ev
->window
))
711 xcb_map_window(connection
, ev
->window
);
712 xembed_window_activate(connection
, ev
->window
);
714 else if((c
= client_getbywin(ev
->window
)))
716 /* Check that it may be visible, but not asked to be hidden */
717 if(client_maybevisible(c
, c
->screen
) && !c
->ishidden
)
719 client_setminimized(c
, false);
720 /* it will be raised, so just update ourself */
726 geom_c
= xcb_get_geometry_unchecked(connection
, ev
->window
);
728 if(!(geom_r
= xcb_get_geometry_reply(connection
, geom_c
, NULL
)))
734 phys_screen
= xutil_root2screen(connection
, geom_r
->root
);
736 client_manage(ev
->window
, geom_r
, phys_screen
, false);
746 /** The unmap notify event handler.
747 * \param data currently unused.
748 * \param connection The connection to the X server.
749 * \param ev The event.
752 event_handle_unmapnotify(void *data
__attribute__ ((unused
)),
753 xcb_connection_t
*connection
, xcb_unmap_notify_event_t
*ev
)
757 if((c
= client_getbywin(ev
->window
)))
759 if(ev
->event
== xutil_screen_get(connection
, c
->phys_screen
)->root
760 && XCB_EVENT_SENT(ev
)
761 && window_state_get_reply(window_state_get_unchecked(c
->win
)) == XCB_WM_STATE_NORMAL
)
765 for(int i
= 0; i
< globalconf
.embedded
.len
; i
++)
766 if(globalconf
.embedded
.tab
[i
].win
== ev
->window
)
768 xembed_window_array_take(&globalconf
.embedded
, i
);
769 foreach(screen
, globalconf
.screens
)
770 widget_invalidate_bytype(screen
, widget_systray
);
776 /** The randr screen change notify event handler.
777 * \param data currently unused.
778 * \param connection The connection to the X server.
779 * \param ev The event.
782 event_handle_randr_screen_change_notify(void *data
__attribute__ ((unused
)),
783 xcb_connection_t
*connection
__attribute__ ((unused
)),
784 xcb_randr_screen_change_notify_event_t
*ev
)
786 if(!globalconf
.have_randr
)
789 /* Code of XRRUpdateConfiguration Xlib function ported to XCB
790 * (only the code relevant to RRScreenChangeNotify) as the latter
791 * doesn't provide this kind of function */
792 if(ev
->rotation
& (XCB_RANDR_ROTATION_ROTATE_90
| XCB_RANDR_ROTATION_ROTATE_270
))
793 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->height
, ev
->width
,
794 ev
->mheight
, ev
->mwidth
);
796 xcb_randr_set_screen_size(connection
, ev
->root
, ev
->width
, ev
->height
,
797 ev
->mwidth
, ev
->mheight
);
799 /* XRRUpdateConfiguration also executes the following instruction
800 * but it's not useful because SubpixelOrder is not used at all at
803 * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
811 /** The client message event handler.
812 * \param data currently unused.
813 * \param connection The connection to the X server.
814 * \param ev The event.
817 event_handle_clientmessage(void *data
__attribute__ ((unused
)),
818 xcb_connection_t
*connection
,
819 xcb_client_message_event_t
*ev
)
821 /* check for startup notification messages */
822 if(sn_xcb_display_process_event(globalconf
.sndisplay
, (xcb_generic_event_t
*) ev
))
825 if(ev
->type
== WM_CHANGE_STATE
)
828 if((c
= client_getbywin(ev
->window
))
830 && ev
->data
.data32
[0] == XCB_WM_STATE_ICONIC
)
831 client_setminimized(c
, true);
833 else if(ev
->type
== _XEMBED
)
834 return xembed_process_client_message(ev
);
835 else if(ev
->type
== _NET_SYSTEM_TRAY_OPCODE
)
836 return systray_process_client_message(ev
);
837 return ewmh_process_client_message(ev
);
840 /** The keymap change notify event handler.
841 * \param data Unused data.
842 * \param connection The connection to the X server.
843 * \param ev The event.
844 * \return Status code, 0 if everything's fine.
847 event_handle_mappingnotify(void *data
,
848 xcb_connection_t
*connection
,
849 xcb_mapping_notify_event_t
*ev
)
851 if(ev
->request
== XCB_MAPPING_MODIFIER
852 || ev
->request
== XCB_MAPPING_KEYBOARD
)
854 /* Free and then allocate the key symbols */
855 xcb_key_symbols_free(globalconf
.keysyms
);
856 globalconf
.keysyms
= xcb_key_symbols_alloc(globalconf
.connection
);
858 int nscreen
= xcb_setup_roots_length(xcb_get_setup(connection
));
860 /* regrab everything */
861 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
863 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
864 /* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
865 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
866 window_grabkeys(s
->root
, &globalconf
.keys
);
869 foreach(_c
, globalconf
.clients
)
872 xcb_ungrab_key(connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
873 window_grabkeys(c
->win
, &c
->keys
);
881 event_handle_reparentnotify(void *data
,
882 xcb_connection_t
*connection
,
883 xcb_reparent_notify_event_t
*ev
)
887 if((c
= client_getbywin(ev
->window
)))
893 void a_xcb_set_event_handlers(void)
895 const xcb_query_extension_reply_t
*randr_query
;
897 xcb_event_set_button_press_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
898 xcb_event_set_button_release_handler(&globalconf
.evenths
, event_handle_button
, NULL
);
899 xcb_event_set_configure_request_handler(&globalconf
.evenths
, event_handle_configurerequest
, NULL
);
900 xcb_event_set_configure_notify_handler(&globalconf
.evenths
, event_handle_configurenotify
, NULL
);
901 xcb_event_set_destroy_notify_handler(&globalconf
.evenths
, event_handle_destroynotify
, NULL
);
902 xcb_event_set_enter_notify_handler(&globalconf
.evenths
, event_handle_enternotify
, NULL
);
903 xcb_event_set_leave_notify_handler(&globalconf
.evenths
, event_handle_leavenotify
, NULL
);
904 xcb_event_set_focus_in_handler(&globalconf
.evenths
, event_handle_focusin
, NULL
);
905 xcb_event_set_focus_out_handler(&globalconf
.evenths
, event_handle_focusout
, NULL
);
906 xcb_event_set_motion_notify_handler(&globalconf
.evenths
, event_handle_motionnotify
, NULL
);
907 xcb_event_set_expose_handler(&globalconf
.evenths
, event_handle_expose
, NULL
);
908 xcb_event_set_key_press_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
909 xcb_event_set_key_release_handler(&globalconf
.evenths
, event_handle_key
, NULL
);
910 xcb_event_set_map_request_handler(&globalconf
.evenths
, event_handle_maprequest
, NULL
);
911 xcb_event_set_unmap_notify_handler(&globalconf
.evenths
, event_handle_unmapnotify
, NULL
);
912 xcb_event_set_client_message_handler(&globalconf
.evenths
, event_handle_clientmessage
, NULL
);
913 xcb_event_set_mapping_notify_handler(&globalconf
.evenths
, event_handle_mappingnotify
, NULL
);
914 xcb_event_set_reparent_notify_handler(&globalconf
.evenths
, event_handle_reparentnotify
, NULL
);
916 /* check for randr extension */
917 randr_query
= xcb_get_extension_data(globalconf
.connection
, &xcb_randr_id
);
918 if((globalconf
.have_randr
= randr_query
->present
))
919 xcb_event_set_handler(&globalconf
.evenths
,
920 randr_query
->first_event
+ XCB_RANDR_SCREEN_CHANGE_NOTIFY
,
921 (xcb_generic_event_handler_t
) event_handle_randr_screen_change_notify
,
926 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80