summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-04-17 11:35:22 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-04-17 11:36:03 -0400
commit84fae94ab9ca7fd148c786d224c49205a212882e (patch)
treed3d3e8a16f96e400ee07cc44e2f9110195bea02a
parentMerge pull request #590 from mikkeloscar/i686-warnings (diff)
downloadsway-84fae94ab9ca7fd148c786d224c49205a212882e.tar.gz
sway-84fae94ab9ca7fd148c786d224c49205a212882e.tar.zst
sway-84fae94ab9ca7fd148c786d224c49205a212882e.zip
Flesh out pango markup implementation
-rw-r--r--include/bar/status_line.h1
-rw-r--r--include/client/pango.h8
-rw-r--r--sway/border.c4
-rw-r--r--swaybar/render.c13
-rw-r--r--swaybar/status_line.c7
-rw-r--r--wayland/pango.c18
6 files changed, 33 insertions, 18 deletions
diff --git a/include/bar/status_line.h b/include/bar/status_line.h
index 273542dc..f890ff8c 100644
--- a/include/bar/status_line.h
+++ b/include/bar/status_line.h
@@ -23,6 +23,7 @@ struct status_block {
23 char *name, *instance; 23 char *name, *instance;
24 bool separator; 24 bool separator;
25 int separator_block_width; 25 int separator_block_width;
26 bool markup;
26 // Airblader features 27 // Airblader features
27 uint32_t background; 28 uint32_t background;
28 uint32_t border; 29 uint32_t border;
diff --git a/include/client/pango.h b/include/client/pango.h
index 97c31e38..66843041 100644
--- a/include/client/pango.h
+++ b/include/client/pango.h
@@ -4,9 +4,11 @@
4#include <cairo/cairo.h> 4#include <cairo/cairo.h>
5#include <pango/pangocairo.h> 5#include <pango/pangocairo.h>
6#include <stdarg.h> 6#include <stdarg.h>
7#include <stdbool.h>
7 8
8PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text); 9PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup);
9void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...); 10void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
10void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...); 11 bool markup, const char *fmt, ...);
12void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt, ...);
11 13
12#endif 14#endif
diff --git a/sway/border.c b/sway/border.c
index 411c0427..3613d2d6 100644
--- a/sway/border.c
+++ b/sway/border.c
@@ -85,7 +85,7 @@ int get_font_text_height(const char *font) {
85 cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200); 85 cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
86 cairo_t *cr = cairo_create(surface); 86 cairo_t *cr = cairo_create(surface);
87 int width, height; 87 int width, height;
88 get_text_size(cr, font, &width, &height, "Gg"); 88 get_text_size(cr, font, &width, &height, false, "Gg");
89 cairo_surface_destroy(surface); 89 cairo_surface_destroy(surface);
90 cairo_destroy(cr); 90 cairo_destroy(cr);
91 return height; 91 return height;
@@ -162,7 +162,7 @@ static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colo
162 int y = MIN(view->actual_geometry.origin.y - height - 2, 2); 162 int y = MIN(view->actual_geometry.origin.y - height - 2, 2);
163 cairo_move_to(cr, x, y); 163 cairo_move_to(cr, x, y);
164 cairo_set_source_u32(cr, colors->text); 164 cairo_set_source_u32(cr, colors->text);
165 pango_printf(cr, config->font, "%s", view->name); 165 pango_printf(cr, config->font, false, "%s", view->name);
166 } 166 }
167 167
168 // header bottom line 168 // header bottom line
diff --git a/swaybar/render.c b/swaybar/render.c
index fff47ab0..3eb824fe 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -136,7 +136,7 @@ static void render_block(struct window *window, struct config *config, struct st
136 136
137 cairo_move_to(window->cairo, offset, margin); 137 cairo_move_to(window->cairo, offset, margin);
138 cairo_set_source_u32(window->cairo, block->color); 138 cairo_set_source_u32(window->cairo, block->color);
139 pango_printf(window->cairo, window->font, "%s", block->full_text); 139 pango_printf(window->cairo, window->font, block->markup, "%s", block->full_text);
140 140
141 pos += width; 141 pos += width;
142 142
@@ -159,7 +159,7 @@ static void render_block(struct window *window, struct config *config, struct st
159 if (config->sep_symbol) { 159 if (config->sep_symbol) {
160 offset = pos + (block->separator_block_width - sep_width) / 2; 160 offset = pos + (block->separator_block_width - sep_width) / 2;
161 cairo_move_to(window->cairo, offset, margin); 161 cairo_move_to(window->cairo, offset, margin);
162 pango_printf(window->cairo, window->font, "%s", config->sep_symbol); 162 pango_printf(window->cairo, window->font, false, "%s", config->sep_symbol);
163 } else { 163 } else {
164 cairo_set_line_width(window->cairo, 1); 164 cairo_set_line_width(window->cairo, 1);
165 cairo_move_to(window->cairo, pos + block->separator_block_width/2, 165 cairo_move_to(window->cairo, pos + block->separator_block_width/2,
@@ -228,7 +228,7 @@ static void render_workspace_button(struct window *window, struct config *config
228 // text 228 // text
229 cairo_set_source_u32(window->cairo, box_colors.text); 229 cairo_set_source_u32(window->cairo, box_colors.text);
230 cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin); 230 cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin);
231 pango_printf(window->cairo, window->font, "%s", name); 231 pango_printf(window->cairo, window->font, false, "%s", name);
232 232
233 *x += width + ws_horizontal_padding * 2 + ws_spacing; 233 *x += width + ws_horizontal_padding * 2 + ws_spacing;
234 234
@@ -254,7 +254,7 @@ static void render_binding_mode_indicator(struct window *window, struct config *
254 // text 254 // text
255 cairo_set_source_u32(window->cairo, config->colors.binding_mode.text); 255 cairo_set_source_u32(window->cairo, config->colors.binding_mode.text);
256 cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin); 256 cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin);
257 pango_printf(window->cairo, window->font, "%s", config->mode); 257 pango_printf(window->cairo, window->font, false, "%s", config->mode);
258} 258}
259 259
260void render(struct output *output, struct config *config, struct status_line *line) { 260void render(struct output *output, struct config *config, struct status_line *line) {
@@ -280,7 +280,7 @@ void render(struct output *output, struct config *config, struct status_line *li
280 if (line->protocol == TEXT) { 280 if (line->protocol == TEXT) {
281 get_text_size(window->cairo, window->font, &width, &height, "%s", line->text_line); 281 get_text_size(window->cairo, window->font, &width, &height, "%s", line->text_line);
282 cairo_move_to(cairo, window->width - margin - width, margin); 282 cairo_move_to(cairo, window->width - margin - width, margin);
283 pango_printf(window->cairo, window->font, "%s", line->text_line); 283 pango_printf(window->cairo, window->font, true, "%s", line->text_line);
284 } else if (line->protocol == I3BAR && line->block_line) { 284 } else if (line->protocol == I3BAR && line->block_line) {
285 double pos = window->width - 0.5; 285 double pos = window->width - 0.5;
286 bool edge = true; 286 bool edge = true;
@@ -312,7 +312,8 @@ void render(struct output *output, struct config *config, struct status_line *li
312 312
313void set_window_height(struct window *window, int height) { 313void set_window_height(struct window *window, int height) {
314 int text_width, text_height; 314 int text_width, text_height;
315 get_text_size(window->cairo, window->font, &text_width, &text_height, "Test string for measuring purposes"); 315 get_text_size(window->cairo, window->font, &text_width, &text_height, false,
316 "Test string for measuring purposes");
316 if (height > 0) { 317 if (height > 0) {
317 margin = (height - text_height) / 2; 318 margin = (height - text_height) / 2;
318 ws_vertical_padding = margin - 1.5; 319 ws_vertical_padding = margin - 1.5;
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index ba6de6a1..63db702f 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -71,7 +71,7 @@ static void parse_json(struct bar *bar, const char *text) {
71 json_object *full_text, *short_text, *color, *min_width, *align, *urgent; 71 json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
72 json_object *name, *instance, *separator, *separator_block_width; 72 json_object *name, *instance, *separator, *separator_block_width;
73 json_object *background, *border, *border_top, *border_bottom; 73 json_object *background, *border, *border_top, *border_bottom;
74 json_object *border_left, *border_right; 74 json_object *border_left, *border_right, *markup;
75 75
76 json_object *json = json_object_array_get_idx(results, i); 76 json_object *json = json_object_array_get_idx(results, i);
77 if (!json) { 77 if (!json) {
@@ -86,6 +86,7 @@ static void parse_json(struct bar *bar, const char *text) {
86 json_object_object_get_ex(json, "urgent", &urgent); 86 json_object_object_get_ex(json, "urgent", &urgent);
87 json_object_object_get_ex(json, "name", &name); 87 json_object_object_get_ex(json, "name", &name);
88 json_object_object_get_ex(json, "instance", &instance); 88 json_object_object_get_ex(json, "instance", &instance);
89 json_object_object_get_ex(json, "markup", &markup);
89 json_object_object_get_ex(json, "separator", &separator); 90 json_object_object_get_ex(json, "separator", &separator);
90 json_object_object_get_ex(json, "separator_block_width", &separator_block_width); 91 json_object_object_get_ex(json, "separator_block_width", &separator_block_width);
91 json_object_object_get_ex(json, "background", &background); 92 json_object_object_get_ex(json, "background", &background);
@@ -139,6 +140,10 @@ static void parse_json(struct bar *bar, const char *text) {
139 new->instance = strdup(json_object_get_string(instance)); 140 new->instance = strdup(json_object_get_string(instance));
140 } 141 }
141 142
143 if (markup) {
144 new->markup = json_object_get_boolean(markup);
145 }
146
142 if (separator) { 147 if (separator) {
143 new->separator = json_object_get_int(separator); 148 new->separator = json_object_get_int(separator);
144 } else { 149 } else {
diff --git a/wayland/pango.c b/wayland/pango.c
index da0b0bfc..f143aa6c 100644
--- a/wayland/pango.c
+++ b/wayland/pango.c
@@ -4,11 +4,16 @@
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h> 5#include <string.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <stdbool.h>
7#include "log.h" 8#include "log.h"
8 9
9PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text) { 10PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) {
10 PangoLayout *layout = pango_cairo_create_layout(cairo); 11 PangoLayout *layout = pango_cairo_create_layout(cairo);
11 pango_layout_set_markup(layout, text, -1); 12 if (markup) {
13 pango_layout_set_markup(layout, text, -1);
14 } else {
15 pango_layout_set_text(layout, text, -1);
16 }
12 PangoFontDescription *desc = pango_font_description_from_string(font); 17 PangoFontDescription *desc = pango_font_description_from_string(font);
13 pango_layout_set_font_description(layout, desc); 18 pango_layout_set_font_description(layout, desc);
14 pango_layout_set_single_paragraph_mode(layout, 1); 19 pango_layout_set_single_paragraph_mode(layout, 1);
@@ -16,7 +21,8 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text
16 return layout; 21 return layout;
17} 22}
18 23
19void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...) { 24void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
25 bool markup, const char *fmt, ...) {
20 char *buf = malloc(2048); 26 char *buf = malloc(2048);
21 27
22 va_list args; 28 va_list args;
@@ -26,7 +32,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, co
26 } 32 }
27 va_end(args); 33 va_end(args);
28 34
29 PangoLayout *layout = get_pango_layout(cairo, font, buf); 35 PangoLayout *layout = get_pango_layout(cairo, font, buf, markup);
30 pango_cairo_update_layout(cairo, layout); 36 pango_cairo_update_layout(cairo, layout);
31 37
32 pango_layout_get_pixel_size(layout, width, height); 38 pango_layout_get_pixel_size(layout, width, height);
@@ -36,7 +42,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, co
36 free(buf); 42 free(buf);
37} 43}
38 44
39void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) { 45void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt, ...) {
40 char *buf = malloc(2048); 46 char *buf = malloc(2048);
41 47
42 va_list args; 48 va_list args;
@@ -46,7 +52,7 @@ void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) {
46 } 52 }
47 va_end(args); 53 va_end(args);
48 54
49 PangoLayout *layout = get_pango_layout(cairo, font, buf); 55 PangoLayout *layout = get_pango_layout(cairo, font, buf, markup);
50 pango_cairo_update_layout(cairo, layout); 56 pango_cairo_update_layout(cairo, layout);
51 57
52 pango_cairo_show_layout(cairo, layout); 58 pango_cairo_show_layout(cairo, layout);