]> git.sur5r.net Git - i3/i3/commitdiff
Added background and border keys to the i3bar protocol. 2025/head
authorIngo Bürk <ingo.buerk@tngtech.com>
Thu, 22 Oct 2015 14:11:08 +0000 (16:11 +0200)
committerIngo Bürk <ingo.buerk@tngtech.com>
Thu, 22 Oct 2015 14:11:08 +0000 (16:11 +0200)
This patch adds two new status block keys, background and border, which
define the respective colors for the status block. If not specified, the
current behavior is kept, e.g., no background / border will be drawn.

If the status block is marked urgent, the urgent color is prioritized.

fixes #2022

docs/i3bar-protocol
i3bar/include/common.h
i3bar/src/child.c
i3bar/src/xcb.c

index 6cb04bf67bda4563917f05b504b7893f083318f8..3ae144536f22b0bd58872ac6446b89eea6833881 100644 (file)
@@ -136,6 +136,10 @@ color::
        when it is associated.
        Colors are specified in hex (like in HTML), starting with a leading
        hash sign. For example, +#ff0000+ means red.
+background::
+       Overrides the background color for this particular block.
+border::
+       Overrides the border color for this particular block.
 min_width::
        The minimum width (in pixels) of the block. If the content of the
        +full_text+ key take less space than the specified min_width, the block
@@ -207,6 +211,8 @@ An example of a block which uses all possible entries follows:
  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
  "short_text": "10.0.0.1",
  "color": "#00ff00",
+ "background": "#1c1c1c",
+ "border": "#ee0000",
  "min_width": 300,
  "align": "right",
  "urgent": false,
index 4d2dbd3565f5be6ef305a120ce8c1242f8038ee3..7ab3441f08b569dd9c7806ee33161df7066a1587 100644 (file)
@@ -38,6 +38,8 @@ struct status_block {
     i3String *short_text;
 
     char *color;
+    char *background;
+    char *border;
 
     /* min_width can be specified either as a numeric value (in pixels) or as a
      * string. For strings, we set min_width to the measured text width of
index 2b10be492b576281510fc20ce7bed9ebe4eedaf6..3570dde91ac6f9e1aa63c2bfc1bda53499a4747c 100644 (file)
@@ -75,6 +75,8 @@ static void clear_statusline(struct statusline_head *head, bool free_resources)
             FREE(first->name);
             FREE(first->instance);
             FREE(first->min_width_str);
+            FREE(first->background);
+            FREE(first->border);
         }
 
         TAILQ_REMOVE(head, first, blocks);
@@ -205,6 +207,14 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
         sasprintf(&(ctx->block.color), "%.*s", len, val);
         return 1;
     }
+    if (strcasecmp(ctx->last_map_key, "background") == 0) {
+        sasprintf(&(ctx->block.background), "%.*s", len, val);
+        return 1;
+    }
+    if (strcasecmp(ctx->last_map_key, "border") == 0) {
+        sasprintf(&(ctx->block.border), "%.*s", len, val);
+        return 1;
+    }
     if (strcasecmp(ctx->last_map_key, "markup") == 0) {
         ctx->block.pango_markup = (len == strlen("pango") && !strncasecmp((const char *)val, "pango", strlen("pango")));
         return 1;
index 63b9863af83aa2114197834d61d9aee84f4eac1e..989b06c75db226cead971a7ae7f5ab769a8fa09a 100644 (file)
@@ -208,6 +208,9 @@ void refresh_statusline(bool use_short_text) {
             continue;
 
         block->width = predict_text_width(block->full_text);
+        /* Add padding for the border if we have to draw it. */
+        if (block->border)
+            block->width += logical_px(2);
 
         /* Compute offset and append for text aligment in min_width. */
         if (block->min_width <= block->width) {
@@ -250,24 +253,43 @@ void refresh_statusline(bool use_short_text) {
     TAILQ_FOREACH(block, &statusline_head, blocks) {
         if (i3string_get_num_bytes(block->full_text) == 0)
             continue;
-        color_t fg_color;
 
-        /* If this block is urgent, draw it with the defined color and border. */
-        if (block->urgent) {
-            fg_color = colors.urgent_ws_fg;
+        color_t fg_color = (block->color ? draw_util_hex_to_color(block->color) : colors.bar_fg);
+        int border_width = (block->border) ? logical_px(1) : 0;
+        if (block->border || block->background || block->urgent) {
+            if (block->urgent)
+                fg_color = colors.urgent_ws_fg;
+
+            /* Let's determine the colors first. */
+            color_t border_color = colors.bar_bg;
+            color_t bg_color = colors.bar_bg;
+            if (block->urgent) {
+                border_color = colors.urgent_ws_border;
+                bg_color = colors.urgent_ws_bg;
+            } else {
+                if (block->border)
+                    border_color = draw_util_hex_to_color(block->border);
 
-            /* Draw the background */
-            draw_util_rectangle(&statusline_surface, colors.urgent_ws_bg,
-                                x - logical_px(2),
-                                logical_px(1),
-                                block->width + logical_px(4),
+                if (block->background)
+                    bg_color = draw_util_hex_to_color(block->background);
+            }
+
+            /* Draw the border. */
+            draw_util_rectangle(&statusline_surface, border_color,
+                                x, logical_px(1),
+                                block->width + block->x_offset + block->x_append,
                                 bar_height - logical_px(2));
-        } else {
-            fg_color = (block->color ? draw_util_hex_to_color(block->color) : colors.bar_fg);
+
+            /* Draw the background. */
+            draw_util_rectangle(&statusline_surface, bg_color,
+                                x + border_width,
+                                logical_px(1) + border_width,
+                                block->width + block->x_offset + block->x_append - 2 * border_width,
+                                bar_height - 2 * border_width - logical_px(2));
         }
 
         draw_util_text(block->full_text, &statusline_surface, fg_color, colors.bar_bg,
-                       x + block->x_offset, logical_px(ws_voff_px), block->width);
+                       x + block->x_offset + border_width, logical_px(ws_voff_px), block->width - 2 * border_width);
         x += block->width + block->sep_block_width + block->x_offset + block->x_append;
 
         /* If this is not the last block, draw a separator. */