diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/background-image.c | 2 | ||||
-rw-r--r-- | common/cairo.c | 4 | ||||
-rw-r--r-- | common/pango.c | 22 | ||||
-rw-r--r-- | common/util.c | 12 |
4 files changed, 28 insertions, 12 deletions
diff --git a/common/background-image.c b/common/background-image.c index de42e8e9..994a0805 100644 --- a/common/background-image.c +++ b/common/background-image.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include "background-image.h" | 2 | #include "background-image.h" |
3 | #include "cairo.h" | 3 | #include "cairo_util.h" |
4 | #include "log.h" | 4 | #include "log.h" |
5 | #if HAVE_GDK_PIXBUF | 5 | #if HAVE_GDK_PIXBUF |
6 | #include <gdk-pixbuf/gdk-pixbuf.h> | 6 | #include <gdk-pixbuf/gdk-pixbuf.h> |
diff --git a/common/cairo.c b/common/cairo.c index 403dcf49..7c59d48c 100644 --- a/common/cairo.c +++ b/common/cairo.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include <stdint.h> | 1 | #include <stdint.h> |
2 | #include <cairo/cairo.h> | 2 | #include <cairo.h> |
3 | #include "cairo.h" | 3 | #include "cairo_util.h" |
4 | 4 | ||
5 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { | 5 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { |
6 | cairo_set_source_rgba(cairo, | 6 | cairo_set_source_rgba(cairo, |
diff --git a/common/pango.c b/common/pango.c index fc3d0688..abc18281 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #include <cairo/cairo.h> | 1 | #include <cairo.h> |
2 | #include <pango/pangocairo.h> | 2 | #include <pango/pangocairo.h> |
3 | #include <stdarg.h> | 3 | #include <stdarg.h> |
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
@@ -6,7 +6,7 @@ | |||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include "cairo.h" | 9 | #include "cairo_util.h" |
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | 12 | ||
@@ -109,7 +109,23 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
109 | free(buf); | 109 | free(buf); |
110 | } | 110 | } |
111 | 111 | ||
112 | void pango_printf(cairo_t *cairo, const char *font, | 112 | void get_text_metrics(const char *font, int *height, int *baseline) { |
113 | cairo_t *cairo = cairo_create(NULL); | ||
114 | PangoContext *pango = pango_cairo_create_context(cairo); | ||
115 | PangoFontDescription *description = pango_font_description_from_string(font); | ||
116 | // When passing NULL as a language, pango uses the current locale. | ||
117 | PangoFontMetrics *metrics = pango_context_get_metrics(pango, description, NULL); | ||
118 | |||
119 | *baseline = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; | ||
120 | *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; | ||
121 | |||
122 | pango_font_metrics_unref(metrics); | ||
123 | pango_font_description_free(description); | ||
124 | g_object_unref(pango); | ||
125 | cairo_destroy(cairo); | ||
126 | } | ||
127 | |||
128 | void render_text(cairo_t *cairo, const char *font, | ||
113 | double scale, bool markup, const char *fmt, ...) { | 129 | double scale, bool markup, const char *fmt, ...) { |
114 | va_list args; | 130 | va_list args; |
115 | va_start(args, fmt); | 131 | va_start(args, fmt); |
diff --git a/common/util.c b/common/util.c index 5ea94f48..5d4c0673 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -10,12 +10,6 @@ | |||
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "util.h" | 11 | #include "util.h" |
12 | 12 | ||
13 | uint32_t get_current_time_msec(void) { | ||
14 | struct timespec now; | ||
15 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
16 | return now.tv_sec * 1000 + now.tv_nsec / 1000000; | ||
17 | } | ||
18 | |||
19 | int wrap(int i, int max) { | 13 | int wrap(int i, int max) { |
20 | return ((i % max) + max) % max; | 14 | return ((i % max) + max) % max; |
21 | } | 15 | } |
@@ -86,6 +80,12 @@ enum movement_unit parse_movement_unit(const char *unit) { | |||
86 | 80 | ||
87 | int parse_movement_amount(int argc, char **argv, | 81 | int parse_movement_amount(int argc, char **argv, |
88 | struct movement_amount *amount) { | 82 | struct movement_amount *amount) { |
83 | if (!sway_assert(argc > 0, "Expected args in parse_movement_amount")) { | ||
84 | amount->amount = 0; | ||
85 | amount->unit = MOVEMENT_UNIT_INVALID; | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | char *err; | 89 | char *err; |
90 | amount->amount = (int)strtol(argv[0], &err, 10); | 90 | amount->amount = (int)strtol(argv[0], &err, 10); |
91 | if (*err) { | 91 | if (*err) { |