]> git.sur5r.net Git - i3/i3/blobdiff - src/restore_layout.c
Use the DPI setting within the i3bar (#2556)
[i3/i3] / src / restore_layout.c
index 53a70d69afe7345c8ed792951303e98aa7c4b18d..d48e5c6ef6197496cd1b8be54bacc19b717622d6 100644 (file)
@@ -1,10 +1,8 @@
-#undef I3__FILE__
-#define I3__FILE__ "restore_layout.c"
 /*
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * restore_layout.c: Everything for restored containers that is not pure state
  *                   parsing (which can be found in load_layout.c).
  */
 #include "all.h"
 
+#ifdef I3_ASAN_ENABLED
+#include <sanitizer/lsan_interface.h>
+#endif
+
 typedef struct placeholder_state {
     /** The X11 placeholder window. */
     xcb_window_t window;
@@ -27,7 +29,8 @@ typedef struct placeholder_state {
     /** The graphics context for “pixmap”. */
     xcb_gcontext_t gc;
 
-    TAILQ_ENTRY(placeholder_state) state;
+    TAILQ_ENTRY(placeholder_state)
+    state;
 } placeholder_state;
 
 static TAILQ_HEAD(state_head, placeholder_state) state_head =
@@ -98,7 +101,11 @@ void restore_connect(void) {
             free(state);
         }
 
-        free(restore_conn);
+        /* xcb_disconnect leaks memory in libxcb versions earlier than 1.11,
+         * but it’s the right function to call. See
+         * http://cgit.freedesktop.org/xcb/libxcb/commit/src/xcb_conn.c?id=4dcbfd77b
+         */
+        xcb_disconnect(restore_conn);
         free(xcb_watcher);
         free(xcb_check);
         free(xcb_prepare);
@@ -106,12 +113,19 @@ void restore_connect(void) {
 
     int screen;
     restore_conn = xcb_connect(NULL, &screen);
-    if (restore_conn == NULL || xcb_connection_has_error(restore_conn))
+    if (restore_conn == NULL || xcb_connection_has_error(restore_conn)) {
+        if (restore_conn != NULL) {
+            xcb_disconnect(restore_conn);
+        }
+#ifdef I3_ASAN_ENABLED
+        __lsan_do_leak_check();
+#endif
         errx(EXIT_FAILURE, "Cannot open display\n");
+    }
 
-    xcb_watcher = scalloc(sizeof(struct ev_io));
-    xcb_check = scalloc(sizeof(struct ev_check));
-    xcb_prepare = scalloc(sizeof(struct ev_prepare));
+    xcb_watcher = scalloc(1, sizeof(struct ev_io));
+    xcb_check = scalloc(1, sizeof(struct ev_check));
+    xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
 
     ev_io_init(xcb_watcher, restore_xcb_got_event, xcb_get_file_descriptor(restore_conn), EV_READ);
     ev_io_start(main_loop, xcb_watcher);
@@ -125,7 +139,7 @@ void restore_connect(void) {
 
 static void update_placeholder_contents(placeholder_state *state) {
     xcb_change_gc(restore_conn, state->gc, XCB_GC_FOREGROUND,
-                  (uint32_t[]){config.client.placeholder.background});
+                  (uint32_t[]){config.client.placeholder.background.colorpixel});
     xcb_poly_fill_rectangle(restore_conn, state->pixmap, state->gc, 1,
                             (xcb_rectangle_t[]){{0, 0, state->rect.width, state->rect.height}});
 
@@ -161,7 +175,7 @@ static void update_placeholder_contents(placeholder_state *state) {
         DLOG("con %p (placeholder 0x%08x) line %d: %s\n", state->con, state->window, n, serialized);
 
         i3String *str = i3string_from_utf8(serialized);
-        draw_text(str, state->pixmap, state->gc, 2, (n * (config.font.height + 2)) + 2, state->rect.width - 2);
+        draw_text(str, state->pixmap, state->gc, NULL, 2, (n * (config.font.height + 2)) + 2, state->rect.width - 2);
         i3string_free(str);
         n++;
         free(serialized);
@@ -172,7 +186,7 @@ static void update_placeholder_contents(placeholder_state *state) {
     int text_width = predict_text_width(line);
     int x = (state->rect.width / 2) - (text_width / 2);
     int y = (state->rect.height / 2) - (config.font.height / 2);
-    draw_text(line, state->pixmap, state->gc, x, y, text_width);
+    draw_text(line, state->pixmap, state->gc, NULL, x, y, text_width);
     i3string_free(line);
     xcb_flush(conn);
     xcb_aux_sync(conn);
@@ -193,7 +207,7 @@ static void open_placeholder_window(Con *con) {
             true,
             XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
             (uint32_t[]){
-                config.client.placeholder.background,
+                config.client.placeholder.background.colorpixel,
                 XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
             });
         /* Make i3 not focus this window. */
@@ -210,7 +224,7 @@ static void open_placeholder_window(Con *con) {
         DLOG("Created placeholder window 0x%08x for leaf container %p / %s\n",
              placeholder, con, con->name);
 
-        placeholder_state *state = scalloc(sizeof(placeholder_state));
+        placeholder_state *state = scalloc(1, sizeof(placeholder_state));
         state->window = placeholder;
         state->con = con;
         state->rect = con->rect;
@@ -225,6 +239,7 @@ static void open_placeholder_window(Con *con) {
         /* create temporary id swallow to match the placeholder */
         Match *temp_id = smalloc(sizeof(Match));
         match_init(temp_id);
+        temp_id->dock = M_DONTCHECK;
         temp_id->id = placeholder;
         TAILQ_INSERT_HEAD(&(con->swallow_head), temp_id, matches);
     }