Make pango markup in mode names optional with a flag.

This introduces the flag "--pango" on the mode config directive to
explicitly enable pango markup for mode names. Not setting this will
cause the mode name to be rendered as is.
This fixes a regression in 4.11 where mode names containing characters
such as '<' would break user's configs as they didn't escape these
characters.

fixes #1992
This commit is contained in:
Ingo Bürk
2015-10-12 23:43:47 +02:00
parent d24964ff6a
commit 82dc747396
9 changed files with 68 additions and 20 deletions

View File

@ -20,6 +20,8 @@
struct mode_json_params {
char *json;
char *cur_key;
char *name;
bool pango_markup;
mode *mode;
};
@ -31,17 +33,35 @@ static int mode_string_cb(void *params_, const unsigned char *val, size_t len) {
struct mode_json_params *params = (struct mode_json_params *)params_;
if (!strcmp(params->cur_key, "change")) {
/* Save the name */
params->mode->name = i3string_from_markup_with_length((const char *)val, len);
/* Save its rendered width */
params->mode->width = predict_text_width(params->mode->name);
char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(copy, (const char *)val, len);
copy[len] = '\0';
DLOG("Got mode change: %s\n", i3string_as_utf8(params->mode->name));
params->name = copy;
FREE(params->cur_key);
return 1;
}
FREE(params->cur_key);
return 0;
}
/*
* Parse a boolean.
*
*/
static int mode_boolean_cb(void *params_, int val) {
struct mode_json_params *params = (struct mode_json_params *)params_;
if (strcmp(params->cur_key, "pango_markup") == 0) {
DLOG("Setting pango_markup to %d.\n", val);
params->pango_markup = val;
FREE(params->cur_key);
return 1;
}
FREE(params->cur_key);
return 0;
}
@ -62,10 +82,27 @@ static int mode_map_key_cb(void *params_, const unsigned char *keyVal, size_t ke
return 1;
}
static int mode_end_map_cb(void *params_) {
struct mode_json_params *params = (struct mode_json_params *)params_;
/* Save the name */
params->mode->name = i3string_from_utf8(params->name);
i3string_set_markup(params->mode->name, params->pango_markup);
/* Save its rendered width */
params->mode->width = predict_text_width(params->mode->name);
DLOG("Got mode change: %s\n", i3string_as_utf8(params->mode->name));
FREE(params->cur_key);
return 1;
}
/* A datastructure to pass all these callbacks to yajl */
static yajl_callbacks mode_callbacks = {
.yajl_string = mode_string_cb,
.yajl_boolean = mode_boolean_cb,
.yajl_map_key = mode_map_key_cb,
.yajl_end_map = mode_end_map_cb,
};
/*