2018-05-02 15:07:52 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <string.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "stringop.h"
|
2022-06-29 21:38:24 +02:00
|
|
|
#include <pango/pangocairo.h>
|
2018-05-02 15:07:52 +02:00
|
|
|
|
|
|
|
struct cmd_results *cmd_font(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
|
|
|
if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
char *font = join_args(argv, argc);
|
|
|
|
free(config->font);
|
2018-05-05 04:53:49 +02:00
|
|
|
|
|
|
|
if (strncmp(font, "pango:", 6) == 0) {
|
|
|
|
config->pango_markup = true;
|
|
|
|
config->font = strdup(font + 6);
|
2022-06-29 21:35:21 +02:00
|
|
|
free(font);
|
2018-05-05 04:53:49 +02:00
|
|
|
} else {
|
|
|
|
config->pango_markup = false;
|
2022-06-29 21:35:21 +02:00
|
|
|
config->font = font;
|
2018-05-05 04:53:49 +02:00
|
|
|
}
|
|
|
|
|
2022-06-29 21:38:24 +02:00
|
|
|
// 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;
|
2021-08-18 23:27:01 +02:00
|
|
|
config_update_font_height();
|
2022-06-29 21:38:24 +02:00
|
|
|
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-05-02 15:07:52 +02:00
|
|
|
}
|