]> git.sur5r.net Git - i3/i3/blob - libi3/fake_configure_notify.c
472d2351bb26508987337c9b4acf6a5740dafb78
[i3/i3] / libi3 / fake_configure_notify.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  */
8 #include <stdlib.h>
9 #include <stdbool.h>
10
11 #include <xcb/xcb.h>
12 #include <xcb/xproto.h>
13
14 #include "libi3.h"
15
16 /*
17  * Generates a configure_notify event and sends it to the given window
18  * Applications need this to think they’ve configured themselves correctly.
19  * The truth is, however, that we will manage them.
20  *
21  */
22 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width) {
23     /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
24      * In order to properly initialize these bytes, we allocate 32 bytes even
25      * though we only need less for an xcb_configure_notify_event_t */
26     void *event = scalloc(32);
27     xcb_configure_notify_event_t *generated_event = event;
28
29     generated_event->event = window;
30     generated_event->window = window;
31     generated_event->response_type = XCB_CONFIGURE_NOTIFY;
32
33     generated_event->x = r.x;
34     generated_event->y = r.y;
35     generated_event->width = r.width;
36     generated_event->height = r.height;
37
38     generated_event->border_width = border_width;
39     generated_event->above_sibling = XCB_NONE;
40     generated_event->override_redirect = false;
41
42     xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)generated_event);
43     xcb_flush(conn);
44
45     free(event);
46 }