diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/font.c | 23 | ||||
-rw-r--r-- | sway/config.c | 3 |
2 files changed, 25 insertions, 1 deletions
diff --git a/sway/commands/font.c b/sway/commands/font.c index 3eda0a9c..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 | ||
8 | struct cmd_results *cmd_font(int argc, char **argv) { | 9 | struct cmd_results *cmd_font(int argc, char **argv) { |
9 | struct cmd_results *error = NULL; | 10 | struct cmd_results *error = NULL; |
@@ -22,6 +23,28 @@ struct cmd_results *cmd_font(int argc, char **argv) { | |||
22 | config->font = font; | 23 | config->font = font; |
23 | } | 24 | } |
24 | 25 | ||
26 | // Parse the font early so we can reject it if it's not valid for pango. | ||
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; | ||
25 | config_update_font_height(); | 47 | config_update_font_height(); |
48 | |||
26 | return cmd_results_new(CMD_SUCCESS, NULL); | 49 | return cmd_results_new(CMD_SUCCESS, NULL); |
27 | } | 50 | } |
diff --git a/sway/config.c b/sway/config.c index 8220ece0..b41dd871 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -243,6 +243,7 @@ static void config_defaults(struct sway_config *config) { | |||
243 | config->default_layout = L_NONE; | 243 | config->default_layout = L_NONE; |
244 | config->default_orientation = L_NONE; | 244 | config->default_orientation = L_NONE; |
245 | if (!(config->font = strdup("monospace 10"))) goto cleanup; | 245 | if (!(config->font = strdup("monospace 10"))) goto cleanup; |
246 | config->font_description = pango_font_description_from_string(config->font); | ||
246 | config->urgent_timeout = 500; | 247 | config->urgent_timeout = 500; |
247 | config->focus_on_window_activation = FOWA_URGENT; | 248 | config->focus_on_window_activation = FOWA_URGENT; |
248 | config->popup_during_fullscreen = POPUP_SMART; | 249 | config->popup_during_fullscreen = POPUP_SMART; |
@@ -1006,7 +1007,7 @@ int workspace_output_cmp_workspace(const void *a, const void *b) { | |||
1006 | void config_update_font_height(void) { | 1007 | void config_update_font_height(void) { |
1007 | int prev_max_height = config->font_height; | 1008 | int prev_max_height = config->font_height; |
1008 | 1009 | ||
1009 | get_text_metrics(config->font, &config->font_height, &config->font_baseline); | 1010 | get_text_metrics(config->font_description, &config->font_height, &config->font_baseline); |
1010 | 1011 | ||
1011 | if (config->font_height != prev_max_height) { | 1012 | if (config->font_height != prev_max_height) { |
1012 | arrange_root(); | 1013 | arrange_root(); |