]> git.sur5r.net Git - i3/i3/commitdiff
i3bar: Bugfix: Correctly allocate pixmap for statuslines which are longer than your...
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 24 Aug 2011 16:48:29 +0000 (18:48 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 24 Aug 2011 16:48:29 +0000 (18:48 +0200)
In case of a 1024 px screen and a 1128 px status line, the status line was not
only cut off (it has to be, obviously), but the right part showed some black
pixels.

i3bar/src/xcb.c

index 28ef3ea236e55a4cf94637acf601b04486e49b78..51a2781ba65562dd1d3f2309c612d35aff2d402b 100644 (file)
@@ -212,7 +212,13 @@ void refresh_statusline() {
     }
 
     xcb_char2b_t *text = (xcb_char2b_t*) convert_utf8_to_ucs2(statusline, &glyph_count);
+    uint32_t old_statusline_width = statusline_width;
     statusline_width = predict_text_extents(text, glyph_count);
+    /* If the statusline is bigger than our screen we need to make sure that
+     * the pixmap provides enough space, so re-allocate if the width grew */
+    if (statusline_width > xcb_screen->width_in_pixels &&
+        statusline_width > old_statusline_width)
+        realloc_sl_buffer();
 
     xcb_rectangle_t rect = { 0, 0, xcb_screen->width_in_pixels, font_height };
     xcb_poly_fill_rectangle(xcb_connection, statusline_pm, statusline_clear, 1, &rect);
@@ -700,13 +706,15 @@ void destroy_window(i3_output *output) {
  *
  */
 void realloc_sl_buffer() {
+    DLOG("Re-allocating statusline-buffer, statusline_width = %d, xcb_screen->width_in_pixels = %d\n",
+         statusline_width, xcb_screen->width_in_pixels);
     xcb_free_pixmap(xcb_connection, statusline_pm);
     statusline_pm = xcb_generate_id(xcb_connection);
     xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
                                                                xcb_screen->root_depth,
                                                                statusline_pm,
                                                                xcb_root,
-                                                               xcb_screen->width_in_pixels,
+                                                               MAX(xcb_screen->width_in_pixels, statusline_width),
                                                                xcb_screen->height_in_pixels);
 
     uint32_t mask = XCB_GC_FOREGROUND;