aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/font.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/font.c')
-rw-r--r--sway/commands/font.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/sway/commands/font.c b/sway/commands/font.c
index c54365b5..74bb6b9f 100644
--- a/sway/commands/font.c
+++ b/sway/commands/font.c
@@ -4,6 +4,7 @@
4#include "sway/config.h" 4#include "sway/config.h"
5#include "log.h" 5#include "log.h"
6#include "stringop.h" 6#include "stringop.h"
7#include <pango/pangocairo.h>
7 8
8struct cmd_results *cmd_font(int argc, char **argv) { 9struct cmd_results *cmd_font(int argc, char **argv) {
9 struct cmd_results *error = NULL; 10 struct cmd_results *error = NULL;
@@ -16,12 +17,34 @@ struct cmd_results *cmd_font(int argc, char **argv) {
16 if (strncmp(font, "pango:", 6) == 0) { 17 if (strncmp(font, "pango:", 6) == 0) {
17 config->pango_markup = true; 18 config->pango_markup = true;
18 config->font = strdup(font + 6); 19 config->font = strdup(font + 6);
20 free(font);
19 } else { 21 } else {
20 config->pango_markup = false; 22 config->pango_markup = false;
21 config->font = strdup(font); 23 config->font = font;
22 } 24 }
23 25
24 free(font); 26 // Parse the font early so we can reject it if it's not valid for pango.
25 config_update_font_height(true); 27 // Also avoids re-parsing each time we render text.
28 PangoFontDescription *font_description = pango_font_description_from_string(config->font);
29
30 const char *family = pango_font_description_get_family(font_description);
31 if (family == NULL) {
32 pango_font_description_free(font_description);
33 return cmd_results_new(CMD_FAILURE, "Invalid font family.");
34 }
35
36 const gint size = pango_font_description_get_size(font_description);
37 if (size == 0) {
38 pango_font_description_free(font_description);
39 return cmd_results_new(CMD_FAILURE, "Invalid font size.");
40 }
41
42 if (config->font_description != NULL) {
43 pango_font_description_free(config->font_description);
44 }
45
46 config->font_description = font_description;
47 config_update_font_height();
48
26 return cmd_results_new(CMD_SUCCESS, NULL); 49 return cmd_results_new(CMD_SUCCESS, NULL);
27} 50}