summaryrefslogtreecommitdiff
path: root/x11-wm/i3-4.8/i3bar-icons.patch
blob: d9eb622d318b5f679405ab99bc06f953ed4136fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
diff --git a/common.mk b/common.mk
index b086bc8..a7b263c 100644
--- a/common.mk
+++ b/common.mk
@@ -82,6 +82,7 @@ XCB_CFLAGS  := $(call cflags_for_lib, xcb)
 XCB_CFLAGS  += $(call cflags_for_lib, xcb-event)
 XCB_LIBS    := $(call ldflags_for_lib, xcb,xcb)
 XCB_LIBS    += $(call ldflags_for_lib, xcb-event,xcb-event)
+XCB_LIBS    += $(call ldflags_for_lib, xcb-image,xcb-image)
 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
 XCB_CFLAGS  += $(call cflags_for_lib, xcb-atom)
 XCB_CFLAGS  += $(call cflags_for_lib, xcb-aux)
diff --git a/i3bar/include/common.h b/i3bar/include/common.h
index d63780d..b0b0394 100644
--- a/i3bar/include/common.h
+++ b/i3bar/include/common.h
@@ -10,6 +10,7 @@
 #include <stdbool.h>
 #include <xcb/xcb.h>
 #include <xcb/xproto.h>
+#include <xcb/xcb_image.h>
 #include "libi3.h"
 #include "queue.h"
 
@@ -38,6 +39,7 @@ struct status_block {
     i3String *full_text;
 
     char *color;
+    char *icon;
     uint32_t min_width;
     blockalign_t align;
 
@@ -56,6 +58,7 @@ struct status_block {
     /* Optional */
     char *name;
     char *instance;
+    xcb_image_t *icon_image;
 
     TAILQ_ENTRY(status_block) blocks;
 };
@@ -69,6 +72,7 @@ TAILQ_HEAD(statusline_head, status_block) statusline_head;
 #include "workspaces.h"
 #include "mode.h"
 #include "trayclients.h"
+#include "xbm.h"
 #include "xcb.h"
 #include "config.h"
 #include "libi3.h"
diff --git a/i3bar/src/child.c b/i3bar/src/child.c
index 5867ce4..0e618bf 100644
--- a/i3bar/src/child.c
+++ b/i3bar/src/child.c
@@ -141,6 +141,7 @@ static int stdin_start_array(void *context) {
         FREE(first->color);
         FREE(first->name);
         FREE(first->instance);
+        FREE(first->icon);
         TAILQ_REMOVE(&statusline_head, first, blocks);
         free(first);
     }
@@ -187,6 +188,9 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
     if (strcasecmp(ctx->last_map_key, "color") == 0) {
         sasprintf(&(ctx->block.color), "%.*s", len, val);
     }
+    if (strcasecmp(ctx->last_map_key, "icon") == 0) {
+        sasprintf(&(ctx->block.icon), "%.*s", len, val);
+    }
     if (strcasecmp(ctx->last_map_key, "align") == 0) {
         if (len == strlen("left") && !strncmp((const char *)val, "left", strlen("left"))) {
             ctx->block.align = ALIGN_LEFT;
@@ -246,6 +250,7 @@ static int stdin_end_array(void *context) {
     TAILQ_FOREACH (current, &statusline_head, blocks) {
         DLOG("full_text = %s\n", i3string_as_utf8(current->full_text));
         DLOG("color = %s\n", current->color);
+				DLOG("icon = %s\n",current->icon);
     }
     DLOG("end of dump\n");
     return 1;
diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c
index a29f909..28f2b23 100644
--- a/i3bar/src/xcb.c
+++ b/i3bar/src/xcb.c
@@ -134,6 +134,14 @@ void refresh_statusline(void) {
 
         block->width = predict_text_width(block->full_text);
 
+        if (block->icon) {
+          block->icon_image = get_icon(block->icon);
+          if (!block->icon_image)
+            ELOG("Could not load icon: %s\n",block->icon);
+          else
+            statusline_width += block->icon_image->width+1;
+        }
+
         /* Compute offset and append for text aligment in min_width. */
         if (block->min_width <= block->width) {
             block->x_offset = 0;
@@ -179,6 +187,18 @@ void refresh_statusline(void) {
 
         uint32_t colorpixel = (block->color ? get_colorpixel(block->color) : colors.bar_fg);
         set_font_colors(statusline_ctx, colorpixel, colors.bar_bg);
+
+        if (block->icon_image) {
+          int h = (font.height-block->icon_image->height)/2;
+          set_icon_color(xcb_connection,statusline_ctx,
+                         colorpixel,colors.bar_bg);
+          xcb_image_put(xcb_connection,statusline_pm,statusline_ctx,
+                        block->icon_image,x,h,0);
+          set_icon_color(xcb_connection,statusline_ctx,
+                         get_colorpixel("#666666"),colors.bar_bg);
+          x+=block->icon_image->width+1;
+        }
+
         draw_text(block->full_text, statusline_pm, statusline_ctx, x + block->x_offset, 1, block->width);
         x += block->width + block->x_offset + block->x_append;
 
@@ -1035,6 +1055,9 @@ char *init_xcb_early() {
     /* Now we get the atoms and save them in a nice data structure */
     get_atoms();
 
+    /* Set the format for icons */
+    set_format(xcb_connection,1,1);
+
     char *path = root_atom_contents("I3_SOCKET_PATH", xcb_connection, screen);
 
     if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer") ||
@@ -1682,6 +1705,7 @@ void draw_bars(bool unhide) {
     DLOG("Drawing Bars...\n");
     int i = 0;
 
+    xbm_clear_cache_used();
     refresh_statusline();
 
     i3_output *outputs_walk;
@@ -1844,6 +1868,8 @@ void draw_bars(bool unhide) {
         hide_bars();
     }
 
+    xbm_free_unused_icons();
+
     redraw_bars();
 }