]> git.sur5r.net Git - i3/i3/blobdiff - src/xcb.c
Merge branch 'tree' into next
[i3/i3] / src / xcb.c
index 7382cc615efe91f718890c812e2b9e38e91a86f3..2c194013b09172d2fc784c11dfc3362569e053fe 100644 (file)
--- a/src/xcb.c
+++ b/src/xcb.c
@@ -62,6 +62,8 @@ i3Font load_font(const char *pattern, bool fallback) {
 
     new.height = reply->font_ascent + reply->font_descent;
 
+    free(reply);
+
     return new;
 }
 
@@ -93,7 +95,6 @@ uint32_t get_colorpixel(char *hex) {
 xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_class,
         enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values) {
     xcb_window_t result = xcb_generate_id(conn);
-    xcb_cursor_t cursor_id = xcb_generate_id(conn);
 
     /* If the window class is XCB_WINDOW_CLASS_INPUT_ONLY, depth has to be 0 */
     uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 : XCB_COPY_FROM_PARENT);
@@ -115,6 +116,7 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_cl
         values[0] = xcursor_get_cursor(cursor);
         xcb_change_window_attributes(conn, result, mask, values);
     } else {
+        xcb_cursor_t cursor_id = xcb_generate_id(conn);
         i3Font cursor_font = load_font("cursor", false);
         int xcb_cursor = xcursor_get_xcb_cursor(cursor);
         xcb_create_glyph_cursor(conn, cursor_id, cursor_font.id, cursor_font.id,
@@ -167,23 +169,29 @@ void xcb_draw_rect(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext
  *
  */
 void fake_configure_notify(xcb_connection_t *conn, Rect r, xcb_window_t window) {
-    xcb_configure_notify_event_t generated_event;
-
-    generated_event.event = window;
-    generated_event.window = window;
-    generated_event.response_type = XCB_CONFIGURE_NOTIFY;
-
-    generated_event.x = r.x;
-    generated_event.y = r.y;
-    generated_event.width = r.width;
-    generated_event.height = r.height;
-
-    generated_event.border_width = 0;
-    generated_event.above_sibling = XCB_NONE;
-    generated_event.override_redirect = false;
-
-    xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&generated_event);
+    /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
+     * In order to properly initialize these bytes, we allocate 32 bytes even
+     * though we only need less for an xcb_configure_notify_event_t */
+    void *event = scalloc(32);
+    xcb_configure_notify_event_t *generated_event = event;
+
+    generated_event->event = window;
+    generated_event->window = window;
+    generated_event->response_type = XCB_CONFIGURE_NOTIFY;
+
+    generated_event->x = r.x;
+    generated_event->y = r.y;
+    generated_event->width = r.width;
+    generated_event->height = r.height;
+
+    generated_event->border_width = 0;
+    generated_event->above_sibling = XCB_NONE;
+    generated_event->override_redirect = false;
+
+    xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)generated_event);
     xcb_flush(conn);
+
+    free(event);
 }
 
 /*
@@ -211,19 +219,22 @@ void fake_absolute_configure_notify(Con *con) {
  *
  */
 void send_take_focus(xcb_window_t window) {
-    xcb_client_message_event_t ev;
-
-    memset(&ev, 0, sizeof(xcb_client_message_event_t));
-
-    ev.response_type = XCB_CLIENT_MESSAGE;
-    ev.window = window;
-    ev.type = A_WM_PROTOCOLS;
-    ev.format = 32;
-    ev.data.data32[0] = A_WM_TAKE_FOCUS;
-    ev.data.data32[1] = XCB_CURRENT_TIME;
+    /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
+     * In order to properly initialize these bytes, we allocate 32 bytes even
+     * though we only need less for an xcb_configure_notify_event_t */
+    void *event = scalloc(32);
+    xcb_client_message_event_t *ev = event;
+
+    ev->response_type = XCB_CLIENT_MESSAGE;
+    ev->window = window;
+    ev->type = A_WM_PROTOCOLS;
+    ev->format = 32;
+    ev->data.data32[0] = A_WM_TAKE_FOCUS;
+    ev->data.data32[1] = XCB_CURRENT_TIME;
 
     DLOG("Sending WM_TAKE_FOCUS to the client\n");
-    xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)&ev);
+    xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)ev);
+    free(event);
 }
 
 /*
@@ -246,7 +257,7 @@ void xcb_get_numlock_mask(xcb_connection_t *conn) {
                            XCB_MOD_MASK_5 };
 
     /* Request the modifier map */
-    cookie = xcb_get_modifier_mapping_unchecked(conn);
+    cookie = xcb_get_modifier_mapping(conn);
 
     /* Get the keysymbols */
     keysyms = xcb_key_symbols_alloc(conn);
@@ -289,38 +300,6 @@ void xcb_raise_window(xcb_connection_t *conn, xcb_window_t window) {
     xcb_configure_window(conn, window, XCB_CONFIG_WINDOW_STACK_MODE, values);
 }
 
-/*
- *
- * Prepares the given Cached_Pixmap for usage (checks whether the size of the
- * object this pixmap is related to (e.g. a window) has changed and re-creates
- * the pixmap if so).
- *
- */
-void cached_pixmap_prepare(xcb_connection_t *conn, struct Cached_Pixmap *pixmap) {
-    DLOG("preparing pixmap\n");
-
-    /* If the Rect did not change, the pixmap does not need to be recreated */
-    if (memcmp(&(pixmap->rect), pixmap->referred_rect, sizeof(Rect)) == 0)
-        return;
-
-    memcpy(&(pixmap->rect), pixmap->referred_rect, sizeof(Rect));
-
-    if (pixmap->id == 0 || pixmap->gc == 0) {
-        DLOG("Creating new pixmap...\n");
-        pixmap->id = xcb_generate_id(conn);
-        pixmap->gc = xcb_generate_id(conn);
-    } else {
-        DLOG("Re-creating this pixmap...\n");
-        xcb_free_gc(conn, pixmap->gc);
-        xcb_free_pixmap(conn, pixmap->id);
-    }
-
-    xcb_create_pixmap(conn, root_depth, pixmap->id,
-                      pixmap->referred_drawable, pixmap->rect.width, pixmap->rect.height);
-
-    xcb_create_gc(conn, pixmap->gc, pixmap->id, 0, 0);
-}
-
 /*
  * Query the width of the given text (16-bit characters, UCS) with given real
  * length (amount of glyphs) using the given font.
@@ -360,7 +339,7 @@ void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r) {
                          XCB_CONFIG_WINDOW_HEIGHT,
                          &(r.x));
     /* ignore events which are generated because we configured a window */
-    add_ignore_event(cookie.sequence);
+    add_ignore_event(cookie.sequence, -1);
 }
 
 /*