aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/font.c23
-rw-r--r--sway/config.c3
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 @@
#include "sway/config.h"
#include "log.h"
#include "stringop.h"
+#include <pango/pangocairo.h>
struct cmd_results *cmd_font(int argc, char **argv) {
struct cmd_results *error = NULL;
@@ -22,6 +23,28 @@ struct cmd_results *cmd_font(int argc, char **argv) {
config->font = font;
}
+ // Parse the font early so we can reject it if it's not valid for pango.
+ // Also avoids re-parsing each time we render text.
+ PangoFontDescription *font_description = pango_font_description_from_string(config->font);
+
+ const char *family = pango_font_description_get_family(font_description);
+ if (family == NULL) {
+ pango_font_description_free(font_description);
+ return cmd_results_new(CMD_FAILURE, "Invalid font family.");
+ }
+
+ const gint size = pango_font_description_get_size(font_description);
+ if (size == 0) {
+ pango_font_description_free(font_description);
+ return cmd_results_new(CMD_FAILURE, "Invalid font size.");
+ }
+
+ if (config->font_description != NULL) {
+ pango_font_description_free(config->font_description);
+ }
+
+ config->font_description = font_description;
config_update_font_height();
+
return cmd_results_new(CMD_SUCCESS, NULL);
}
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) {
config->default_layout = L_NONE;
config->default_orientation = L_NONE;
if (!(config->font = strdup("monospace 10"))) goto cleanup;
+ config->font_description = pango_font_description_from_string(config->font);
config->urgent_timeout = 500;
config->focus_on_window_activation = FOWA_URGENT;
config->popup_during_fullscreen = POPUP_SMART;
@@ -1006,7 +1007,7 @@ int workspace_output_cmp_workspace(const void *a, const void *b) {
void config_update_font_height(void) {
int prev_max_height = config->font_height;
- get_text_metrics(config->font, &config->font_height, &config->font_baseline);
+ get_text_metrics(config->font_description, &config->font_height, &config->font_baseline);
if (config->font_height != prev_max_height) {
arrange_root();