mirror of
https://github.com/swaywm/sway.git
synced 2024-11-16 05:03:17 +00:00
Use statically allocated text buffer
This commit is contained in:
parent
c91adbd188
commit
849c3515ab
|
@ -32,7 +32,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
|
||||||
|
|
||||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
||||||
int32_t scale, bool markup, const char *fmt, ...) {
|
int32_t scale, bool markup, const char *fmt, ...) {
|
||||||
char *buf = malloc(2048);
|
static char buf[2048];
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -45,12 +45,11 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
||||||
pango_cairo_update_layout(cairo, layout);
|
pango_cairo_update_layout(cairo, layout);
|
||||||
pango_layout_get_pixel_size(layout, width, height);
|
pango_layout_get_pixel_size(layout, width, height);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
free(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pango_printf(cairo_t *cairo, const char *font,
|
void pango_printf(cairo_t *cairo, const char *font,
|
||||||
int32_t scale, bool markup, const char *fmt, ...) {
|
int32_t scale, bool markup, const char *fmt, ...) {
|
||||||
char *buf = malloc(2048);
|
static char buf[2048];
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -63,5 +62,4 @@ void pango_printf(cairo_t *cairo, const char *font,
|
||||||
pango_cairo_update_layout(cairo, layout);
|
pango_cairo_update_layout(cairo, layout);
|
||||||
pango_cairo_show_layout(cairo, layout);
|
pango_cairo_show_layout(cairo, layout);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
free(buf);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,15 +36,15 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set bar id
|
// set bar id
|
||||||
int i;
|
for (int i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
|
||||||
if (bar == config->bars->items[i]) {
|
if (bar == config->bars->items[i]) {
|
||||||
const int len = 5 + numlen(i); // "bar-" + i + \0
|
const int len = 5 + numlen(i); // "bar-" + i + \0
|
||||||
bar->id = malloc(len * sizeof(char));
|
bar->id = malloc(len * sizeof(char));
|
||||||
if (bar->id) {
|
if (bar->id) {
|
||||||
snprintf(bar->id, len, "bar-%d", i);
|
snprintf(bar->id, len, "bar-%d", i);
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
|
return cmd_results_new(CMD_FAILURE,
|
||||||
|
"bar", "Unable to allocate bar ID");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue