summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-03-28 22:22:46 +0200
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-03-30 00:47:58 +0200
commitcefcce48aad4e452be9d081b1cd1521e2b042e97 (patch)
treea1baadb89b2d94f63175f61c2459d77cd2819ab4
parentMake pango: prefix optional for font config (diff)
downloadsway-cefcce48aad4e452be9d081b1cd1521e2b042e97.tar.gz
sway-cefcce48aad4e452be9d081b1cd1521e2b042e97.tar.zst
sway-cefcce48aad4e452be9d081b1cd1521e2b042e97.zip
Make client/pango.h not depend on client/window.h
-rw-r--r--include/client/pango.h10
-rw-r--r--swaybar/render.c22
-rw-r--r--wayland/pango.c22
3 files changed, 26 insertions, 28 deletions
diff --git a/include/client/pango.h b/include/client/pango.h
index e25a2211..97c31e38 100644
--- a/include/client/pango.h
+++ b/include/client/pango.h
@@ -1,12 +1,12 @@
1#ifndef _SWAY_CLIENT_PANGO_H 1#ifndef _SWAY_CLIENT_PANGO_H
2#define _SWAY_CLIENT_PANGO_H 2#define _SWAY_CLIENT_PANGO_H
3 3
4#include "client/window.h" 4#include <cairo/cairo.h>
5#include "client/buffer.h" 5#include <pango/pangocairo.h>
6#include <stdarg.h> 6#include <stdarg.h>
7 7
8PangoLayout *get_pango_layout(struct window *window, struct buffer *buffer, const char *text); 8PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text);
9void get_text_size(struct window *window, int *width, int *height, const char *fmt, ...); 9void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...);
10void pango_printf(struct window *window, const char *fmt, ...); 10void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...);
11 11
12#endif 12#endif
diff --git a/swaybar/render.c b/swaybar/render.c
index 1573a373..fff47ab0 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -50,7 +50,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, double x, double y
50 50
51static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) { 51static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) {
52 int width, height, sep_width; 52 int width, height, sep_width;
53 get_text_size(window, &width, &height, "%s", block->full_text); 53 get_text_size(window->cairo, window->font, &width, &height, "%s", block->full_text);
54 54
55 int textwidth = width; 55 int textwidth = width;
56 double block_width = width; 56 double block_width = width;
@@ -74,7 +74,7 @@ static void render_block(struct window *window, struct config *config, struct st
74 // Add separator 74 // Add separator
75 if (!edge) { 75 if (!edge) {
76 if (config->sep_symbol) { 76 if (config->sep_symbol) {
77 get_text_size(window, &sep_width, &height, "%s", config->sep_symbol); 77 get_text_size(window->cairo, window->font, &sep_width, &height, "%s", config->sep_symbol);
78 if (sep_width > block->separator_block_width) { 78 if (sep_width > block->separator_block_width) {
79 block->separator_block_width = sep_width + margin * 2; 79 block->separator_block_width = sep_width + margin * 2;
80 } 80 }
@@ -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, "%s", block->full_text); 139 pango_printf(window->cairo, window->font, "%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, "%s", config->sep_symbol); 162 pango_printf(window->cairo, window->font, "%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,
@@ -201,7 +201,7 @@ static void render_workspace_button(struct window *window, struct config *config
201 char *name = handle_workspace_number(config->strip_workspace_numbers, ws->name); 201 char *name = handle_workspace_number(config->strip_workspace_numbers, ws->name);
202 202
203 int width, height; 203 int width, height;
204 get_text_size(window, &width, &height, "%s", name); 204 get_text_size(window->cairo, window->font, &width, &height, "%s", name);
205 struct box_colors box_colors; 205 struct box_colors box_colors;
206 if (ws->urgent) { 206 if (ws->urgent) {
207 box_colors = config->colors.urgent_workspace; 207 box_colors = config->colors.urgent_workspace;
@@ -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, "%s", name); 231 pango_printf(window->cairo, window->font, "%s", name);
232 232
233 *x += width + ws_horizontal_padding * 2 + ws_spacing; 233 *x += width + ws_horizontal_padding * 2 + ws_spacing;
234 234
@@ -237,7 +237,7 @@ static void render_workspace_button(struct window *window, struct config *config
237 237
238static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) { 238static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) {
239 int width, height; 239 int width, height;
240 get_text_size(window, &width, &height, "%s", config->mode); 240 get_text_size(window->cairo, window->font, &width, &height, "%s", config->mode);
241 241
242 // background 242 // background
243 cairo_set_source_u32(window->cairo, config->colors.binding_mode.background); 243 cairo_set_source_u32(window->cairo, config->colors.binding_mode.background);
@@ -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, "%s", config->mode); 257 pango_printf(window->cairo, window->font, "%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) {
@@ -278,9 +278,9 @@ void render(struct output *output, struct config *config, struct status_line *li
278 int width, height; 278 int width, height;
279 279
280 if (line->protocol == TEXT) { 280 if (line->protocol == TEXT) {
281 get_text_size(window, &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, "%s", line->text_line); 283 pango_printf(window->cairo, window->font, "%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,7 @@ 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, &text_width, &text_height, "Test string for measuring purposes"); 315 get_text_size(window->cairo, window->font, &text_width, &text_height, "Test string for measuring purposes");
316 if (height > 0) { 316 if (height > 0) {
317 margin = (height - text_height) / 2; 317 margin = (height - text_height) / 2;
318 ws_vertical_padding = margin - 1.5; 318 ws_vertical_padding = margin - 1.5;
diff --git a/wayland/pango.c b/wayland/pango.c
index 9766be6a..d79d89b3 100644
--- a/wayland/pango.c
+++ b/wayland/pango.c
@@ -4,21 +4,19 @@
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 "client/window.h"
8#include "client/buffer.h"
9#include "log.h" 7#include "log.h"
10 8
11PangoLayout *get_pango_layout(struct window *window, const char *text) { 9PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text) {
12 PangoLayout *layout = pango_cairo_create_layout(window->cairo); 10 PangoLayout *layout = pango_cairo_create_layout(cairo);
13 pango_layout_set_text(layout, text, -1); 11 pango_layout_set_text(layout, text, -1);
14 PangoFontDescription *desc = pango_font_description_from_string(window->font); 12 PangoFontDescription *desc = pango_font_description_from_string(font);
15 pango_layout_set_font_description(layout, desc); 13 pango_layout_set_font_description(layout, desc);
16 pango_layout_set_single_paragraph_mode(layout, 1); 14 pango_layout_set_single_paragraph_mode(layout, 1);
17 pango_font_description_free(desc); 15 pango_font_description_free(desc);
18 return layout; 16 return layout;
19} 17}
20 18
21void get_text_size(struct window *window, int *width, int *height, const char *fmt, ...) { 19void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...) {
22 char *buf = malloc(2048); 20 char *buf = malloc(2048);
23 21
24 va_list args; 22 va_list args;
@@ -28,8 +26,8 @@ void get_text_size(struct window *window, int *width, int *height, const char *f
28 } 26 }
29 va_end(args); 27 va_end(args);
30 28
31 PangoLayout *layout = get_pango_layout(window, buf); 29 PangoLayout *layout = get_pango_layout(cairo, font, buf);
32 pango_cairo_update_layout(window->cairo, layout); 30 pango_cairo_update_layout(cairo, layout);
33 31
34 pango_layout_get_pixel_size(layout, width, height); 32 pango_layout_get_pixel_size(layout, width, height);
35 33
@@ -38,7 +36,7 @@ void get_text_size(struct window *window, int *width, int *height, const char *f
38 free(buf); 36 free(buf);
39} 37}
40 38
41void pango_printf(struct window *window, const char *fmt, ...) { 39void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) {
42 char *buf = malloc(2048); 40 char *buf = malloc(2048);
43 41
44 va_list args; 42 va_list args;
@@ -48,10 +46,10 @@ void pango_printf(struct window *window, const char *fmt, ...) {
48 } 46 }
49 va_end(args); 47 va_end(args);
50 48
51 PangoLayout *layout = get_pango_layout(window, buf); 49 PangoLayout *layout = get_pango_layout(cairo, font, buf);
52 pango_cairo_update_layout(window->cairo, layout); 50 pango_cairo_update_layout(cairo, layout);
53 51
54 pango_cairo_show_layout(window->cairo, layout); 52 pango_cairo_show_layout(cairo, layout);
55 53
56 g_object_unref(layout); 54 g_object_unref(layout);
57 55