i3 - improved tiling WM


Add background color to i3bar segments

Patch status: rejected

Patch by S0lll0s

To apply this patch, use:
curl http://cr.i3wm.org/patch/418/raw.patch | git am

b/i3bar/include/common.h

16
@@ -38,6 +38,7 @@ struct status_block {
17
     i3String *full_text;
18
 
19
     char *color;
20
+    char *bgcolor;
21
     uint32_t min_width;
22
     blockalign_t align;
23
 

b/i3bar/src/child.c

28
@@ -195,6 +195,9 @@ static int stdin_string(void *context, const unsigned char *val, unsigned int le
29
     if (strcasecmp(ctx->last_map_key, "color") == 0) {
30
         sasprintf(&(ctx->block.color), "%.*s", len, val);
31
     }
32
+    if (strcasecmp(ctx->last_map_key, "background_color") == 0) {
33
+        sasprintf(&(ctx->block.bgcolor), "%.*s", len, val);
34
+    }
35
     if (strcasecmp(ctx->last_map_key, "align") == 0) {
36
         if (len == strlen("left") && !strncmp((const char*)val, "left", strlen("left"))) {
37
             ctx->block.align = ALIGN_LEFT;

b/i3bar/src/xcb.c

42
@@ -178,7 +178,8 @@ void refresh_statusline(void) {
43
             continue;
44
 
45
         uint32_t colorpixel = (block->color ? get_colorpixel(block->color) : colors.bar_fg);
46
-        set_font_colors(statusline_ctx, colorpixel, colors.bar_bg);
47
+        uint32_t bgcolorpix = (block->bgcolor ? get_colorpixel(block->bgcolor) : colors.bar_bg);
48
+        set_font_colors(statusline_ctx, colorpixel, bgcolorpix);
49
         draw_text(block->full_text, statusline_pm, statusline_ctx, x + block->x_offset, 1, block->width);
50
         x += block->width + block->x_offset + block->x_append;
51
 

b/libi3/font.c

56
@@ -29,6 +29,9 @@ static xcb_visualtype_t *root_visual_type;
57
 static double pango_font_red;
58
 static double pango_font_green;
59
 static double pango_font_blue;
60
+static double pango_bgfont_red;
61
+static double pango_bgfont_green;
62
+static double pango_bgfont_blue;
63
 
64
 /* Necessary to track whether the dpi changes and trigger a LOG() message,
65
  * which is more easily visible to users. */
66
@@ -120,6 +123,10 @@ static void draw_text_pango(const char *text, size_t text_len,
67
     pango_layout_set_text(layout, text, text_len);
68
 
69
     /* Do the drawing */
70
+    cairo_set_source_rgb(cr, pango_bgfont_red, pango_bgfont_green, pango_bgfont_blue);
71
+    cairo_rectangle(cr, x, y, max_width, savedFont->height);
72
+    cairo_fill(cr);
73
+
74
     cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue);
75
     pango_cairo_update_layout(cr, layout);
76
     pango_layout_get_pixel_size(layout, NULL, &height);
77
@@ -303,6 +310,11 @@ void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background
78
             pango_font_red = ((foreground >> 16) & 0xff) / 255.0;
79
             pango_font_green = ((foreground >> 8) & 0xff) / 255.0;
80
             pango_font_blue = (foreground & 0xff) / 255.0;
81
+
82
+            /* Save the background font */
83
+            pango_bgfont_red = ((background >> 16) & 0xff) / 255.0;
84
+            pango_bgfont_green = ((background >> 8) & 0xff) / 255.0;
85
+            pango_bgfont_blue = (background & 0xff) / 255.0;
86
             break;
87
 #endif
88
         default: